|
pink26 0.1.1
Image processing and digital topology for teaching
|
Topological watershed of grayscale images ([CB97], [Ber05], [CNB05]). More...
Go to the source code of this file.
Functions | |
| p26_status | p26_topological_watershed (const p26_image *image, int connectivity, p26_image **out) |
| Topological watershed ([Ber05], [CNB05]; Pink's lwshedtopo_lwshedtopo on the inverted image, command wshedtopo). | |
| p26_status | p26_watershed_lines (const p26_image *image, const p26_image *markers, int connectivity, p26_image **out) |
| Watershed lines with markers (Pink's lwshedtopobin on the inverted image, command watershed). | |
Topological watershed of grayscale images ([CB97], [Ber05], [CNB05]).
Think of a grayscale image F as a relief: dark points are low, bright points are high. The lower section of F at level k is the set {F < k} of the points below k: as k grows, it is the water of a flood rising from the minima. Its connected components are the lakes at level k.
W-destructible point ([Ber05] definitions 7 and 9). A point p is W-destructible when it has at least one lower neighbour and all its lower neighbours lie in the same component of {F < F(p)}: p touches exactly one lake below it. Lowering p by one then only enlarges that lake: no lake appears, none disappears and no two lakes merge, at any level. A point that touches two lakes below it is separating: lowering it would merge them.
W-thinning ([Ber05] definition 10). An image G is a W-thinning of F when G can be obtained from F by lowering W-destructible points by one, again and again. Equivalently ([Ber05] theorem 7: G is a W-thinning of F if and only if G is an extension of F, definitions 12 and 13), G <= F and, at every level k, each component of {G < k} contains exactly one component of {F < k}: the lakes grow but keep their number. A W-thinning keeps the number of minima, at the same levels, and the level of the passes between them: the lowest level at which two minima are joined does not change ([Ber05] theorems 14 and 18).
Topological watershed ([Ber05] definition 10, [CNB05] definition 5). A W-thinning with no W-destructible point left. Each minimum has spread as far as it can: the minima of the result fill the basins, and the points outside the minima form thin crest lines, which stay at the level of the passes. An image may have several topological watersheds (the points are lowered in some order); pink26 gives Pink's one, computed on the component tree with the quasi-linear method of [CNB05].
WHERE PINK26 DIFFERS FROM PINK'S wshedtopo AND watershed. Pink's result was a W-thinning on every test image, but in rare cases not a topological watershed: a few W-destructible points were left. Pink first queued only the points next to a minimum, and later only the neighbours of the points it lowered, whereas the algorithm of [CNB05] (procedure TopologicalWatershed, line 02) tests every point: a W-destructible point next to no minimum, whose neighbours never changed, was never lowered. Smallest example, connectivity 4: in 255 255 170 170 0 255 0 170 0 the 255 at the top left has a single lower neighbour (the 170 below it): it can be lowered to 170, but Pink returned the image unchanged (on the random images of pink26's tests: 5 images out of 60, in 2D with connectivity 4 and in 3D with connectivity 6). pink26 corrects it (a marked edit of src/legacy/lwshedtopo.c): after Pink's own pass, it tests every point once more and lowers those that are still W-destructible. So the result has no W-destructible point, and it is exactly Pink's result whenever Pink's result had none. The lines with markers use the same code; no case was found where Pink's lines were wrong, and on the images of the tests they are unchanged.
Watershed lines with markers. The marker image chooses the basins: each marker region becomes the only minimum of its basin, the other minima are ignored (a geodesic reconstruction in the component tree, as the conclusion of [CNB05] suggests), and the result is the binary image of the points outside the spread minima: 1 on the lines, 0 in the basins. Every nonzero marker value is a marker point. Pink imposes the markers at level 0, the lowest level: a marker region is therefore a component of the marker points TOGETHER WITH the points of the image at 0. Two markers joined by points at 0 (or adjacent to each other) form one region, and get no line between them; on an image at 0 everywhere, there is never a line. Each component of the points off the lines contains exactly one marker region, and no line point lies on a marker region. One marker region, or markers that cover the whole image, give no line at all.
Connectivity. The connectivity parameter is the adjacency of the graph of the image: the connectivity of the lakes, the basins and the minima. The crest lines, which separate them, are thin for the other connectivity: with connectivity 4 a line may go diagonally (it is 8-connected), with 8 it is 4-connected. Accepted values: 4 or 8 in 2D, 6, 18 or 26 in 3D.
Border. There is no frame and no outside: the image is the whole relief. A minimum that touches the side of the image is a minimum like any other, and two minima on opposite sides stay apart. (The homotopic operators of pink26/grayscale.h add no frame either: they never modify the border.)
Plateaus. On a plateau, the place of a crest line depends on the order in which Pink processes the points (its queues are first in, first out at each level): the line is not always in the middle of the plateau, and the result is not symmetric. It is still a topological watershed.
Pink and pink26. Pink's watershed spreads the MAXIMA of its image. Like Pink's commands wshedtopo and watershed without their option i, pink26 gives Pink the inverted image (255 - v) and inverts the result back, so that the minima spread. What pink26 changes in Pink's code: when the component tree has a single node (a constant image, or markers that cover the whole image), Pink's LCApreprocess (lwshedtopo.c) wrote past an empty allocation and could crash; pink26 fixes it (a marked edit of src/legacy/lwshedtopo.c), which does not change the results. pink26 also refuses an empty marker image, on which Pink reads outside its tree. It fixes two other defects of Pink's code, which do not change its results either: a table of its lowest-common-ancestor search was too small when the tree had few nodes (a heap overflow, even on a 1 x 3 image), and the volume of a component, which the watershed does not use, overflowed int32_t beyond 8388608 points. The correction of Pink's seeding, which can change the result, is described above.
Size. Pink counts the points in int32_t: an image of more than INT32_MAX (2147483647) points is refused before any call to Pink (P26_E_OVERFLOW). Pink also computes the sizes of its lowest-common-ancestor tables in int32_t, which can overflow from about 8 x 10^7 points (images with very many minima): pink26 therefore refuses, also before any call to Pink, an image of more than 2^25 = 33554432 points (P26_E_UNSUPPORTED); 5792 x 5792 in 2D and 322 x 322 x 322 in 3D still fit. The int32_t check comes first: more than INT32_MAX points give P26_E_OVERFLOW.
Pink functions used (lwshedtopo.c, mccomptree.c; Couprie, Najman, ESIEE):
pink26 function 2D and 3D command p26_topological_watershed lwshedtopo_lwshedtopo (inverted) wshedtopo (without i) p26_watershed_lines lwshedtopobin (inverted) watershed (without i)
References: [CB97] M. Couprie, G. Bertrand, "Topological grayscale watershed transformation", Proc. SPIE Vision Geometry VI, vol. 3168, 1997, pp. 136-146 (no local copy: not checked; cited by [Ber05] and [CNB05]). [Ber05] G. Bertrand, "On topological watersheds", Journal of Mathematical Imaging and Vision 22(2-3), 2005, pp. 217-230. [CNB05] M. Couprie, L. Najman, G. Bertrand, "Quasi-linear algorithms for the topological watershed", Journal of Mathematical Imaging and Vision 22(2-3), 2005, pp. 231-249.
| p26_status p26_topological_watershed | ( | const p26_image * | image, |
| int | connectivity, | ||
| p26_image ** | out ) |
Topological watershed ([Ber05], [CNB05]; Pink's lwshedtopo_lwshedtopo on the inverted image, command wshedtopo).
Lowers W-destructible points until none is left (see the top of this file). The result is at most the input at every point, is a W-thinning of it, keeps the same number of minima, at the same levels, and the level of the passes between them, and does not change when the function is applied to it again. It has no W-destructible point (on this point pink26 corrects Pink, see the top of this file).
| image | P26_U8 image, 2D or 3D. |
| connectivity | Connectivity of the minima and the basins: 4 or 8 in 2D, 6, 18 or 26 in 3D. |
| out | Set to NULL on entry; receives a new P26_U8 image of the shape of image (released with p26_image_free()). |
Complexity: quasi-linear time in the number N of points ([CNB05]); memory: the copy of image (1 byte per point) and Pink's component tree, maps and queues, about 100 bytes per point (more when the image has many minima).
| p26_status p26_watershed_lines | ( | const p26_image * | image, |
| const p26_image * | markers, | ||
| int | connectivity, | ||
| p26_image ** | out ) |
Watershed lines with markers (Pink's lwshedtopobin on the inverted image, command watershed).
The topological watershed of image in which only the marker regions are minima (see the top of this file), as a binary image: 1 on the lines, 0 in the basins. Each component (in connectivity) of the points at 0 contains exactly one marker region, and no point of a marker region is a line point.
| image | P26_U8 image, 2D or 3D. |
| markers | P26_U8 image of the shape of image: every nonzero point is a marker point; at least one is required. |
| connectivity | As p26_topological_watershed(). |
| out | Set to NULL on entry; receives a new P26_U8 image of the shape of image, at 0 or 1 (released with p26_image_free()). |
Complexity: as p26_topological_watershed(), plus a 0/1 copy of markers and Pink's own copy of it (1 byte per point each).