clustering rgb image only green channel
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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
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().
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!