Canadian Journal on Image Processing and Computer Vision Vol. 2 No. 7, November 2011 72 Connected Components Labeling Algorithm Based on Span Tracking Farag Ibrahim Younis Elnagahy Abstract — In this paper, a single scan algorithm for labeling of connected components in binary images is presented. The main feature of this algorithm is to label the entire component in one shot, to avoid the analysis of label equivalences. In the algorithm, the binary image is scanned row by row, from top to bottom and from left to right. When a starting pixel (seed) of a component is encountered, the scanning process is paused and the algorithm completely labels all pixels of that component with the same label. The scanning process is resumed and the labeling process is continued until the entire image is scanned. The performance of the proposed algorithm is compared with the well-known single scan labeling algorithm, Chang‘s contour tracing algorithm. Both algorithms generate consecutive labels for objects. Experimental results demonstrated that the presented algorithm is superior to contour tracing algorithm 1 . Key Words — Component- labeling algorithm, contour tracing, pixel spans. I. INTRODUCTION Connected component labeling is a fundamental process common to virtually all image processing applications in two and three dimensions [1-4]. The pixels in a connected component form a candidate region for representing an object. A component-labeling algorithm finds all connected components in an image and assigns a unique number (“label”) to all pixels in the same components. These labels are the keys for any subsequent analysis procedure and are used for distinguishing and referencing the objects. This makes connected component labeling an indispensable part of nearly all applications in pattern recognition and computer vision [5]. In many cases, connected component labeling is also one of the most time-consuming tasks among other pattern- recognition algorithms. Therefore, connected component algorithms usually form a bottleneck in machine vision systems. Many algorithms have been proposed for connected component labeling. They can be classified into two categories according to computer architecture and image representations. The algorithms of the first category are suitable for ordinary 1 Farag Elnagahy is with the King ABDUL AZIZ University, Faculty of Computing and Information Technology, Department of Computer Science, Kingdom of Saudi Arabia. The author is also with the National Research Institute of Astronomy and Geophysics (NRIAG), Department of Astronomy, Helwan, Cairo, Egypt. faragelnagahy@hotmail.com computer architectures and two-dimensional images; there are mainly the following three classes of algorithms [6]: (1) Multi-scan algorithms [7-8]: in these algorithms, the image is scanned in the forward and backward raster directions alternately to propagate label equivalences until no label changes. (2) Two-scan algorithms [6, 9–19]: two scans are performed to complete the labeling process. In the first scan, provisional labels are assigned to object pixels, and the label equivalences are recorded. Label equivalences are resolved during or after the first scan. All equivalent labels are replaced by their representative label in the second scan. (3) One-scan algorithms [1, 20-21]. These algorithms avoid analysis of label equivalences by tracing the contours of objects (connected components) or by the use of an iterative recursion operation. The most efficient algorithm in this group is Chang's contour- tracing algorithm [21]. The algorithms of the second category are suitable for special image representations and special computer architectures. This category can be divided into the following two classes: (1) Algorithms for hierarchical image formats [16, 22- 25]: There are many labeling algorithms that are developed for more complex image formats than the simple 2D array. These images are represented by hierarchical tree structures such as bintree, quadtree, octree, etc. (2) Parallel algorithms [26-31]: These algorithms were developed for parallel machine models such as a mesh-connected massively parallel processors or systolic array processors. This paper is organized as follows: In section II a brief description of the most efficient single scan labeling algorithm; contour-tracing labeling algorithm (CTLA) is presented. The general structure of the proposed labeling algorithm is presented in section III. Section IV discusses experimental results of the proposed and the CTLA for various images. The paper concludes with Section V. II. CONTOUR TRACING LABELING ALGORITHM (CTLA) In this algorithm, a binary image is scanned from top to bottom and from left to right per each line. When an external contour pixel A is encountered the first time (i.e. unlabeled pixel), the algorithm performs a complete trace of the contour pixels until returns A as shown in Fig. 1a. Pixel A and all pixel