|
pink26 0.1.1
Image processing and digital topology for teaching
|
Homotopic skeletons of binary images. More...
Go to the source code of this file.
Functions | |
| p26_status | p26_ultimate_skeleton (const p26_image *binary, int connectivity, const p26_image *priority, const p26_image *inhibit, p26_image **out) |
| Ultimate homotopic skeleton (Pink's lskelubp2 and lskelubp3d2, with or without inhibit image; [BC07]). | |
| p26_status | p26_curvilinear_skeleton (const p26_image *binary, int connectivity, const p26_image *priority, const p26_image *inhibit, p26_image **out) |
| Curvilinear homotopic skeleton (Pink's lskelcurv, lskelcurv3d; [BC07]). | |
Homotopic skeletons of binary images.
A point of the object is simple when removing it does not change the topology of the image (see pink26/topology.h: T(p) = T-bar(p) = 1, Bertrand 1994). A homotopic thinning removes simple points one at a time. Each removal keeps the topology, so the result has exactly the topology of the input:
Which simple point goes first matters for the shape of the result, not for its topology. A priority image decides: among the simple points, the one with the LOWEST priority value is removed first. The default priority is the squared Euclidean distance to the background, so the thinning peels the object from its boundary inwards and the skeleton stays near the middle of the object (Couprie, Coeurjolly and Zrour 2007, "Discrete bisector function and Euclidean skeleton in 2D and 3D", Image and Vision Computing 25(10)).
Pink takes integer priorities. pink26 passes an integer priority to Pink unchanged (P26_I32, P26_U8, or P26_F32 / P26_F64 whose values are all integers) when every value lies in [-71582788, 71582786], the range where Pink's int32 key priority * 30 + d of the 3D curvilinear skeleton cannot overflow; the default distance map is passed unchanged too. Any other priority (non-integer floats, integers out of that range) is replaced by the dense rank of its values (0 for the smallest, equal values get equal ranks), which keeps their order exactly: float values that differ only slightly are never merged.
For the ultimate skeleton and the 2D curvilinear skeleton only the ORDER of the priority values matters: two priority images that sort the points in the same way give the same skeleton. For the 3D curvilinear skeleton the differences between values matter too (see p26_curvilinear_skeleton()).
Points of equal priority are processed in a fixed order: the result is deterministic, and always a correct skeleton. That order depends on the size of the image, though (Pink's priority queue reorganizes itself when it grows): the same object inside a larger background may give another, equally valid, skeleton when many priorities are equal.
Border convention: as everywhere in pink26, the image is surrounded by an infinite background. An object that touches the frame is thinned as if the outside were background: a bar that crosses the whole image shrinks to a point, its ends are not held by the frame.
The algorithms are those of Pink's lskeletons.c (Couprie, ESIEE): lskelubp2 and lskelcurv, with their 3D versions. Reference: G. Bertrand and M. Couprie, "Transformations topologiques discretes", in Geometrie discrete et images numeriques (D. Coeurjolly, A. Montanvert, J.-M. Chassery, eds), Hermes, 2007, pp. 187-209 (cited [BC07] by Pink).
| p26_status p26_ultimate_skeleton | ( | const p26_image * | binary, |
| int | connectivity, | ||
| const p26_image * | priority, | ||
| const p26_image * | inhibit, | ||
| p26_image ** | out ) |
Ultimate homotopic skeleton (Pink's lskelubp2 and lskelubp3d2, with or without inhibit image; [BC07]).
Repeats until no point changes: choose the object point x, outside inhibit, of lowest priority among the simple points, and remove it. The result has no simple point left outside inhibit: it is the thinnest set with the topology of the input. A component without holes (2D), or without tunnels and cavities (3D), usually shrinks to a single point; an annulus becomes a closed curve; a torus a closed curve around its hole.
| binary | P26_U8 image, 2D or 3D; any nonzero value is an object point. |
| connectivity | Connectivity of the object: 4 or 8 in 2D, 6 or 26 in 3D (the background has the complementary one). |
| priority | NULL for the default priority, the squared Euclidean distance to the background (P26_DISTANCE_SQUARED_EUCLIDEAN of pink26/distance.h); otherwise an image of the shape of binary, of type P26_U8, P26_I32, P26_F32 or P26_F64 (no NaN). Lower values are removed first; only their order matters (see above). Values on the background are ignored, but they count for the range test and the ranking above. |
| inhibit | NULL, or a P26_U8 image of the shape of binary: its nonzero points are never removed (they stay in the result if they are object points). |
| out | Set to NULL on entry; receives a new P26_U8 image of the shape of binary, 1 on the skeleton and 0 elsewhere (released with p26_image_free()). |
Complexity: O(N log N) time for N pixels (Pink's priority queue; each point enters it a bounded number of times; sorting a ranked priority costs as much), and a few bytes per pixel of memory: the framed copies of the object (1 byte), the priority (4 bytes) and the inhibit image (1 byte), the default distance map (4 bytes) or the sorted values of a ranked priority (8 bytes), both freed before the thinning, and Pink's per-pixel flags.
| p26_status p26_curvilinear_skeleton | ( | const p26_image * | binary, |
| int | connectivity, | ||
| const p26_image * | priority, | ||
| const p26_image * | inhibit, | ||
| p26_image ** | out ) |
Curvilinear homotopic skeleton (Pink's lskelcurv, lskelcurv3d; [BC07]).
The same thinning as p26_ultimate_skeleton(), except that the points that become 1D isthmuses during the thinning (points where the object is locally a curve: T > 1) are kept as well. The branches of the object are kept as thin curves, their ends may move a little inward: a thick cross becomes a thin cross with its four arms, where the ultimate skeleton would reduce it to a point.
Pink's rule (lskeletons.c): a point x is constrained, and never removed, when T(x) > 1 at the start (2D and 3D) or after the removal of a neighbor (3D); in 2D, after the removal of a neighbor, when T-bar(x) > 1. The constrained points and the inhibit points are not removed; the other simple points are removed in priority order. The result therefore usually still has simple points (the ends of the curves).
Two consequences of that rule. The end of a thick branch is kept a little inside the branch (for a 3-pixel-wide arm, 2 pixels from its tip): its last pixels are removed with the first layer. And the function is not idempotent: on a curve that is already one pixel thick, the end points have T = 1, are not constrained and are removed, so each new call shortens every open curve by one pixel at each end.
In 3D, Pink orders the points by the key priority * 30 + d, where d (0 to 44) describes which 6-neighbors are background: the direction breaks the ties between equal priorities, and can also reorder points whose priorities differ by 1. So the differences between priority values matter, not only their order: priorities p and 100 p can give different 3D curvilinear skeletons (both homotopic).
Batches. In 2D, and in 3D with connectivity 6, Pink removes the points in batches and updates the constraints after each batch; a batch is the set of keys with the same key / 10, truncated toward zero (in 2D the key is priority * 10 + d with d at most 9, so a batch is one priority value). The truncation toward zero shifts the batches around zero: for priority -1 only the points with d = 0 (key -10) stay in batch -1, the others (keys -9 to -1) merge into batch 0. In 3D the key is priority * 30 + d, so a batch is a range of 10 consecutive keys, not one priority value. The result is still homotopic.
| binary | As p26_ultimate_skeleton(). |
| connectivity | As p26_ultimate_skeleton(). |
| priority | As p26_ultimate_skeleton(). |
| inhibit | As p26_ultimate_skeleton(). |
| out | As p26_ultimate_skeleton(). |
Complexity: as p26_ultimate_skeleton().