views:

180

answers:

1

How can I count the number of white pixels in a binary image with MATLAB?

+2  A: 

The function NNZ should do the trick, since "white" is represented as 1 and "black" as 0 in a binary image img:

nWhite = nnz(img);
gnovice
Thanks, but how to dispaly this variable on the screen using subplot ?
dotNET
@AZIRAR: I'm not sure what you're asking for, but if you want to display the number of white pixels along with the image, you could do the following: `imshow(img); title(['Number of white pixels: ' int2str(nnz(img))]);`
gnovice
Thank you so much gnovice. It's work perfectly
dotNET