Skeletonization¶
| Fact | Value |
|---|---|
| Also called | Morphological skeleton, Lantuejoul skeleton |
| Status | Implemented and tested |
| Family | Morphological filters |
| Engine | Browser |
| Type | Nonlinear, spatial, Lantuejoul skeleton |
| Output | Mask |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | web/src/core/filters/morphology/binary.ts, skeletonFilter |
| Operator code | web/src/core/filters/morphology/binary.ts, morphologicalSkeleton |
| Channels | Brightness only, RGB |
Overview¶
The morphological skeleton keeps the center points of a shape. These are the centers of the largest copies of the structuring element that fit inside the shape. Unlike thinning it can be broken into pieces, but the shape can be rebuilt from it exactly.
How it works¶
- Erode the shape again and again with the element.
- Each time, keep the pixels that an opening of the eroded shape would remove.
- Join everything kept.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(A \\ominus kB\): A eroded k times by B
- \(\\circ\): Opening
A eroded k times by B, minus its opening by B, keeps the pixels where a copy of B of size k fits but a larger one does not. The union over k, until the erosion is empty, is the skeleton. Unlike thinning, it may be disconnected, but the shape can be rebuilt from it.
Lantuejoul's formula builds the skeleton from erosions and openings. After k erosions, the pixels that an opening removes are the centers of the largest copies of the element, of size k, that fit at that place. The union over all k is the skeleton.
Kernel or operator¶
There is no kernel. The Inspector lists the formula with the chosen element.
Algorithm¶
- Make the image binary.
- For k = 0, 1, 2 and so on, erode k times and subtract the opening of that erosion.
- Join the results until the erosion is empty.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Structuring element element |
cross 1 | Disk, rectangle, ellipse, cross, diamond, line or custom, with sizes | The element B used for the erosions and openings. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
morphologicalSkeleton in web/src/core/filters/morphology/binary.ts erodes and opens until the erosion is empty. Pixels outside the image count as black. It is a global filter, so it always runs on the whole image in one tile, and a selection is cut out of the result. The filter runs in the browser engine through the shared filter framework in web/src/core/filters/run.ts, which handles the channel scope and alpha. Values at or above 128 count as white, and the result is 255 or 0.
Worked example¶
| Row | Input | Result |
|---|---|---|
| 0 | 1 0 0 0 0 0 0 0 0 0 |
1 0 0 0 0 0 0 0 0 0 |
| 1 | 0 0 0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 0 0 |
| 2 | 0 1 1 1 1 1 1 0 0 0 |
0 1 0 0 0 0 1 0 0 0 |
| 3 | 0 1 1 1 1 1 1 0 0 0 |
0 0 1 1 1 1 0 0 0 0 |
| 4 | 0 1 1 1 1 1 1 0 0 0 |
0 1 0 0 0 0 1 0 0 0 |
| 5 | 0 0 0 0 0 0 0 0 0 0 |
0 0 0 0 0 0 0 0 0 0 |
| 6 | 0 0 1 0 0 0 0 0 0 0 |
0 0 1 0 0 0 0 0 0 0 |
| 7 | 0 0 1 0 0 0 0 0 0 0 |
0 0 1 0 0 0 0 0 0 0 |
| 8 | 0 0 1 1 1 0 0 0 0 0 |
0 0 1 1 1 0 0 0 0 0 |
A small binary image, 1 for white and 0 for black. With the 3 x 3 cross, the bar of three rows keeps the middle of its center row and its four corners. The L, one pixel thick, is its own skeleton.
Complexity¶
- Time: \(O(N K m)\)
- Memory: \(O(N)\)
N is the number of pixels per channel, K the size of the element and m the number of erosions, about half the thickness of the widest shape.
Artifacts and limitations¶
Limitations
- Often disconnected and sensitive to noise on the outline.
Artifacts
- Broken skeleton lines.
Tests¶
The reference uses scipy.ndimage.binary_erosion and binary_dilation with the same element. The cases cover three elements, one of them not symmetric.
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 9, morphological image processing.
- Soille, P. Morphological Image Analysis, 2nd edition. Springer, 2004. DOI 10.1007/978-3-662-05088-0.