kmeans clustering on n*3 matrix
    4 views (last 30 days)
  
       Show older comments
    
I am evaluating an n*3 matrix using kmeans. The idx result which I get is only n*1. What does this mean? Is the algorithm only evaluating each column as separate observations?
0 Comments
Answers (2)
  dpb
      
      
 on 9 Jul 2018
        >> help kmeans
kmeans K-means clustering.
  IDX = kmeans(X, K) partitions the points in the N-by-P data matrix X
  into K clusters.  This partition minimizes the sum, over all clusters, of
  the within-cluster sums of point-to-cluster-centroid distances.  Rows of X
  correspond to points, columns correspond to variables. ...
  kmeans returns an N-by-1 vector IDX containing the cluster indices of each point.
  ...
Each row is a joint observation; how do you want the input array to be interpreted?
3 Comments
  dpb
      
      
 on 9 Jul 2018
				
      Edited: dpb
      
      
 on 10 Jul 2018
  
			Each row is then a RGB triplet, I gather? KMEANS will simply try to separate those based on a "distance" measure into non-overlapping groups based on solely that distance measure from the group centroid given an a priori number of groups.
It uses the three values to compute a single measure; there's no sense of 3D left for it to operate on.
I'm not enough of an image-processing type to have a more suitable algorithm otomh but I don't think this is what you're looking for...it should isolate areas of roughly the same hue/intensity, however, but it will do those globally throughout the image.
  Image Analyst
      
      
 on 10 Jul 2018
        The output is the classified result. It will be a number 1, 2, or 3 depending on whether it thinks that row belongs to class 1, class 2, or class 3.
k-means is a lousy way to classify RGB images. Nonetheless, I attach a demo so you can see for yourself. Discriminant analysis is better and I also attach a demo for that.
0 Comments
See Also
Categories
				Find more on Cluster Analysis and Anomaly Detection in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

