
About
This project contains the implementation of Connected Component Labeling using the Two-Pass Algorithm in both C and MIPS Assembly. The algorithm is used to label different connected components in binary images, where each pixel is represented by hex values stored in .txt files.
In the C implementation, the labels are represented as integers, and the goal is to group connected pixels into the same label. In the MIPS Assembly implementation, a picture will be shown with different colors representing different components.
Two Pass Algorithm
- First Pass:
- Traverse through the binary image, pixel by pixel, from the top-left corner to the bottom-right corner.
- If the current pixel is part of a connected component (i.e., has a value of 1), assign a unique label to it. The label represents the connected component to which the pixel belongs.
- Update the label equivalences to keep track of connected components that share the same label.
- Second Pass:
- Traverse through the binary image again, pixel by pixel.
- For each labeled pixel (value > 0), update its label based on the label equivalences determined in the first pass. This step ensures that all connected pixels in the same component have the same label.
IN ASSEMBLY
FIRST PASS
SECOND PASS

Description
In the examples above, the picture at the left represents the result from the first pass of the algorithm, while the picture on the right displays the outcome after the second pass. In the MIPS Assembly implementation, the image is colorized directly within the assembly code after the completion of the two-pass algorithm.
The MIPS Assembly implementation is not merely colorizing the output generated by the C implementation; instead, it independently executes the entire Connected Component Labeling process, including the two-pass algorithm and the subsequent colorization of the connected components.