k means

1 次查看(过去 30 天)
Mahalakshmi
Mahalakshmi 2011-6-27
I'm trying to perform k means on a 512*512 img of class uint8. Here is my code ab = double(img(:,:)); nrows = 512; ncols = 512; ab = reshape(ab,nrows*ncols,1); [cluster_idx cluster_center] = kmeans(ab,[],'distance','sqEuclidean',... 'emptyaction','Singleton','start',[1,2;2,1]); but this is the error msg I get ??? Subscripted assignment dimension mismatch.
Error in ==> kmeans>batchUpdate at 428 [C(changed,:), m(changed)] = gcentroids(X, idx, changed, distance);
Error in ==> kmeans at 337 converged = batchUpdate(); Please help me figure out where I am going wrong. Thanx in advance.

采纳的回答

Walter Roberson
Walter Roberson 2011-6-27
Note that your setup code is equivalent to
ab = double(img(:));
You are passing in a single column of data to kmeans(), so kmeans is getting 1D data, but you are trying to initialize the centroids as a pair of two-dimensional points.
  3 个评论
Walter Roberson
Walter Roberson 2011-6-27
Yes, you can perform kmeans on grayscale images using the inbuilt kmeans function. You must, however, first define what it is you want to cluster on.
Looking through the documentation for kmeans for the version I have and for the latest (2011a) version, I do not see any possibility of using an empty matrix in place of the number of clusters ? Which version are you using?
Mahalakshmi
Mahalakshmi 2011-6-27
I too use the same version. When I changed the distance measure to cosine or correlation ,this is the error I get..
Error using ==> kmeans at 157
Some points have small relative magnitudes, making them effectively zero.
Either remove those points, or choose a distance other than 'cosine'.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by