uniq_per_pix#
- crispy.grid_ridge.uniq_per_pix(coord, mask, coord_in_xfirst=False, start_index=1)[source]#
Reduce a list of ridge coordinates to one unique point per pixel.
Processes ridge coordinates to retain a single representative point per pixel based on a provided binary mask. The representative point is selected as the one with the median value along the last coordinate axis.
- Parameters:
coord (ndarray) – Ridge coordinates, shape (D, n), where D is the number of dimensions (e.g., 2 or 3) and n is the number of points.
mask (ndarray) – Binary mask array, shape matching the reference grid, where True indicates pixels of interest.
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 the coordinate system. Adjusts the input coordinates before processing.
- Returns:
coord_uniq – Reduced set of coordinates, shape (D, m), where m is the number of unique pixels with a representative coordinate.
- Return type:
ndarray
Notes
This function is optimized for cases where the input mask represents gridded, one-voxel-wide skeletons or spines.
The median value along the last axis (e.g., z in 3D) is used to select the representative point for each pixel.
Examples
Reduce ridge coordinates to one per pixel:
>>> import numpy as np >>> from crispy import grid_ridge >>> coords = np.array([[0, 1, 1, 2], [0, 0, 0, 0], [0, 0, 1, 1]]) # 3D coordinates >>> mask = np.zeros((3, 3, 3), dtype=bool) >>> mask[1, 1, 0] = True >>> mask[1, 1, 1] = True >>> reduced_coords = grid_ridge.uniq_per_pix(coords, mask) >>> print(reduced_coords) [[1] [1] [0]]