It's a technique in computer vision to detect connected regions.
Wikipedia: Connect Component Labeling
Implementation Details
- One-pass (one component at a time) algorithm is used.
- Connected regions are painted with different colors.
Notes
- 16 distinct colors are used to represent regions. If there are more than 16 regions, try changing the constant NUM_OF_COLORS to avoid color re-use
- Program looks for components.png in the Images dir.
Source Code:
Instructions to Run
- Install and configure OpenCV.
- Compile and run.
- output.jpg will be generated in the same dir as the executable.
Sample Input

Output
