make_skeleton#

crispy.grid_ridge.make_skeleton(coord, refdata, rm_sml_obj=True, coord_in_xfirst=False, start_index=1, min_length=6)[source]#

Map CRISPy skeleton coordinates onto a reference grid and clean the skeleton.

Grids CRISPy ridge coordinates onto a binary mask based on a reference image. It optionally removes small objects and structures shorter than a specified length to produce a cleaned skeleton map.

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.

  • rm_sml_obj (bool, optional, default=True) – If True, removes small objects shorter than min_length from the skeletonized map.

  • 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) – Starting index for mapping the skeleton coordinates to the reference grid.

  • min_length (int, optional, default=6) – Minimum length (in pixels) for structures to be retained.

Returns:

mask – Binary array with the same shape as refdata, representing the cleaned skeleton. Structures shorter than min_length are removed if rm_sml_obj is True.

Return type:

ndarray

Notes

  • The skeleton is gridded using the grid_skeleton function and further processed to remove small objects or short structures.

  • Cleaning operations assume the skeleton is 1-pixel wide and connected by an 8-neighbor connectivity in 2D or 26-neighbor connectivity in 3D.

Examples

Create and clean a 3D skeleton:

>>> 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))  # Reference image
>>> mask = grid_ridge.make_skeleton(coords, ref_image, rm_sml_obj=True, min_length=5)
>>> print(mask.shape)
(20, 20, 20)