2017 2nd International Conference on Artificial Intelligence and Engineering Applications (AIEA 2017)
ISBN: 978-1-60595-485-1
An Algorithm for Calculating Objects’ Shape
Features in Binary Images
LIFENG HE, YUYAN CHAO, XIAO ZHAO, BIN YAO, HIDETO KASUYA and ATSUSHI OHTA
ABSTRACT
The shape features of objects (connected components) in binary images are very important for image analysis, pattern (object) recognition, and computer vision. Conventional algorithms for calculating the shape features of objects in binary images can only calculate the shape features of objects without holes. This paper presents an algorithm or calculating the shape features of objects in binary images with holes. Based on a contour-tracing-based connected-component labeling algorithm, our proposed algorithm can calculate the number of objects, the number of holes, the Euler number in a binary image, extract the contours of objects, and calculate the area, perimeter, circularity, centroid of each object. Our proposed algorithm is able to make a contribution to image analysis, pattern recognition, and computer vision.
KEYWORDS
algorithm, shape feature, image analysis, pattern recognition, computer vision.
INTRODUCTION
The number of objects, the number of holes, the Euler number in a binary image, the contours of objects, and basic shape features of objects, i.e., areas, perimeters, circularities, and centroids, are very important for pattern recognition, image analysis and computer vision [1]-[2].
In binary images, the concept of objects is equal to that of connected components. Therefore, by conventional algorithms, before calculating basic shape features of objects in a binary image, we usually need to perform connected-component labeling to distinguish different objects in the image. By connected-component labeling [3]-[11], all pixels of each connected component (object) in a binary image will be assigned a unique label corresponding to the object; thus, we can distinguish different objects by their labels. Then, we can calculate the basic shape features of each object according to its label.
_________________________________________
Moreover, all conventional algorithms can only calculate the basic shape features of objects without holes, and if the number of holes and/or the Euler number in a binary image are also necessary, the corresponding calculations will be needed respectively.
This paper proposes an algorithm for calculating areas, perimeters, circularities, and centroids of each object in which there may be holes in a binary image. The proposed algorithm incorporates basic shape feature computation into a contour-tracing-based connected-component labeling algorithm. By connected-component labeling, we can obtain the number of connected components, the number of holes, the contours of objects and holes. During connected-component labeling, we record the data related to shape features of objects. After connected-component labeling, we use the recorded data to calculate the shape features of objects.
The remains of this paper are organized as follows. Section II introduces the concepts about connected components, holes, the Euler number, areas, perimeters, circularities, and centroids of objects, and Setion III reviews conventional algorithms for calculating shape features of objects in a binary image. Then, we introduce the contour-tracing-based connected compoent labeling algorithm in Section IV, and our proposed algorithm in Section V. Lastly, we give the conclusion in Section VI.
CONNECTED COMPONENTS, HOLES, THE EULER NUMBER, AREAS, PERIMETERS, CIRCULARITIES, AND CENTROIDS OF OBJECT
For an N × M-size binary image, we use p(i, j) to denote a pixel as well as its value at (i, j) in the image, where 0 i < N and 0 j < M. We assume that object (foreground) pixels and non-object (background) pixels in a given binary image are represented by 1 and 0, respectively.
For pixel p(i, j), the four pixels p(i1, j), p(i, j1), p(i1, j), and p(i, j1) are called
the p(i, j)’s 4-neighbors; the four-neighbors together with the four pixels p(i1, j1), p(i1, j1), p(i1, j1), and p(i1, j1) as shown in Fig. 1(b) are called the p(i, j)’s
8-neighbors of the pixel. Two object pixels s and t are said to be 4-connected
(8-connected) if there is a path which consists of object pixels a1, a2, , an such that a1 =
s and an = t, and for all 1 kn1, ak and ak+1 are 4-neighbor (8-neighbor) for each
other.
A set of object pixels in the image is said to be a 4-connected (8-connected)
component in a binary image if and only if any of two pixels in the set are 4-connected
(8-connected). A connected component is also called an object. Because objects with
8-connectivity are more complicated than those with 4-connectivity, in this paper, only objects with 8-connectivity will be considered. On the other hand, a hole is a
maximum set of background pixels such that they are enclosed by foreground pixels, and any two pixels in the set are 4-connected. The Euler number of a binary image is the difference of the number of connected components and that of holes in the image.
The area of an object O, AO,is defined as the number of the pixels in O, i.e.,
AO = | {p(x, y) | p(x, y) O} | (1)
The area of the holes in an object O, AH,is defined as the number of the pixels in
AHO = | {p(x, y) | p(x, y) Hi and HiO} | (2)
The centroid of O, (X, Y), is defined to the average location of row and column of
the pixels in O, which can be calculated as follows.
X = AO, Y = AO (3)
where and are the sums of row and column of the pixels in O, i.e., =
O y x p x ) , (
and =
O y x p y ) , ( , respectively.
The perimeter of O, P, can be calculated by the numbers of patterns B1, B2, B3, and
Bd shown in Fig. 1 in the object O. Let Ni be the numbers of Bi, then, P can also be
calculated as follows [1], where K1 = 1/ , K2 = 1, K3 = 1/ , and Kd = ,
respectively. i d i iN K P
, 3 , 2 ,1 (4)
Lastly, the circularity of O, C, is defined as follows.
2
/
)
(
4
A
A
P
C
O
HO(5)
CONTOUR-TRACING-BASED CONNECTED COMPONENT LABELING ALGORITHM
The Contour-Tracing-based connected-component Labeling (CTL) algorithm
proposed in Ref. [4] is a contour-tracing-based algorithm. It processes pixels in the given binary image one by one in the raster scan. For the current pixel p(x, y), it does
nothing if p(x, y) is a background pixel, otherwise, i.e., p(x, y) is an object pixel, it
processes p(x, y) as follows, where l is initialized to 1:
(a) If p(x, y) is unlabeled and its upper neighbor, i.e., p(x, y 1), is a background
pixel, then p(x, y) must be on an external contour of a newly encountered object. The
CTL algorithm assigns label l to p(x, y) and all pixels on the external contour by
contour tracing. At the same time, it also marks all background pixels surrounding the external contour (the object) with 1 for distinguishing whether an object pixel is on an unprocessed internal contour or not (in order to prevent to trace a contour multi times). Then, the CTL algorithm increases the value of l by 1.
(b) If the pixel immediately below p(x, y), i.e., p(x, y + 1), is an unmarked
background pixel (i.e., p(x, y + 1) = 0), p(x, y) must be on a newly encountered internal
contour. If p(x, y) is unlabeled (in this case, its left neighbor of p(x, y), i.e., p(x 1, y),
must be a labeled pixel), the CTL algorithm assigns the same label of p(x 1, y) to p(x, y).Then, it uses contour tracing to find the internal contour from p(x, y), and assigns
the label of p(x, y) to all pixels on the counter. At the same time, it also marks all
Figure 1. Patterns for calculating perimeter.
(c) If p(x, y) is an unlabeled object pixels not being described in (a) and (b), then
the left neighbor of p(x, y), i.e., p(x 1, y), must be a labeled pixel. The CTL
algorithm assigns the label of p(x 1, y) to p(x, y).
Notice that by the CTL algorithm, each object pixel will be assigned a label which will never changes. Thus, after labeling, all pixels of an object will have the same label. Moreover, it is obvious that the number of objects and that of holes will be the times for tracing external contours and that for tracing interior contours, respectively.
PROPOSED ALGORITHM FOR CALCULATING OBJECTS’ SHAPE FEATURES IN BINARY IMAGE
We use O[l] to denote the object with label l, AO[l], HO[l], [l], [l], (X[l], Y[l]), P[l], and C[l] to denote the area of O[l], the hole area of O[l], the sums of row and
column of the pixels in O[l], centroid of O[l], the perimeter of O[l], and the circularity
of O[l], respectively. Moreover, NO and NH are used to denote to the number of objects
and that of holes in the given image.
For calculating objects’ shape features in a binary image, during labeling the image by use of the CTL algorithm, we record the data related to each object O[l] as
follows, where for each l, AO[l], HO[l],[l], [l], X[l], Y[l], P[l], C[l], NO and NH are
initialized to 0.
(a) For each object pixel p(x, y) assigned to label l, do AO[l] AO[l] + 1, [l]
[l] + x, and [l] [l] + y;
(b) For each background pixel belonging to the holes of O[l], do AHO[l] AHO[l]
+ 1;
(c) When tracing the external contour with label l (thus, it is the contour of O[l]),
record the contour, calculate the perimeter of the contour, i.e., P[l], according the
formula (4), and do NONO + 1.
(d) When tracing an interior contour, record the interior contour, and do NHNH
When the labeling finished, AO[l], AHO[l], [l], [l], P[l], and NH will be the real
data related to O[l]. Thus, we can calculate the centroid of O[l], i.e., (X[l], Y[l]), by use
of the formula (3) and the circularity of O[l], i.e., C[l], by use of the formula (5).
Moreover, the Euler number of the image, E, can be calculated by E = NO NH.
We implemented our proposed algorithm in the C language on a PC-based workstation (Intel Core i5-3470 [email protected], 4GB Memory, Ubuntu Linux OS), and compiled by the GNU C compiler (version 4.2.3) with the option –O. For each image used in our experimental test, the number of objects, the number of holes, the Euler number of the image, the areas, perimeters, circularities, and centroids of objects in the image were calculated correctly.
CONCLUSION
This paper proposed an algorithm for calculating the number of objects, the number of holes, the Euler number of a binary image, extract the contours of objects, and calculate the area, perimeter, circularity, centroid of each object. Our proposed algorithm will make a contribution to image analysis, pattern recognition, and computer vision.
ACKNOWLEDGEMENTS
This work was supported in part by the Grant-in-Aid for the National Natural Science Foundation of China under Grant No.61601271, No. 61471227, No. 61603234, and the DAIKO FUNDATJION, Japan; the Scientific Research Program Founded by Shaanxi Provincial Education Department under Grant No. 16JK1087.
REFERENCES
1. R.C. Gonzalez and R.E. Woods. Digital Image Processing, Addison-Wesley, Reading, Massachusetts, 1993.
2. R. Szeliski. Computer Vision: Algorithms and Applications. Springer, 2011.
3. L. He, Y. Chao, and K. Suzuki. “Two Efficient Label-Equivalence-Based Connected- Component Labeling Algorithms for Three-Dimensional Binary Images,” IEEE Transactions on Image Processing, 20(8), 2122-2134, 2008.
4. F. Chang, C J. Chen and C.J. Lu. “A linear-time component-labeling algorithm using contour tracing technique,” Comput. Vis. Imag. Underst. 93, pp. 206-220, 2004.
5. J. Martin-Herrero. “Hybrid object labelling in digital images”, Mach. Vision Appl., 18(1), pp.1-15, 2007.
6. He, Y. Chao, and K. Suzuki. “A run-based two-scan labeling algorithm”, IEEE Trans. On Image Processing,” 17(5), pp.749–756, 2008.
7. Wu, E. Otoo, and K. Suzuki. “Optimi zing two-pass connected-component labeling algorithms,” Pattern Anal. Appl. 12(2), pp. 117-135, 2009.
8. L. He, Y. Chao, K. Suzuki, and K. Wu. “Fast connected-component labeling,” Pattern Recognition, 42(9): 1977-1987, 2009.
9. C. Grana, D. Borghesani, and R. Cucchiara. “Optimized block-based connected components labeling with decision trees,” IEEE Trans. On Image Processing, 9(6): 1596-1609, 2010.
10. L. He, X. Zhao, Y. Chao, and K. Suzuk. “Configuration-Transition-Based Connected- Component Labeling,” IEEE Transactions on Image Processing, 23(2), 943-951, 2014.