k means
3 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!