Sometimes, the color of pixels in an image can help determine where semantically close areas are. For example, road surfaces, in some circumstances, may have almost the same color. By color, we can find all road pixels. But what if we don't know the color of the road? Here, the k-means clustering algorithm comes into play. This algorithm only needs to know how many clusters are in an image, or, in other words, how many clusters we want an image to have. With this information, it can automatically find the best clusters. In this recipe, we will consider how k-means image segmentation can be applied using OpenCV.
Image segmentation using the k-means algorithm
Getting ready
Install the OpenCV 3.x Python API package and the...