howcan count just red pixels in matlab image proccessing ?

17 views (last 30 days)
hello guys please help
i wanna count just red pixels or just white pixels in image processing using matlab programming
please say a usefull solution
thanks

Answers (4)

Erum
Erum on 27 Sep 2014
Edited: DGM on 20 Feb 2023
wpcount: to count white pixels. red is similar
wpcount=0;
for i=1:width
for j=1:height
if image(i,j,:)==255
wpcount=wpcount+1;
end
end
end

Erum
Erum on 27 Sep 2014
Edited: DGM on 20 Feb 2023
for red rpcount
rpcount=0;
for i=1:width
for j=1:height
if image(i,j,1)==255&image(i,j,2)==0&image(i,j,3)==0
rpcount=rpcount+1;
end
end
end
  3 Comments
Image Analyst
Image Analyst on 30 Mar 2017
OK. Do you have a question though?
If so, state the question and post your image so we can check that there is no pure red pixels.

Sign in to comment.


Image Analyst
Image Analyst on 27 Sep 2014
Like Mohammad says, it depends on how you define red. Is it like computer graphics with values of 0 and 255? Or is it from a real camera where there are a bunch of reds, like [255,0,0], [253,20,18], and so on. What about pink? Does that count? What about [2,0,0]? That's really kind of black, but it does have a red component and zero for the green and blue components. Your best bet is to examine the color gamut and determine the best approach. I've given the main approaches as demos in my File Exchange. Any of the color segmentation demos in http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 can be adapted to find red, or any other color. The best method to use depends on the shape of your 3D gamut so that's why I need to see your image and to know why you need to measure red and white. For example if you're doing color matching you may need to use the Delta E method. If you want to do tracking you might use the RGB or HSV method.

mohammad javad houshiano
mohammad javad houshiano on 28 Sep 2014
thanks every body for answering question .
please tell me about counting red and similar red pixels like pink color in image processing thank
  1 Comment
Image Analyst
Image Analyst on 28 Sep 2014
Look at my CIE LAB avatar. That's a cross section through LAB or HSV color space. Basically light to dark is along the vertical axis, the hue (colors of the rainbow) go around the circumference, and saturation or chroma goes radially so that pure, vivid colors are far away from the L or V axis and neutral is at the axis. So gray is on the axis and red is way out there and pink is partway out the radius. If you convert from rgb to hsv with rgb2hsv() then you can threshold the S channel somewhere to divide grays from pinks and reds. Of course you also have to threshold the h channel so that you get only pink/red hues and not blue/sky blue or green/mint green hues. See the LAB and HSV display demo I attached below. It produces several images, one of which is below. Also see my color segmentation demos in my File Exchange. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!