digitopo.skeleton
¶
Homotopic skeletons and parallel thinnings of binary images (2D and 3D).
The functions and parameters are those of pink26.skeleton, and the
results are the same point by point: digitopo examines the points in the
order of Pink's lskelubp2, lskelubp3d2, lskelcurv and lskelcurv3d, and
ports Pink's parallel thinnings (lskelpar.c, lskelpar3d.c).
A homotopic thinning removes simple points one at a time, so the result has the topology of the input. Among the simple points, the one with the lowest priority goes first; by default the priority is the squared Euclidean distance to the background, so the object is peeled from its boundary inwards. Points of inhibit are never removed. The outside of the array is background.
zhang_wang_thinning and guo_hall_thinning are two classic 2D
parallel thinnings, given for comparison: they have no topology proof.
References
G. Bertrand, M. Couprie, "Transformations topologiques discretes", in Geometrie discrete et images numeriques (D. Coeurjolly, A. Montanvert, J.-M. Chassery, eds), Hermes, 2007, pp. 187-209.
Y. Y. Zhang, P. S. P. Wang, "A modified parallel thinning algorithm", Proc. 9th ICPR, 1988, pp. 1023-1025.
Z. Guo, R. W. Hall, "Fast fully parallel thinning algorithms", CVGIP: Image Understanding 55(3), 1992, pp. 317-328.
ultimate_skeleton
¶
ultimate_skeleton(
image: ArrayLike,
connectivity: int,
priority: ArrayLike | None = None,
inhibit: ArrayLike | None = None,
) -> NDArray[np.bool_]
Compute the ultimate homotopic skeleton of a binary image.
Repeats until no point changes: among the simple points of the object
that are not in inhibit, remove the one with the lowest priority. A
component without holes (2D), or without tunnels and cavities (3D),
usually shrinks to a single point; an annulus becomes a closed curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D or 3D array of |
required |
connectivity
|
int
|
4 or 8 in 2D, 6 or 26 in 3D. No default. |
required |
priority
|
array_like
|
Same shape as |
None
|
inhibit
|
array_like
|
Same shape as |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
curvilinear_skeleton
¶
curvilinear_skeleton(
image: ArrayLike,
connectivity: int,
priority: ArrayLike | None = None,
inhibit: ArrayLike | None = None,
) -> NDArray[np.bool_]
Compute the curvilinear homotopic skeleton of a binary image.
The same thinning as ultimate_skeleton, except that the points
where the object is locally a curve (T > 1) are kept as well, so the
branches stay as thin curves. As in Pink, the ends of the curves may move
inward, and the transformation is not idempotent: on a curve one pixel
thick, the end points are simple and are removed.
In 3D, Pink orders the points by 30 * priority + d, where d
codes the background face neighbours: the differences between the
priority values matter, not only their order. In 2D, the key is
10 * priority + d and the points are taken in batches of equal
key / 10, truncated toward zero as in C: the priorities -1 and 0 then
fall in the same batch. Use non-negative priorities (the default, the
squared distance, is) to have one batch per priority value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D or 3D array of |
required |
connectivity
|
int
|
4 or 8 in 2D, 6 or 26 in 3D. No default. |
required |
priority
|
array_like
|
As for |
None
|
inhibit
|
array_like
|
As for |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
parallel_skeleton
¶
parallel_skeleton(
image: ArrayLike,
connectivity: int,
shape: str = "ultimate",
symmetric: bool = True,
max_steps: int | None = None,
inhibit: ArrayLike | None = None,
) -> NDArray[np.bool_]
Thin a binary image in parallel with critical kernels.
Each step removes at once all the simple points, except that each small configuration of simple points whose complete removal would change the topology (two neighbouring pixels, two diagonal pixels, a 2 x 2 square; in 3D a few more) keeps at least one point. The result has the topology of the input.
The symmetric version keeps all the points of such configurations: a rotated or mirrored object gives the rotated or mirrored result, but a small core may remain (a 2 x 2 block for a square of even side). The asymmetric version keeps one point per configuration, chosen by a fixed rule, and reaches one point for a disk.
shape: "ultimate" thins as far as possible; "curvilinear"
also keeps the points where the object is locally a curve;
"surface" (3D) keeps the points where it is locally a surface.
The parameters and results are those of
pink26.skeleton.parallel_skeleton. Combinations provided, with the
function of Pink they reproduce (pink26's corrected versions in 3D):
=========== ========= ========= =========== shape symmetric 2D 3D =========== ========= ========= =========== ultimate True lskelMK2 lskelMK3 ultimate False lskelNK2b lskelAMK3 curvilinear True lskelCK2 lskelCK3a curvilinear False (none) lskelACK3a surface True (none) lskelSK3 =========== ========= ========= ===========
The transformation is not idempotent: applied again to its result, a curvilinear or surface skeleton may lose more points (its curves are two points thick in places, where the symmetric kernels keep both points). The topology is kept in every case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D or 3D array of |
required |
connectivity
|
int
|
8 in 2D, 26 in 3D (Pink defines these thinnings for these
connectivities only; 4 and 6 raise |
required |
shape
|
('ultimate', 'curvilinear', 'surface')
|
What the result keeps ( |
"ultimate"
|
symmetric
|
bool
|
Symmetric or asymmetric algorithm. |
True
|
max_steps
|
int or None
|
|
None
|
inhibit
|
array_like
|
Object points that are never removed. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If |
Examples:
zhang_wang_thinning
¶
Thin a 2D binary image with the Zhang-Wang parallel algorithm.
In each step, every object pixel that has 2 to 6 object neighbours (among its 8 neighbours) and whose neighbours, taken around it, form exactly one group of object pixels is removed, all at once, except where the object is two pixels thick (according to Pink's source comment, this is Zhang and Wang's correction of the older Zhang-Suen algorithm). The steps repeat until nothing changes. The object is 8-connected.
The result is pink26's (Pink's lskelzhangwang on a copy framed by 2
pixels of background).
Warning
This algorithm has no topology proof and Pink states that it may not
preserve the topology: it can disconnect an object or erase a small
part of it. It is given to compare with the critical-kernel
thinnings (parallel_skeleton), which are proved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array of |
required |
max_steps
|
int or None
|
Maximal number of parallel steps; |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If the image is too large for 32-bit point indices (about 4 x 10^9 points with the frame; pink26's limit is 2^31 pixels). |
See Also
guo_hall_thinning, parallel_skeleton
References
Y. Y. Zhang, P. S. P. Wang, "A modified parallel thinning algorithm",
Proc. 9th International Conference on Pattern Recognition, 1988,
pp. 1023-1025. Pink function: lskelzhangwang.
Examples:
A bar 3 pixels thick becomes a thin line inside it:
guo_hall_thinning
¶
guo_hall_thinning(
image: ArrayLike,
variant: int = 1,
max_steps: int | None = None,
) -> NDArray[np.bool_]
Thin a 2D binary image with the Guo-Hall parallel algorithm.
In each step, every object pixel on the border of the object (it has a background 4-neighbour) with more than 2 object neighbours, whose neighbours, taken around it, form exactly one group of object pixels, is removed, all at once, except some configurations that depend on the variant. The steps repeat until nothing changes. The object is 8-connected.
The result is pink26's (Pink's lskelguohall on a copy framed by 2
pixels of background).
Warning
Like zhang_wang_thinning, these algorithms are not proved to
preserve the topology: they may disconnect an object or remove a
component. They are given to compare with the critical-kernel
thinnings (parallel_skeleton), which are proved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
array_like
|
2D array of |
required |
variant
|
(1, 2, 3)
|
1: the first algorithm of Guo and Hall (a test on an L-shaped configuration two pixels away). 2: three tests on diagonal configurations instead. 3: variant 2, and two kinds of end pixels are removed too. |
1
|
max_steps
|
int or None
|
Maximal number of parallel steps; |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
New |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
DigitopoError
|
If the image is too large for 32-bit point indices (about 4 x 10^9 points with the frame; pink26's limit is 2^31 pixels). |
See Also
zhang_wang_thinning, parallel_skeleton
References
Z. Guo, R. W. Hall, "Fast fully parallel thinning algorithms", CVGIP:
Image Understanding 55(3), 1992, pp. 317-328. Pink function:
lskelguohall (variants 1, 2, 3 are the commands 8, 9, 10 of
skelpar).
Examples:
A bar 3 pixels thick becomes a thin line inside it: