RGB Image Segmentation using Clustering I want to apply some segmentation on a dataset for preprocessing purposes. I have tried the "otsu thresholding" approach in order to segment the image. It's a good method, however, I think a clustering algorithm such as K-Means can be even more succesful for the basic segmentation. Here is some problem with Otsu Thresholding:



As you can see, in some samples, Otsu thresholding may fail like in the picture 1. I think that, using a pixel-wise positioning approach as well as color thresholding may increase the success even further.

However, I couldn't manage to work with scikit-learn's KMeans function to work with an RGB image, since it is a 3 channel 2-d matrix(basically 3d matrix).

How can I combine both pixel-wise distance approach as well as color clustering with K-Means clustering or alike method?
You will want to implement this yourself.

Encoding the data as 5 dimensional vectors per pixel crates a substantial memory overhead. But if you can try that first, to see if the results are as good as you believe then to be...
Pay attention to scaling!