MATLAB: How to extract color feature of an image without extracting white color

color extractionpixel

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.

Best Answer

count = nnz( R ~= 255 | G ~= 255 | B ~= 255 );
Or more simply,
count = nnz( ~all(I == 255, 3) );
Related Question