Segmenting our input image
Now, we are going to introduce two techniques to segment our threshold image:
- Connected components
- Find contours
With these two techniques, we are allowed to extract each region of interest (ROI) of our image where our targets objects appear. In our case, these are the nut, screw, and ring.
The connected components algorithm
The connected component algorithm is a very common algorithm that's used to segment and identify parts in binary images. The connected component is an iterative algorithm with the purpose of labeling an image using eight or four connectivity pixels. Two pixels are connected if they have the same value and are neighbors. In an image, each pixel has eight neighbor pixels:
Four-connectivity means that only the 2, 4, 5, and 7 neighbors can be connected to the center if they have the same value as the center pixel. With eight-connectivity, the 1, 2, 3, 4, 5, 6, 7, and 8 neighbors can be connected if they have the same value as the center pixel. We can...