ImageDev

Hit Or Miss And Skeleton

Algorithms computing morphological skeleton and applying post-processing on it.
The Hit-or-miss and Skeleton category contains algorithms used to produce simplified representations of image objects, while preserving their geometrical structure. The representations then can be used to calculate length, direction, etc., or to detect special topological structures such as end or triple points (number of crossings).

Morphological LUT

Using a morphological LUT (Look Up Table) consists of moving some predefined configurations of neighborhood in a binary image and applying a decision when this configuration matches or not.

Creating a morphological LUT

First a kernel has to be defined to test whether a given pixel matches a criterion or not. The kernel is made of classical binary pixel values : 0, 1 and a specific one, 2, which means 'do not care'.

For example: $$ \begin{array}{ccc} 2 & 0 & 1\\ 2 & 1 & 0\\ 2 & 2 & 2 \end{array} ~~~\mbox{matches with}~~~ \begin{array}{ccc} 1 & 0 & 1\\ 1 & 1 & 0\\ 0 & 0 & 0 \end{array} ~~~\mbox{and}~~~ \begin{array}{ccc} 1 & 0 & 1\\ 1 & 1 & 0\\ 1 & 1 & 0 \end{array} ~~~\mbox{but not}~~~ \begin{array}{ccc} 0 & 1 & 1\\ 0 & 1 & 0\\ 0 & 0 & 0 \end{array} $$
A LUT to convert a binary image from an 8 neighbors connectivity to 4 neighbors connectivity can be defined, testing whether a given pixel has a neighbour in the north-east, north-west, south-west and south-east directions.
$$ \mbox{north-west:}~~~ \begin{array}{ccc} 1 & 0 & 2\\ 0 & 1 & 2\\ 2 & 2 & 2 \end{array} ~~~~~~~~~~~~\mbox{north-east:}~~~ \begin{array}{ccc} 2 & 0 & 1\\ 2 & 1 & 0\\ 2 & 2 & 2 \end{array} $$ $$ \mbox{south-west:}~~~ \begin{array}{ccc} 2 & 2 & 2\\ 0 & 1 & 2\\ 1 & 0 & 2 \end{array} ~~~~~~~~~~~~\mbox{south-east:}~~~ \begin{array}{ccc} 2 & 2 & 2\\ 2 & 1 & 0\\ 2 & 0 & 1 \end{array} $$
These kernels have to be added one by one to build the LUT by using the addKernel method. The kernelRotation parameter indicates whether the kernel must be rotated before being inserted. A value of zero inserts the kernel as is; a value of 2 transforms the north-west configuration above into the south-west configuration.
The LUT can be reinitialized with the reset, which removes all existing kernels from the LUT.

Applying a morphological LUT

Once a LUT is created, it has to be specified what has to be done with the pixels that match the LUT and those that do not. Two flag fields are available to specify the different actions: matchingFlag if the pixel matches and unmatchingFlag if it does not. There are 4 possible values: For example: to change the connectivity from 8 neighbors connectivity to 4, if the pixel matches the criterion, the output value has to be forced to 0 and if it does not it has to be left unchanged. Therefore, matchingFlag = SET_ZERO and unmatchingFlag = PRESERVE.

Applying a morphological LUT on a binary image can be performed with the ApplyMorphologicalLut2d and ApplyMorphologicalLut3d algorithms.

Thinning, thickening, and hit-or-miss operation with Morphological LUT

Morphological LUT's can be used to perform classical neighborhood operations such as thinning, thickening, and hit-or-miss: $$ \begin{array}{|c|c|c|} \hline \textbf{matchingFlag} & \textbf{unmatchingFlag} & \textbf{Operation}\\ \hline \mbox{SET_ZERO} & \mbox{PRESERVE} & \mbox{Thinning}\\ \hline \mbox{SET_ONE} & \mbox{PRESERVE} & \mbox{Thickening}\\ \hline \mbox{SET_ONE} & \mbox{SET_ZERO} & \mbox{Hit-or-miss}\\ \hline \end{array} $$

Skeletonization

Skeletonization is used to produce a simplified representation of the objects in an image, while preserving their geometrical structure. The representation then can be used to calculate length, direction, etc., or to detect special topological structures such as end or triple points (number of crossings).

Skeletonization is a transformation based on the thinning of connected components until a line is achieved. A skeleton is obtained by successive thinnings until convergence, using the L configuration and rotating it. The structuring element associated with the L configuration is: $$ \begin{array}{ccc} 1 & 1 & 1\\ \times & \bullet & \times\\ 0 & 0 & 0 \end{array} $$ where $\times$ means "don't care".

Point detectors

Once a skeleton is computed it may be useful to detect specific configurations of points. The point detectors use hit-or-miss transforms (HMT) to select target points.
The following algorithms are some point detectors: