How do I calculate the medial axis for a 2D vector shape?

I have a 2D shape stored as a path element in SVG. Shapes are made up of Bezier curves and line segments.

I also have many identical spatial points along the shape, which I generate using the arc length parameterization.

How can I use SVG or these points to define the medial axis of the shape?

I'm using Python, but any pseudocode or algorithm evaluations would be appreciated.


Below is an example of the types of shapes I am dealing with and the red points are my sample points along the curve.

example

+3


source to share


1 answer


you can see the code from skimage (scikit-image). you will find the code for skeletonization as well as for the medial axis (skimage.morphology.medial_axis)

The source is available at this address: https://github.com/scikit-image/scikit-image/blob/v0.12.2/skimage/morphology/_skeletonize.py#L103

This algorithm computes the medial transform of the image axis as the ridges of its distance transform.



The different stages 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.

      

I hope this helps you

0


source







All Articles