Medial axis¶
| Fact | Value |
|---|---|
| Also called | Medial axis transform, Blum skeleton, Medial axis with distance |
| Status | Implemented and tested |
| Family | Morphological filters |
| Engine | Science engine |
| Type | Nonlinear, morphological, medial axis transform |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/tree_morphology.py, medial_axis_filter |
| Operator code | engine/src/pixelnexus_engine/filters/tree_morphology.py, medial_axis_representation |
| Packages | scikit-image |
Overview¶
The medial axis reduces each white shape to a line through its middle, the centers of the largest disks that fit inside it. Each axis pixel also carries its distance to the background, so the axis and the distances together describe the width of the shape everywhere. The filter runs in the PixelNexus engine, with scikit-image.
How it works¶
- Make the image binary at a luma of 128.
- Compute the distance of each foreground pixel to the background.
- Thin the foreground in order of distance, keeping it connected.
- Show the axis, its distances, or the axis over the image.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(X\): The foreground
- \(D(p)\): The distance of p to the background
- \(M(X)\): The medial axis
X is the foreground and D the Euclidean distance to the background. Blum defined the medial axis as the centers of the maximal disks, those that fit in X and lie in no larger disk that fits. Together with D, the axis describes X completely. On a pixel grid the exact axis breaks into pieces. The scikit-image code thins the foreground instead, removing pixels in order of increasing distance as long as connectivity is kept, so the axis stays connected and one pixel wide. Ties are broken in a random order, which the filter fixes with the seed 0.
The axis alone looks like a skeleton. The difference is the distance. A skeleton only keeps the shape's topology. The medial axis transform keeps enough to rebuild the shape. Draw a disk of radius D at every axis pixel, and their union is the shape again.
Kernel or operator¶
There is no fixed kernel. The Inspector asks the engine for the stages with the current settings.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Axis | Axis, Distance on the axis, Axis over the image | The axis in white on black, each axis pixel with its distance to the background stretched so the largest is white, or the axis in yellow over the darkened image. |
Implementation¶
medial_axis_filter in engine/src/pixelnexus_engine/filters/tree_morphology.py makes the image binary at a luma of 128, as the skeleton filter does. It calls skimage.morphology.medial_axis with the distances, and a fixed seed of 0 for the order in which it breaks ties.
Worked example¶
| Shape | Pixels | Axis pixels | Largest distance (px) |
|---|---|---|---|
| Rectangle | 2880 | 144 | 12.00 |
| Disk | 2121 | 104 | 25.02 |
| L shape | 1272 | 122 | 7.07 |
The image of the figure. The largest distance is half the width of the shape, or its radius, measured from a pixel center to the nearest background pixel center.
The largest distance is half the width: 12 for the rectangle 24 pixels wide, and 25 for the disk of radius 26. The distance runs from a pixel center to the nearest background pixel center. In the L, the largest distance is 7.07, a little more than half its width of 12, where the two arms meet. The disk's axis is a small cross, not a single point, an effect of thinning on the pixel grid.
Complexity¶
- Time: \(O(N log N)\)
- Memory: \(O(N)\)
N is the number of pixels, with the sort by distance.
Artifacts and limitations¶
Limitations
- Small bumps on the outline make spurious branches.
- Needs a clean binary image.
Artifacts
- Short side branches at noisy edges.
Tests¶
The axis and distances must equal scikit-image's own call, and the largest distance in a 20 pixel wide rectangle must be 10. Each output must show the axis it computed. The representation must have its three stages.
References¶
- scikit-image documentation, skimage.morphology.medial_axis.