Contents

Overview

In five seconds

Detection of connected objects in an image, mainly used in image analysis and OCR.

In five minutes

Connected-component labeling (alternatively connected-component
analysis, blob extraction, region labeling, blob
discovery, or region extraction) is an algorithmic
application of graph theory, where subsets of connected components
are uniquely labeled based on a given heuristic.
Connected-component labeling is not to be confused with segmentation.

Pay special attention to the recursive function GetRoot(), that's how we reach the parent of any label.

Remember this part? This is what the function Join(Label root) does. Now let's say we have
three labels, 1, 2, and 3, and we picked 1 to be our current label; all we have to do is loop the other labels, if their roots don't match,
set their root to that of the label we just picked.

Conclusion

Hope I delivered a clear explanation, feel free to comment or ask .
Drawings by zwibbler