H (色相) が 0.00~0.02 と 0.98~1.00 のピクセルを「赤」と判定しました。
HSV = rgb2hsv(imread('image.png'));
RED = (HSV(:,:,1) <= 0.02) ...
| (HSV(:,:,1) >= 0.98);
sum(RED,'all') % 赤い部分のピクセル数
numel(HSV(:,:,1)) % 画像のピクセル数
imshow(~RED) % 黒い部分が赤色、白い部分が赤色以外。若干判定ムラが生じている
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!