How can I count the number of white pixels in a binary image with MATLAB?
views:
180answers:
1
+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
2010-05-20 15:55:16
Thanks, but how to dispaly this variable on the screen using subplot ?
dotNET
2010-05-20 16:00:01
@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
2010-05-20 16:04:01
Thank you so much gnovice. It's work perfectly
dotNET
2010-05-20 16:13:54