简体   繁体   English

图像聚类,k 表示

[英]image clustering, k means

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.看,如果您使用平方欧几里得距离运行 k 均值(正如您所做的那样),集群将偏向球形。 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM