_u
intermediate images. There are other fast algorithms proposed to reduce this storage requirement [2, 3, 4, 5]. It may also be more efficient to replace the characteristic functionLONPRQSTQUTQ}Q8JP[
by a lookup table.
6.3.
Labeling Components with Sequential Labels
The component labeling algorithms of Section 6.2 began by assigning each point in the domain of the source image the number that represents its position in a forward scan of the domain grid. The label assigned to a component is either the maximum or minimum from the set of point numbers encompassed by the component (or its bounding box). Consequently, label numbers are not used sequentially, that is, in d +RR u
order. In this section two algorithms for labeling components with sequential labels are presented. The first locates connected components and assigns labels sequentially, and thus takes the source image as input. The second takes as input labeled images, such as those produced by the algorithms of Section 6.2, and reassigns new labels sequentially.
It is easy to determine the number of connected components in an image from its corresponding sequential label image; simply find the maximum pixel value of the label image. The set of label numbers is also known, namely
dR&&
where
is the maximum pixel value of the component image. If component labeling is one step in larger image processing regimen, this information may facilitate later processing steps.
Labeling with sequential labels also offers a savings in storage space. Suppose one is working withd`d
gray level images whose pixel values have eight bit representations. Up to
labels can be assigned if labeling with sequential labels is used. It may not be possible to represent the label image at all if labeling with sequential labels is not used and a label value greater than
6. 3 Labeling Components with Sequential Labels 177
Image Algebra Formulation
Lets+R be the source image, where is an grid. The neighborhood
used is either the von Neumann neighborhood for labeling 4-connected components, or the Moore neighborhood for labeling 8-connected components.
When the algorithm below ends, the sequential label image will be contained in image variable . ¡¢ ¡8¢ £ ¡8¢ ¤¥¦¨§ª©« ¬z¬8® ¥&¥¯ ¤¥¦E°±©« ¬²¬8 ¥G¥>¯ ©¤ ³ § °>´ ¢ nµ¶· « ¡8¢¸ *¹ º³ § °´ ¡¢ »³ § °´ ¹@ ¼ ¶ © +·~k½ ¢ £ ¥G¥>¯ £ ¡¢ ¡¢ ³ £¿¾ À ´ºÁ · «Â ¥&¥>¯ · «Â~©¤ · «Â ¥G¥>¯ · «Â ¥G¥>¯ ¡8¢ Äø'¬
Alternate Image Algebra Formulation
The alternate image algebra algorithm takes as input a label image and reassigns
labels sequentially. When the ¼
¶
©
+· loop in the pseudocode below terminates, the image
variable will contain the sequential label image. The component connectivity criterion
(four or eight) for will be the same that was used in generating the image .
§ ¡8¢ ¡8¢¸Å ¡8¢ ¾ ¼ ¶ © +·ÆÇ½ ¢ ` ¥&¥>¯ § ¡¢ § ¹ ¡8¢ §'ÁTÈwÉ*Ê ³^ ´ ¹ ¡8¢ ³ ÈË Ê ³V ´´Á ¡8¢ ¾ · «Â ¥&¥>¯ ¬
Comments and Observations
Figure 6.3.1shows a binary image (left) whose feature pixels are represented by an asterisk. The pixel values assigned to its 4- and 8-components after sequential labeling are seen in the center and right images, respectively, of Figure 6.3.1.
178 CHAPTER 6. CONNECTED COMPONENT ALGORITHMS
Figure 6.3.1. A binary image, its 4-labeled image (center) and 8-labeled image (right).
6.4.
Counting Connected Components by Shrinking
The purpose of the shrinking algorithm presented in this section is to count the connected components in a Boolean image. The idea, based on Levialdi’s approach [6], is to shrink each component to a point and then count the number of points obtained. To express this idea explicitly, letÌÎÍÏÐÑÒÓÔ denote the source image and let Õ denote the
Heaviside function defined by
Õ×ÖÙØ ÚÛÜ
ÐÞÝ8ߨºà@Ð ÒáÝ}ßOغâ@Ðã
One of four windows may be chosen as the shrinking pattern. Each is distinguished by the direction it compresses the image.
Shrinking toward top right —
ÌÖ\äÑXåÚ¸æ8Û6ÕKçÕ×Ö^Ì×Öqä Ñ\å¿è@ÒÚé¸Ì×Öqä Ñ\åÚ'éêÌÖqä*é@ÒÑ\åÚKè@ÒÚéÕÖVÌÖqä ÑXå>ÚKéÄÌÖ\äéDÒÑXå#è@ÒÚKè@ÒRÚVëã
Shrinking toward top left —
ÌÖ\äÑXåÚ¸æ8Û6ÕKçÕ×Ö^Ì×Öqä Ñ\åÚ'éêÌÖqä Ñ\å¿é@ÒÚ'éêÌÖqä*é@ÒÑ\åÚKè@ÒÚéÕÖVÌÖqä ÑXå>ÚKéÄÌÖ\äéDÒÑXåºéDÒÚKè@ÒRÚVëã
Shrinking toward bottom left —
ÌÖ\äÑXåÚ¸æ8Û6ÕKçÕ×Ö^Ì×Öqä Ñ\åÚ'éêÌÖqä×èìÒÑ\åÚ'éêÌÖqä Ñ\å¿é@ÒÚKè@ÒÚéÕÖVÌÖqä ÑXå>ÚKéÄÌÖ\äè@ÒÑXåºéDÒÚKè@ÒRÚVëã
Shrinking toward bottom right —
ÌÖ\äÑXåÚ¸æ8Û6ÕKçÕ×Ö^Ì×Öqä Ñ\åÚ'éêÌÖqä Ñ\ånèìÒÚ'éêÌÖqä×èìÒÑ\åÚKè@ÒÚéÕÖVÌÖqä ÑXå>ÚKéÄÌÖ\äè@ÒÑXå#è@ÒÚKè@ÒRÚVëã
Each iteration of the algorithm consists of applying, in parallel, the selected shrinking window on every element of the image. Iteration continues until the original image has been reduced to the zero image. After each iteration the number of isolated points is counted and added to a running total of isolated points. Each isolated point corresponds to an 8-connected component of the original image.
This shrinking process is illustrated in the series (in left to right and top to bottom order) of images in Figure 6.4.1. The original image (in the top left corner) consists of five 8-connected patterns. By the fifth iteration the component in the upper left corner has been reduced to an isolated pixel. Then the isolated pixel is counted and removed in the
6. 4 Counting Connected Components by Shrinking 179 following iteration. This process continues until each component has been reduced to an isolated pixel, counted, and then removed.
Figure 6.4.1. The parallel shrinking process.
Image Algebra Formulation
Let be the source image. We will illustrate the image algebra formulation using the shrinking window that compresses toward the top right. This choice of shrinking window dictates the form of neighborhoods and below. The template
is used to find isolated points.
N
=
M = O
=
The image variable a is initialized with the original image. The integer variable
180 CHAPTER 6. CONNECTED COMPONENT ALGORITHMS image variable a is reduced to the zero image.
!#" %$%$& ')(! '+*-, . +/ .1032-. 54 687:919;9 (!=<?>A@ .<?>CB . * 6EDF9 * <?>GB . * 6-HI9J9 LK%MN%$%$&PO
When the algorithm terminates, the value of'
will represent the number of 8-connected components of the original image.
Alternate Image Algebra Formulation
The above image algebra formulation closely parallels the formulation presented in Levialdi [6]. However, it involves three convolutions in each iteration. We can reduce number of convolutions in each iteration to only one by using the following census template. A binary census template (whose weights are powers of 2), when applied to a binary image, encodes the neighborhood configurations of target pixels. From the configuration of a pixel, we can decide whether to change it from 1 to 0 or from 0 to 1, and we can also decide whether it is an isolated pixel or not.
=
1
2
4
8
16
32
64
Q128
256
Rs
SThe algorithm using the binary census template is expressed as follows:
TUAVXWYZ\[ ]#^ W%_%_` Zba ] Zdc eEf g a ] g c-hjilknmGoipZrq;q Zba]ts iuZrq YLvwxW%_%_`zy
In order to count 8-components, the function s
should be defined as s i;{q ]F|)}~ {: } 1J;}}}XL}J}}L XJJ~; y
The 4-components of the image can be counted by defining s
to be s i;{q ] | }~ {j5 }11L}}}LL}rL}; XJ;~J y
In either case, the movement of the shrinking component is toward the pixel at the top right of the component.
6. 5 Pruning of Connected Components 181
Comments and Observations
The maximum number of iterations required to shrink a component to its cor- responding isolated point is equal to the ¡ distance of the element of the region farthest
from top rightmost corner of the rectangle circumscribing the region.
6.5.
Pruning of Connected Components
Pruning of connected components is a common step in removing various unde- sirable artifacts created during preceding image processing steps. Pruning usually removes thin objects such as feelers from thick, blob-shaped components. There exists a wide variety of pruning algorithms. Most of these algorithms are usually structured to solve a particular task or problem. For example, after edge detection and thresholding, various objects of interest may be reduced to closed contours. However, in real situations there may also be many unwanted edge pixels left. In this case a pruning algorithm can be tailored so that only closed contours remain.
In this section we present a pruning algorithm that removes feelers and other objects that are of single-pixel width while preserving closed contours of up to single-pixel width as well as 4-connectivity of components consisting of thick bloblike objects that may be connected by thin lines. In this algorithm, a pixel is removed from an object if it contains fewer than two 4-neighbors. The procedure is iterative and continues until every object pixel has two or more 4-neighbors.
Image Algebra Formulation
Let ¢¤£F¥¦§¨©Lª be the source image and « denote the von Neumann neigh-
borhood. The following simple algorithm will produce the pruned version of a described
above: ¬I®°¯ ±²A³X´µ ¬·¶® ¢ ´¸%¸¹ ¬Iº® ¢ ¢ º®»?¼½¿¾ ¢5ÀLÁl¢ÃÂ Ä «ÆÅuÇ µÈÉx´%¸%¸¹CÊ
The results of applying this pruning algorithm are shown in Figure 6.5.1.
Figure 6.5.1. The source image a is shown at the left and the pruned version of a on the right.