endPoints#

crispy.pruning.pruning.endPoints(skel)[source]#

Identify endpoints in a skeletonized structure.

Detects endpoints in a 2D or 3D skeleton. Endpoints are defined as pixels in the skeleton with exactly one neighbor, based on 2-connectivity in ND.

Parameters:

skel (ndarray) – Binary array representing the skeletonized structure. Non-zero values represent skeleton points, and zero values represent the background.

Returns:

ep – Binary array with the same shape as skel, where endpoints are set to True.

Return type:

ndarray

Notes

  • Endpoints are determined using hit-or-miss morphology with connectivity rules that detect pixels with only one neighbor.

  • This function supports both 2D and 3D skeletons, adjusting connectivity checks based on the dimensionality.

  • This code is based on the 2D version seen in FilFinder (v1.7.2) by Eric Koch.

Examples

Detect endpoints in a 2D skeleton:

>>> import numpy as np
>>> from crispy import grid_ridge
>>> skel = np.zeros((5, 5), dtype=bool)
>>> skel[2, 1:4] = True
>>> skel[1, 2] = True
>>> endpoints = grid_ridge.endPoints(skel)
>>> print(endpoints)
[[False False False False False]
 [False False  True False False]
 [False  True False  True False]
 [False False False False False]
 [False False False False False]]