How can I extract color feature of an image without extracting white color?

2 ビュー (過去 30 日間)
test test
test test 2018 年 9 月 21 日
コメント済み: Image Analyst 2018 年 9 月 21 日
I = imread('coriander.png');
imshow(I);
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
count = 0;
if R == 255 && G == 255 && B == 255
count = count;
else
count = count +1;
end
disp(count);
I don't want to extract white color and just want to count the number of pixel where is not white color.

採用された回答

Walter Roberson
Walter Roberson 2018 年 9 月 21 日
count = nnz( R ~= 255 | G ~= 255 | B ~= 255 );
Or more simply,
count = nnz( ~all(I == 255, 3) );
  2 件のコメント
test test
test test 2018 年 9 月 21 日
編集済み: Image Analyst 2018 年 9 月 21 日
Thanks. By the way, how can I separate the values of RGB without calculating the white pixel values?
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
just like to get the values as above, but without white pixel values.
Image Analyst
Image Analyst 2018 年 9 月 21 日
If you want a 2-D image, you can't because the white pixels must be in there because 2-D images must remain rectangular. If you want a 1-D vector, you can delete them
mask = R==255 & G==255 & B=255;
RwithoutWhite = R(~mask);
GwithoutWhite = G(~mask);
BwithoutWhite = B(~mask);
Again, those are vectors (lists of pixel values), NOT images. However you can reassign the white pixels to some other value if you want
R(mask) = 137; % Whatever value you want.
THIS will still be a 2-D image.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Filtering and Enhancement についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by