Extracting connected components from a binary image

Connected components in binary images are areas of non-zero values. Each element of each connected component is surrounded by at least one other element from the same component. And different components don't touch each other, there are zeros around each one.

Connected component analysis can be an important part of image processing. Typically (and in OpenCV, it's a fact), finding connected components in an image is much faster than finding all contours. So, it's possible to quickly exclude all irrelevant parts of the image according to connected component features (such as area, centroid location, and so on), to continue working with, remaining areas.

This recipe shows you how to find connected ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.