Filter löschen
Filter löschen

k means

1 Ansicht (letzte 30 Tage)
Mahalakshmi
Mahalakshmi am 27 Jun. 2011
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Jun. 2011
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 Kommentare
Walter Roberson
Walter Roberson am 27 Jun. 2011
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 am 27 Jun. 2011
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'.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by