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'); ?
Best Answer
Looking at your code, you should be able to put the line
rng('default')
literallyanywhere before the call tokmeans, because you do not call any other random number functions. But the safest bet might be to call it in the linejust before the call tokmeans, in case you do something differently later.
But, also, I don't think you put 'default' in the actualkmeans 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');
Best Answer