clustering rgb image only green channel

1 次查看(过去 30 天)
Tomas
Tomas 2014-4-20
评论: Tomas 2014-4-20
Hello, i have image
i want to clustering only green channel from rgb image.
my code is :
I = imread('obraz1.png'); %%input image
r = I(:,:,1);
g = I(:,:,2);
b = I(:,:,3);
I = g(:);%%green channel
I = ( I - min(I(:)) ) ./ ( max(I(:)) - min(I(:)) );
I = ~I;
[m n]=size(I)
P = [];
for i=1:m
for j=1:n
if I(i,j)>0
P = [P ; i j];
end
end
end
size(P)
MON=P;
[IDX,C]=kmeans(MON,3,'emptyaction','singleton')
How do I display my output image?
Thanks for you help

回答(1 个)

Image Analyst
Image Analyst 2014-4-20
Tomas, since this normalizes (the badly-named) I into the range 0-1, and then you set I equal to the "inverse" what do you think that will do to the values of I. Check this out:
>> ~0.8
ans =
0
So basically I is all zero.
  3 个评论
Image Analyst
Image Analyst 2014-4-20
No, not really. For one thing, the whole loop can be replaced by
[rows, columns] = find(g < 255);
but even that won't do it because other colored spots might have green values less than 255. You have to find out the specific RGB value of the green spots you want to find so that you don't get other colors. Try calling impixelinfo() so you can mouse around on the image and see what colors the spots have. Or use imtool().
Tomas
Tomas 2014-4-20
I was lost, you can not tell me how I found out somehow automatically ?

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by