MATLAB: K-means Clustering for Color Grouping

color clusteringImage Processing ToolboxkmeansStatistics and Machine Learning Toolbox

I need to cluster different colors using k-means clustering algorithm.
when i use function like this with k=4 for 5 colors image.
[cluster_idx cluster_centre]=kmeans(inputImg,k,'distance','sqEuclidean','Replicates',3);
It will end up with empty cluster at iteration 1 and no partition. If i run multiple times,then at one time it will partition the colors .
then if i change above function like this [cluster_idx cluster_centre]=kmeans(inputImg,k); and then also end up with same result.
Why it showing like this even though image is having 5 colors..? How to debug this problem..? Does any one know please help me out.
Thank You.

Best Answer

Have you seen the Mathworks demo: http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html. I don't have the stats toolbox so I can't help you debug it anymore.
Related Question