pink26 0.1.1
Image processing and digital topology for teaching
Loading...
Searching...
No Matches
parallel_skeleton.h File Reference

Parallel thinning of binary images: critical kernels and two classic 2D thinnings. More...

#include <pink26/image.h>
#include <pink26/status.h>

Go to the source code of this file.

Enumerations

enum  p26_parallel_shape { P26_PARALLEL_ULTIMATE = 0 , P26_PARALLEL_CURVILINEAR = 1 , P26_PARALLEL_SURFACE = 2 }
 What a critical-kernel thinning keeps (see the top of this file). More...

Functions

p26_status p26_parallel_skeleton (const p26_image *binary, int connectivity, p26_parallel_shape shape, int symmetric, int max_steps, const p26_image *inhibit, p26_image **out)
 Parallel thinning based on critical kernels ([BC08], [BC14], [CB16]).
p26_status p26_zhang_wang_thinning (const p26_image *binary, int max_steps, p26_image **out)
 Zhang-Wang parallel thinning (2D; Zhang and Wang 1988; Pink's lskelzhangwang).
p26_status p26_guo_hall_thinning (const p26_image *binary, int variant, int max_steps, p26_image **out)
 Guo-Hall parallel thinning (2D; Guo and Hall 1992; Pink's lskelguohall).

Detailed Description

Parallel thinning of binary images: critical kernels and two classic 2D thinnings.

Sequential thinning (pink26/skeleton.h) removes ONE simple point at a time, so each step obviously keeps the topology. A parallel thinning removes a whole SET of points in each step. Removing several simple points together can break the topology even when each of them is simple: the two pixels of a 2-pixel segment are both simple, removing both erases the segment. A parallel algorithm must therefore choose which simple points may go together.

Critical kernels (Bertrand 2007; [BC08] in 2D, [BC14] and [CB16] in 3D) answer that question. Seen as a cubical complex, the object is made of faces (squares, edges, vertices; in 3D cubes too). A face f is "essential" when it is exactly the intersection of the largest faces of the object that contain it; its "core" is made of the essential faces strictly inside f. An essential face is "regular" when its core is reducible (it can be shrunk to a point without changing its topology), "critical" otherwise; the critical kernel is the set of the critical faces. Bertrand's theorem: any set between the critical kernel and the object has the topology of the object. In terms of points: the simple points may all go together, except that every small "crucial" configuration of simple points (in 2D: two 4-adjacent pixels, two diagonal pixels, a 2 x 2 square, recognised by the masks of [BC08]; in 3D also the configurations around an edge or a vertex) must keep at least one of its points.

Symmetric or asymmetric. A symmetric algorithm keeps ALL the points of every crucial configuration. It treats in the same way two configurations that are images of each other by a symmetry of the grid (a rotation of 90 degrees, a mirror, in 3D a permutation of the axes), so its result should not depend on how the object is oriented; but it may keep a small core where a single point would do: a 2 x 6 bar keeps 2 to 4 pixels in its middle, not one, because no pixel is "the" middle. An asymmetric algorithm keeps ONE point of each crucial configuration, chosen by a fixed rule (the first in a fixed direction): it thins further, down to one point for a disk, and its result depends a little on the orientation.

Shapes of the result:

  • ultimate: thin until no point can be removed. Each component without holes (2D), or without tunnels and cavities (3D), becomes a point or a small core; an annulus becomes a closed curve. The asymmetric algorithms leave no simple point outside inhibit;
  • curvilinear: also keep the 1D isthmuses, the points where the object is locally a curve: in 2D (lskelCK2) the points with T > 1 (two or more object components around them); in 3D (lskelCK3a, lskelACK3a, Pink's NEW_ISTHMUS rule) the points with T = 2 and T-bar = 1. The branches of the object stay as thin curves;
  • surface (3D only, lskelSK3): keep the 2D isthmuses, the points with T-bar = 2 and T = 1, where the object is locally a surface: a plate stays as a surface at most 2 voxels thick. An isthmus, once found, is kept until the end: the curvilinear and surface algorithms add it to their copy of the inhibit image. A new call starts without that memory, so these algorithms are not idempotent: thinning their result again may remove the isthmuses that have become simple (the ends of the curves, for instance), and k steps followed by a call until stability need not give the result of a single call. The ultimate algorithms have no memory: they are idempotent, and k steps then until stability give the same result as until stability.

Classic thinnings (2D only): Zhang and Wang 1988 and Guo and Hall 1992 are fast fully parallel algorithms from the image-processing literature, defined by local conditions on the 8 neighbours of a pixel, not by critical kernels. Pink states that Zhang-Wang is not topologically sound, and the Guo-Hall variants are not proved sound either: they may disconnect an object or remove a component. They are given for comparison in practical work; the critical-kernel algorithms are the ones with a proof.

What pink26 corrects in Pink's 3D functions (read this before comparing with Pink's commands skel_MK3, skel_AMK, skel_CK3a, skel_ACK3a, skel_SK3). The 2D functions are Pink's code unchanged: pink26 gives exactly Pink's results, and these kept the topology and the symmetries on every image tested. The five 3D functions had three defects, proved on the frozen original Pink (tests/oracle) and corrected in pink26 by marked edits of src/legacy/lskelpar3d.c ("pink26: fix"):

  1. Missing 0-cliques. The voxels of the object that contain a vertex of the grid form a 0-clique when that vertex is exactly their intersection ([BC14], Def. 2), i.e. when along each axis they lie on both sides of it; such a clique is always critical, and one of its voxels must stay. Pink recognised it only when two of the voxels are opposite corners of the 2 x 2 x 2 block, which misses three or four voxels pairwise adjacent by an edge. The five functions erased the 3-voxel object {(1,1,0), (2,2,0), (1,2,1)} entirely. Pink follows the papers here, and the papers are wrong for d = 0: the mask K0 of [BC14] (Def. 12(3)) and the mask M0 of [BC06] (Def. 13(3)) ask for an antipodal pair, and [BC14] Prop. 13 (like [BC06] Prop. 14(iii)) states that this characterises the critical 0-cliques. The triangle {(0,0,0), (1,1,0), (0,1,1)} of a block is a counterexample: its three voxels meet exactly in the central vertex (an essential, hence critical, 0-clique by Def. 2), it has no antipodal pair, and its 1-cliques are regular (Prop. 11), so no mask keeps any of its voxels. The 2D masks of [BC08] are exact because a set of pixels of a 2 x 2 square that meets both rows and both columns always contains a diagonal pair; in a 2 x 2 x 2 block, a set that meets both sides along each of the three axes need not contain an antipodal pair.
  2. Blocks not examined. The symmetric functions (MK3, CK3a, SK3) looked for 0-cliques only in the block whose corner of largest x, y and z is the voxel being examined: two voxels sharing only a vertex vanished in 6 of the 8 orientations, and a digital line along (1, -1, 1) vanished under MK3 and SK3. pink26 examines the 8 blocks of every simple voxel.
  3. Scan order. The symmetric functions marked the crucial voxels while scanning the image, and a clique that met a voxel marked earlier in the same scan was skipped: the raster order chose between two overlapping cliques, so the result was not invariant under the symmetries of the grid (MK3 differed after x <-> y on 3 random images out of 4). [BC14] (Def. 20, D-crucial cliques) lets a clique be skipped only for a voxel kept by a clique of HIGHER dimension; pink26 makes the marks of a pass visible only to the next passes. After the corrections, the five 3D functions keep the topology on every object of a 2 x 2 x 2 block, every object of a 2 x 2 x 3 column (the neighbourhood of a 1-clique), 20000 random 3 x 3 x 3 windows (one step and until stability, make exhaustive) and every random image tested, and MK3, CK3a and SK3 commute with the permutations of the axes and the mirrors. One step of the corrected MK3 equals, voxel for voxel, the D-crucial kernel computed from the definitions alone (no masks: [BC14] Def. 2, Th. 16, Alg. 2) on every object of a 3 x 3 x 2 slab and on random windows, and the five functions keep a voxel of every critical clique (tests/exhaustive/test_critical_kernel_reference_3d.c). The detection of 1- and 2-cliques is Pink's: the exhaustive tests found no defect there. Consequence for practical work: in 3D, pink26's results can differ from those of Pink's commands. On the 48 random images per function of the oracle (make oracle), pink26 gives Pink's result on 17 images for MK3, 32 for AMK3, 43 for CK3a, 42 for ACK3a and 20 for SK3. Corrections 1 and 2 keep a voxel of every critical 0-clique. Where Pink removed a whole such clique, the theorem no longer covers that step, and the results can differ from then on, even when Pink's final result has the right topology (AMK3 and ACK3a differ from Pink on about a quarter of random images). Correction 3 also changes results that were topologically valid: Pink's scan order kept one of two overlapping cliques where the symmetric definition keeps both, so pink26's symmetric results are a little larger (MK3 about 5 % more voxels than Pink's on random images of 14 x 12 x 10, SK3 about 1 %), and they no longer depend on the orientation of the object. Pink's other 3D functions (not exposed by pink26) are unchanged.

Connectivity: all these algorithms are written for an 8-connected object in 2D and a 26-connected object in 3D (background 4 / 6).

Border convention: as everywhere in pink26, the image is surrounded by an infinite background. pink26 gives Pink a copy with a frame of 2 pixels of background (Zhang-Wang and Guo-Hall look 2 pixels away), so an object that touches the side of the image is thinned as if the outside were background.

Pink functions used (lskelpar.c, lskelpar3d.c; Couprie, ESIEE):

shape        symmetric  2D (object 8)       3D (object 26, corrected)
ULTIMATE     yes        lskelMK2 [BC08]     lskelMK3 (see below)
ULTIMATE     no         lskelNK2b [BC08]    lskelAMK3 [CB16]
CURVILINEAR  yes        lskelCK2            lskelCK3a [BC14]
CURVILINEAR  no         (none)              lskelACK3a [CB16]
SURFACE      yes        (no meaning in 2D)  lskelSK3 [BC14]
SURFACE      no         (no meaning in 2D)  (none)
Zhang-Wang              lskelzhangwang
Guo-Hall                lskelguohall, variants 1, 2, 3

lskelMK3: Pink describes it as a version "revised after the IWCIA 2006 paper" ("révisée d'après le papier IWCIA 2006"), i.e. [BC06b] (a 2D paper, whose scheme the 3D functions extend); its 3D masks are those of [BC06] and [BC14].

References: [BC08] G. Bertrand, M. Couprie, "Two-dimensional parallel thinning algorithms based on critical kernels", Journal of Mathematical Imaging and Vision 31(1), 2008, pp. 35-56. [BC06] G. Bertrand, M. Couprie, "A new 3D parallel thinning scheme based on critical kernels", DGCI 2006, LNCS 4245, Springer, 2006, pp. 580-591. [BC06b] G. Bertrand, M. Couprie, "New 2D parallel thinning algorithms based on critical kernels", Combinatorial Image Analysis (IWCIA 2006), LNCS 4040, Springer, 2006, pp. 45-59 (as cited in M. Couprie, A. Saude, G. Bertrand, SIBGRAPI 2006, ref. [3]). [BC14] G. Bertrand, M. Couprie, "Powerful parallel and symmetric 3D thinning schemes based on critical kernels", Journal of Mathematical Imaging and Vision 48(1), 2014, pp. 134-148. [CB16] M. Couprie, G. Bertrand, "Asymmetric parallel 3D thinning scheme and algorithms based on isthmuses", Pattern Recognition Letters 76, 2016, pp. 22-31. G. Bertrand, "On critical kernels", Comptes Rendus Mathematique 345(7), 2007, pp. 363-367. Y. Y. Zhang, P. S. P. Wang, "A modified parallel thinning algorithm", Proc. 9th International Conference on Pattern Recognition, 1988, pp. 1023-1025. Z. Guo, R. W. Hall, "Fast fully parallel thinning algorithms", CVGIP: Image Understanding 55(3), 1992, pp. 317-328.

Enumeration Type Documentation

◆ p26_parallel_shape

What a critical-kernel thinning keeps (see the top of this file).

Enumerator
P26_PARALLEL_ULTIMATE 

thin until only non-removable points are left

P26_PARALLEL_CURVILINEAR 

keep 1D isthmuses: curves

P26_PARALLEL_SURFACE 

3D only: keep 2D isthmuses: surfaces

Function Documentation

◆ p26_parallel_skeleton()

p26_status p26_parallel_skeleton ( const p26_image * binary,
int connectivity,
p26_parallel_shape shape,
int symmetric,
int max_steps,
const p26_image * inhibit,
p26_image ** out )

Parallel thinning based on critical kernels ([BC08], [BC14], [CB16]).

Each step removes, all at once, the simple points outside inhibit that are not needed to keep the topology (the crucial configurations, see the top of this file) and, for the curvilinear and surface shapes, that are not isthmuses. The result is a subset of the input with exactly its topology (same components, holes; in 3D cavities and tunnels). In 3D, pink26 corrects Pink's functions for this (see "What pink26 corrects" at the top of this file).

Parameters
binaryP26_U8 image, 2D or 3D; any nonzero value is an object point.
connectivityConnectivity of the object: 8 in 2D, 26 in 3D (the background has 4 / 6).
shapeP26_PARALLEL_ULTIMATE, P26_PARALLEL_CURVILINEAR, or P26_PARALLEL_SURFACE (3D only).
symmetric1 for the symmetric algorithm, 0 for the asymmetric one (see the top of this file).
max_stepsNumber of parallel steps: any negative value runs until no point changes; 0 returns a 0/1 copy of binary without thinning; k > 0 runs at most k steps (fewer if the result is stable before). The result after k + 1 steps is a subset of the result after k steps.
inhibitNULL, or a P26_U8 image of the shape of binary: its nonzero points that are object points are never removed. Its points outside the object are ignored (pink26 gives Pink inhibit AND binary: Pink's lskelMK2 would otherwise let them change the result).
outSet to NULL on entry; receives a new P26_U8 image of the shape of binary, 1 on the result and 0 elsewhere (released with p26_image_free()).
Returns
P26_OK; P26_E_INVALID_ARG if out is NULL, binary or inhibit is not a valid image, symmetric is not 0 or 1, shape is not one of the three values, shape is P26_PARALLEL_SURFACE on a 2D image, connectivity is not a connectivity of the dimension (8 or 4 in 2D, 26 or 6 in 3D), or inhibit has another shape than binary; P26_E_UNSUPPORTED if connectivity is 4 or 6 (Pink defines these thinnings for 8- and 26-connected objects only), or for the combinations Pink does not provide: curvilinear asymmetric in 2D, surface asymmetric in 3D; P26_E_TYPE if binary or inhibit is not P26_U8; P26_E_OVERFLOW if the image with its 2-pixel frame is too large (in 2D Pink counts the pixels in int32: at most INT32_MAX framed pixels); P26_E_NOMEM if an allocation of pink26 fails; P26_E_INTERNAL if the admitted Pink code aborted, which includes an allocation failure inside Pink (message "out of memory"; the memory Pink allocated before is then leaked). On error, *out stays NULL.

Complexity: O(N) time per step for N pixels (each step visits every pixel a bounded number of times), and at most about the thickness of the object in steps; memory: the framed copies of the object and of the inhibit image (1 byte per pixel each) and Pink's work images (1 or 2 bytes per pixel).

◆ p26_zhang_wang_thinning()

p26_status p26_zhang_wang_thinning ( const p26_image * binary,
int max_steps,
p26_image ** out )

Zhang-Wang parallel thinning (2D; Zhang and Wang 1988; Pink's lskelzhangwang).

In each step, every object pixel with 2 to 6 object 8-neighbours and exactly one 0-to-1 transition around it (crossing number 1) is removed at once, except where the object is 2 pixels thick (Zhang and Wang's correction of the Zhang-Suen thinning, which erased lines of that thickness); the steps repeat until no pixel changes. The result is thin, but the algorithm is NOT topologically sound: it may disconnect or erase small parts. The object is 8-connected (no connectivity parameter).

Parameters
binaryP26_U8 2D image; any nonzero value is an object point.
max_stepsAs p26_parallel_skeleton().
outAs p26_parallel_skeleton().
Returns
P26_OK; P26_E_INVALID_ARG if out is NULL, binary is not a valid image or is 3D; P26_E_TYPE if binary is not P26_U8; P26_E_OVERFLOW, P26_E_NOMEM, P26_E_INTERNAL as p26_parallel_skeleton(). On error, *out stays NULL.

Complexity: as p26_parallel_skeleton().

◆ p26_guo_hall_thinning()

p26_status p26_guo_hall_thinning ( const p26_image * binary,
int variant,
int max_steps,
p26_image ** out )

Guo-Hall parallel thinning (2D; Guo and Hall 1992; Pink's lskelguohall).

In each step, every object pixel on the 4-border of the object with more than 2 object 8-neighbours and crossing number 1 is removed, except some configurations that depend on the variant:

  • 1: Guo and Hall's first algorithm (an L-shaped test, 2 pixels away);
  • 2: three tests on diagonal configurations instead;
  • 3: variant 2, plus the removal of two kinds of end pixels. The steps repeat until no pixel changes. Like Zhang-Wang, these variants are not proved topologically sound. The object is 8-connected.
Parameters
binaryP26_U8 2D image; any nonzero value is an object point.
variant1, 2 or 3 (Pink's skelpar commands 8, 9, 10).
max_stepsAs p26_parallel_skeleton().
outAs p26_parallel_skeleton().
Returns
P26_OK; P26_E_INVALID_ARG if out is NULL, binary is not a valid image or is 3D, or variant is not 1, 2 or 3; P26_E_TYPE if binary is not P26_U8; P26_E_OVERFLOW, P26_E_NOMEM, P26_E_INTERNAL as p26_parallel_skeleton(). On error, *out stays NULL.

Complexity: as p26_parallel_skeleton().