# A Novel Connected-Components Algorithm for 2D Binarized Images
## 2 Materials and Methods
### Extraction of Connected Components  
Once all rows have been processed, connected components are extracted via Algorithm 4. The final output is a labeled image where each connected component is uniquely identified. ``` Input: List of connected components Output: Labeled image ```
1. For i = 1:RunList.Length
2. \(N_{i}\leftarrow\) RunList(i).First
3. If\(N_{i}\).head = \(N_{i}\)
4. Do
5. \(N_{i}\).label \(\gets i\)
6. \(N_{i}\gets N_{i}\).next
7. While\(N_{i}\)! = NULL
```

**Algorithm 4**Connected Component Labeling Pseudocode

### Discussion on 4-Way vs. 8-Way Connectivity

The choice between 4-way and 8-way connectivity significantly impacts the number of connected components and algorithm complexity. While 4-way connectivity tends to produce more distinct components, 8-way connectivity captures diagonal connections and reduces fragmentation, making it more suitable for natural images and complex structures. The proposed method describes the approach of the authors' patented application for identifying connected components in binary images [20]. Since the original patent documentation is available only in Romanian, the present article offers a comprehensible, self-contained description of the said algorithm in order to improve its overall accessibility. However, it is important to note that additional optimizations and tests were performed compared to the original code, adding a variety of improvements in certain scenarios. Figure 1 shows an example image, going through the run-lengths generation and then through merging using 8-way connectivity. The run segments and connected components were assigned random colors to easily visualize them. The three images are separated by horizontal gray bars. ## 3 Results

This section presents the experimental evaluation of the proposed method, detailing the experimental setup, dataset characteristics, performance metrics, comparative

Figure 1: From top to bottom: (**a**) original image; (**b**) run segments; and (**c**) connected components. analysThe colors do not need additional explanation. They just aid in distinguishing the connected components and RLE segments is against state-of-the-art algorithms, and potential limitations with avenues for improvement. The focus is on execution speed and memory efficiency, as these factors play a critical role in the applicability of CCL in real-world scenarios. ### Experimental Setup and Datasets

To assess the performance of the proposed run-length-based approach, we implemented the method in C++ and compared it against well-established CCL techniques using the YACCLAB [21; 22; 23] benchmark. Specifically, we evaluated our approach against Scan Array Union-Find (SAUF) Algorithm [8], Block-Based Decision Tree (BBDT) [24], Pixel Prediction (PRED) [25], Directed Rooted Acyclic Graphs (DRAG) based scanning [26], and Spaghetti [9]. Additionally, we also test a variety of algorithms that work specifically on RLE, such as Stripe-Based Labeling Algorithm (SBLA) [27], Run-Based Two-Scan (RBTS) [28], and more modern ones that use bit-level processing, such as Bit-Run Two Scan (BRTS) and Bit-Merge-Run Scan (BMRS) proposed by [PERSON] et al. [29]. All algorithms tested, except for ours, were employed to use a Union Find with Path Compression structure (UFPC) when solving labels, as that tended to perform the best in our tests. We test all algorithms on some of the datasets provided by YACCLAB, which contain a variety of black-and-white binary images, as well as a synthetic one with varying degrees of density between black and white. One thing to note is that this dataset is a subset of the classical big dataset found in YACCLAB, but only includes the large images for a better overall assessment. The details for these datasets are given in Table 2.

The datasets were selected to ensure a wide range of connectivity patterns, including dense and sparse distributions of foreground pixels, to thoroughly evaluate the adaptability of each method.