Problems with kmeans clustering

4 views (last 30 days)
sam  CP
sam CP on 31 Mar 2017
Commented: sam CP on 3 Apr 2017
OI have used the following code to segment the attached image. But each iteration on the same image shows different result. How can i solve this by using rng('default'); ?
  2 Comments
sam  CP
sam CP on 31 Mar 2017
Edited: sam CP on 31 Mar 2017
%k-means clustering algorithm
imData = reshape(Y,[],1);
imData = double(imData);
[IDX nn] = kmeans(imData,'default');
imIDX = reshape(IDX,size(Y));
figure, imshow(imIDX,[]),title('Image after applying k-means Clustering Algorithm');
Where can i apply the rng('default'); ?

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 31 Mar 2017
Edited: the cyclist on 31 Mar 2017
Looking at your code, you should be able to put the line
rng('default')
literally anywhere before the call to kmeans, because you do not call any other random number functions. But the safest bet might be to call it in the line just before the call to kmeans, in case you do something differently later.
But, also, I don't think you put 'default' in the actual kmeans call. So it should be like this ...
%k-means clustering algorithm
imData = reshape(Y,[],1);
imData = double(imData);
rng('default')
[IDX nn] = kmeans(imData);
imIDX = reshape(IDX,size(Y));
figure, imshow(imIDX,[]),title('Image after applying k-means Clustering Algorithm');
  10 Comments
sam  CP
sam CP on 3 Apr 2017
I have already found that the kmeans clustering method can't be detect the tumor when it is very small.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by