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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top