medial-axis

medial_axis

skimage.morphology.medial_axis(image, mask=None, return_distance=False) [source]

Compute the medial axis transform of a binary image

Parameters:

image : binary ndarray, shape (M, N)

The image of the shape to be skeletonized.

mask : binary ndarray, shape (M, N), optional

If a mask is given, only those elements in image with a true value in mask are used for computing the medial axis.

return_distance : bool, optional

If true, the distance transform is returned as well as the skeleton.

Returns:

out : ndarray of bools

Medial axis transform of the image

dist : ndarray of ints, optional

Distance transform of the image (only returned if return_distance is True)

See also

skeletonize

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=np.uint8)
>>> square[1:-1, 2:-2] = 1
>>> square
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
>>> medial_axis(square).astype(np.uint8)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 1, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 1, 0, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
doc_scikit_image
2017-01-12 17:22:02
Comments
Leave a Comment

Please login to continue.