bundles / skimage latest / skimage / morphology / _skeletonize / medial_axis
function
skimage.morphology._skeletonize:medial_axis
source: /dev/scikit-image/src/skimage/morphology/_skeletonize.py :360
Signature
def medial_axis ( image , mask = None , return_distance = False , * , rng = None ) Summary
Compute the medial axis transform of a binary image.
Parameters
image: binary ndarray, shape (M, N)The image of the shape to skeletonize. If this input isn't already a binary image, it gets converted into one: In this case, zero values are considered background (False), nonzero values are considered foreground (True).
mask: binary ndarray, shape (M, N), optionalIf a mask is given, only those elements in
imagewith a true value inmaskare used for computing the medial axis.return_distance: bool, optionalIf true, the distance transform is returned as well as the skeleton.
rng: {`numpy.random.Generator`, int}, optionalPseudo-random number generator. By default, a PCG64 generator is used (see numpy.random.default_rng). If
rngis an int, it is used to seed the generator.The PRNG determines the order in which pixels are processed for tiebreaking.
Returns
out: ndarray of boolsMedial axis transform of the image
dist: ndarray of ints, optionalDistance transform of the image (only returned if
return_distanceis True)
Notes
This algorithm computes the medial axis transform of an image as the ridges of its distance transform.
The different steps of the algorithm are as follows
A lookup table is used, that assigns 0 or 1 to each configuration of the 3x3 binary square, whether the central pixel should be removed or kept. We want a point to be removed if it has more than one neighbor and if removing it does not change the number of connected components.
The distance transform to the background is computed, as well as the cornerness of the pixel.
The foreground (value of 1) points are ordered by the distance transform, then the cornerness.
A cython function is called to reduce the image to its skeleton. It processes pixels in the order determined at the previous step, and removes or maintains a pixel according to the lookup table. Because of the ordering, it is possible to process all pixels in only one pass.
Examples
square = np.zeros((7, 7), dtype=bool) square[1:-1, 2:-2] = 1 square.view(np.uint8) medial_axis(square).view(np.uint8)✓
See also
Aliases
-
skimage.morphology.medial_axis