i have input image my input image
my code is
img = imread('obraz.bmp');
img=rgb2gray(img)
imshow(img)
%% normalization
img = ( img - min(img(:)) ) ./ ( max(img(:)) - min(img(:)) );
img = ~img;
[m n]=size(img)
P = [];
for i=1:m
for j=1:n
if img(i,j)>=1
P = [P ; i j];
end
end
end
size(P);
MON=P;
[IDX,ctrs] = kmeans(MON,3);
clusteredImage = zeros(size(img));
clusteredImage(sub2ind(size(img) , P(:,1) , P(:,2)))=IDX;
imshow(label2rgb(clusteredImage))
My output image is my output image
My output is not correct, I have to be logically correct output
can anyone help?, I don't understand to clustering image.
I'm not sure why you say that the output is not correct. It seems fine to me.
See, if you run k-means using the squared Euclidean distance (as you did) the clusters will be biased towards spherical shapes. Unfortunately for you, one of the clusters in the image is not spherical. You can see that each spherical cluster has a unique colour, but the cluster that isn't spherical doesn't.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.