clean_grid#
- crispy.grid_ridge.clean_grid(coord, refdata, coord_in_xfirst=False, start_index=1, min_length=6, method='robust')[source]#
Process and grid CRISPy coordinates onto a reference image, labeling and cleaning skeleton structures.
Takes CRISPy coordinates, labels distinct ridge structures using DBSCAN, grids them onto a reference image, and removes endpoints that might connect separate structures. Structures shorter than a specified length are filtered out.
- Parameters:
coord (ndarray) – Coordinates of the ridge points, shape (n, D), where n is the number of points and D is the dimensionality (2D or 3D).
refdata (ndarray) – Reference image array defining the grid dimensions.
coord_in_xfirst (bool, optional, default=False) – If True, assumes the input coordinates are ordered with x as the first axis. If False, assumes z is the first axis for 3D data or y for 2D data.
start_index (int, optional, default=1) – The starting index for gridding the skeleton onto the reference image.
min_length (int, optional, default=6) – Minimum length (in pixels) for structures to be retained.
method ({"robust", "fast"}, optional, default="robust") – Method for cleaning skeleton endpoints: - “robust”: Ensures diagonal connections are handled but is computationally intensive. - “fast”: Faster but may miss diagonally connected structures.
- Returns:
skel_cube – Binary array with the same shape as refdata, where gridded skeleton structures are set to True.
- Return type:
ndarray
Notes
The DBSCAN algorithm is used to label distinct ridge structures, grouping nearby points into clusters and treating outliers as noise.
Endpoints are removed to avoid overlap between distinct structures when gridded.
The current implementation supports only 2D and 3D data.
Examples
Grid and clean ridge coordinates for a 3D reference image:
>>> import numpy as np >>> from crispy import grid_ridge >>> coords = np.array([[0, 0, 0], [1, 1, 1], [10, 10, 10]]) >>> ref_image = np.zeros((20, 20, 20)) >>> skel_cube = grid_ridge.clean_grid(coords, ref_image, min_length=5, method="fast") >>> print(skel_cube.shape) (20, 20, 20)