필터 지우기
필터 지우기

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