Abstract
We present two optimization strategies to improve connected-component labeling algorithms. Taking together, they form an efficient two-pass labeling algorithm that is fast and theoretically optimal. The first optimization strategy reduces the number of neighboring pixels accessed through the use of a decision tree, and the second one streamlines the union-find algorithms used to track equivalent labels. We show that the first strategy reduces the average number of neighbors accessed by a factor of about 2. We prove our streamlined union-find algorithms have the same theoretical optimality as the more sophisticated ones in literature. This result generalizes an earlier one on using union-find in labeling algorithms by Fiorio and Gustedt (Theor Comput Sci 154(2):165–181, 1996). In tests, the new union-find algorithms improve a labeling algorithm by a factor of 4 or more. Through analyses and experiments, we demonstrate that our new two-pass labeling algorithm scales linearly with the number of pixels in the image, which is optimal in computational complexity theory. Furthermore, the new labeling algorithm outperforms the published labeling algorithms irrespective of test platforms. In comparing with the fastest known labeling algorithm for two-dimensional (2D) binary images called contour tracing algorithm, our new labeling algorithm is up to ten times faster than the contour tracing program distributed by the original authors.
![](http://media.springernature.com/m312/springer-static/image/art%3A10.1007%2Fs10044-008-0109-y/MediaObjects/10044_2008_109_Fig1_HTML.gif)
![](http://media.springernature.com/m312/springer-static/image/art%3A10.1007%2Fs10044-008-0109-y/MediaObjects/10044_2008_109_Fig2_HTML.gif)
![](http://media.springernature.com/m312/springer-static/image/art%3A10.1007%2Fs10044-008-0109-y/MediaObjects/10044_2008_109_Fig3_HTML.gif)
![](http://media.springernature.com/m312/springer-static/image/art%3A10.1007%2Fs10044-008-0109-y/MediaObjects/10044_2008_109_Fig4_HTML.gif)
![](http://media.springernature.com/m312/springer-static/image/art%3A10.1007%2Fs10044-008-0109-y/MediaObjects/10044_2008_109_Fig5_HTML.gif)
![](http://media.springernature.com/m312/springer-static/image/art%3A10.1007%2Fs10044-008-0109-y/MediaObjects/10044_2008_109_Fig6_HTML.gif)
![](http://media.springernature.com/m312/springer-static/image/art%3A10.1007%2Fs10044-008-0109-y/MediaObjects/10044_2008_109_Fig7_HTML.gif)
![](http://media.springernature.com/m312/springer-static/image/art%3A10.1007%2Fs10044-008-0109-y/MediaObjects/10044_2008_109_Fig8_HTML.gif)
Similar content being viewed by others
Notes
An implementation of the Contour Tracing algorithm distributed by the original authors of the algorithm is available from http://www.iis.sinica.edu.tw/∼fchang/03src.html.
Note that we have made an arbitrary choice of denoting a background pixel by 0 and an object pixel by 1; however, there are other equally valid choices [38]. It is also possible to use other types of labels than the integers used in this paper.
In C++ convention, all indices to arrays start from 0. The word array or vector in all pseudo-code segments is a short-hand of C++ STL type std::vector<unsigned> .
The computation uses the function lsqlin from the optimization toolbox of MATLAB.
References
Agarwal PK, Arge L, Ke Yi (2006) I/O-efficient batched union-find and its applications to terrain analysis. In: SCG ’06: Proceedings of the 22nd annual symposium on computational geometry. ACM Press, New York, pp 167–176
Aho AV, Hopcroft JE, Ullman JD (1974) The design and analysis of computer algorithms. Addison–Wesley, Reading
Aho AV, Ullman JD, Hopcroft JE (1983) Data structures and algorithms. Addison–Wesley, Reading
Alnuweiri HM, Prasanna VK (1992) Parallel architectures and algorithms for image component labeling. IEEE Trans Pattern Anal Mach Intell 14(10):1014–1034
Alstrup S, Ben-Amram AM, Rauhe T (1999) Worst-case and amortised optimality in union-find. In: Proceedings of 31th Annual ACM symposium on theory of computing (STOC’99). ACM Press, New York, pp 499–506
Amin A, Fisher S (2000) A document skew detection method using the Hough transform. Pattern Anal Appl 3(3):243–253
Ballard DH (1982) Computer vision. Prentice-Hall, Englewood
Bollobás B, Simon I (1985) On the expected behavior of disjoint set union algorithms. In: STOC ’85: Proceedings of the 17th annual ACM symposium on theory of computing. ACM Press, New York, pp 224–231
Chang F, Chen C-J, Lu C-J (2004) A linear-time component-labeling algorithm using contour tracing technique. Comput Vis Image Underst 93(2):206–220
Dillencourt MB, Samet H, Tamminen M (1992) A general approach to connected-component labeling for arbitrary image representations. J ACM 39(2):253–280
Doyle J, Rivest RL (1976) Linear expected time of a simple union-find algorithm. Inf Process Lett 5(5):146–148
Fiorio C, Gustedt J (1996) Two linear time union-find strategies for image processing. Theor Comput Sci 154(2):165–181
Fiorio C, Gustedt J (1997) Memory management for union-find algorithms. In: Proceedings of 14th symposium on theoretical aspects of computer Science. Springer, New York, pp 67–79
Gabow HN, Tarjan RE (1983) A linear-time algorithm for a special case of disjoint set union. In: STOC ’83: Proceedings of the 15th annual ACM symposium on theory of computing. ACM Press, New York, pp 246–251
Galil Z, Italiano GF (1991) Data structures and algorithms for disjoint set union problems. ACM Comput Surv 23(3):319–344
Galler BA, Fisher MJ (1964) An improved equivalence algorithm. Commun ACM 7(5):301–303
Gonzalez RC, Woods RE (2002) Digital Image Processing, 2nd edn. Prentice-Hall, New Jersy
Gotoh T, Ohta Y, Yoshida M, Shirai Y (1987) Component labeling algorithm for video rate processing. In: Proceedings of SPIE 1987. Advances in image processing, vol 804, pp 217–224
Haralick RM (1981) Some neighborhood operations. Plenum Press, New York, pp 11–35
Haralick RM, Shapiro LG (1985) Image segmentation techniques. Comput Vis Graph Image Process 29(1):100–132
Hayashi H, Kudo M, Toyama J, Shimbo M (2001) Fast labelling of natural scenes using enhanced knowledge. Pattern Anal Appl 4(1):20–27
Qingmao H, Guoyu Q, Nowinski WL (2005) Fast connected-component labelling in three-dimensional binary images based on iterative recursion. Comput Vis Image Underst 99:414–434
Kim J-H, Kim KK, Suen CY (2000) An HMM-MLP hybrid model for cursive script recognition. Pattern Anal Appl 3(4):314–324
Knop F, Rego V (1998) Parallel labeling of three-dimensional clusters on networks of workstations. J Parallel Distrib Comput 49(2):182–203
Knuth DE, Schönhage A (1978) The expected linearity of a simple equivalence algorithm. Theor Comput Sci 6:281–315
Lucas JM (1990) Postorder disjoint set union is linear. SIAM J Comput 19(5):868–882
Lumia R (1983) A new three-dimensional connected components algorithm. Comput Vis Graph Image Process 23(2):207–217
Lumia R, Shapiro L, Zungia O (1983) A new connected components algorithm for virtual memory computers. Comput Vis Graph Image Process 22(2):287–300
Moga AN, Gabbouj M (1997) Parallel image component labeling with watershed transformations. IEEE Trans Pattern Anal Mach Intell 19(5):441–450
Naoi S (1995) High-speed labeling method using adaptive variable window size for character shape feature. In: IEEE Asian Conference on computer vision, vol 1, pp 408–411
Otsu N (1979) A threshold selection method from gray level histograms. IEEE Trans Syst Man Cybern 9:62–66
Regentova E, Latifi S, Deng S, Yao D (2002) An algorithm with reduced operations for connected components detection in itu-t group 3/4 coded images. IEEE Trans Pattern Anal Mach Intell 24(8):1039–1047
Rosenfeld A (1970) Connectivity in digital pictures. J ACM 17(1):146–160
Rosenfeld A, Kak AC (1982) Digital picture processing, 2nd edn. Academic Press, San Diego
Shi J, Malik J (2000) Normalized cuts and image segmentation. IEEE Trans Pattern Anal Mach Intell 22(8):888–905
Stockman GC, Shapiro LG (2001) Computer Vision. Prentice-Hall, Englewood
Suri JS, Singh B, Reden L (2002) Computer vision and pattern recognition techniques for 2-d and 3-d MR cerebral cortical segmentation: a state-of-the-art review. Pattern Analy Appl 5(1):46–76
Suzuki K, Horiba I, Sugie N (2003) Linear-time connected-component labeling based on sequential local operations. Comput Vis Image Underst 89(1):1–23
Tarjan RE, van Leeuwen J (1984) Worst-case analysis of set union algorithms. J ACM 31(2):245–281
Tarjan RE (1975) Efficiency of a good but not linear set union algorithm. J ACM 22(2):215–225
Tarjan RE (1977) Reference machines require non-linear time to maintain disjoint sets. In: STOC ’77: Proceedings of the 9th annual ACM symposium on theory of computing. ACM Press, pp 18–29
Udupa JK, Ajjanagadde VG (1990) Boundary and object labelling in three-dimensional images. Comput Vis Graph Image Process 51(3):355–369
Wang K-B, Chia T-L, Chen Z, Lou D-C (2003) Parallel execution of a connected component labeling operation on a linear array architecture. J Inf Sci Eng 19:353–370
Wang Y, Bhattacharya P (2003) Using connected components to guide image understanding and segmentation. Mach Graph Vis 12(2):163–186
Wu K, Otoo E, Shoshani A (2005) Optimizing connected component labeling algorithms. In: Proceedings of SPIE medical imaging conference 2005, San Diego, CA, 2005. LBNL report LBNL-56864
Yao AC (1985) On the expected performance of path compression algorithms. SIAM J Comput 14(1):129–133
Yapa RD, Koichi H (2007) A connected component labeling algorithm for grayscale images and application of the algorithm on mammograms. In: SAC’07: Proceedings of the 2007 ACM symposium on applied computing. ACM Press, New York, pp 146–152
Acknowledgment
This work was supported in part by the Office of Science of the U.S. Department of Energy under Contract No. DE-AC03-76SF00098.
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
About this article
Cite this article
Wu, K., Otoo, E. & Suzuki, K. Optimizing two-pass connected-component labeling algorithms. Pattern Anal Applic 12, 117–135 (2009). https://doi.org/10.1007/s10044-008-0109-y
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s10044-008-0109-y