How can I count the pixels in a black and white image?

1 view (last 30 days)
Mara Pereira
Mara Pereira on 8 Jul 2020
Answered: Image Analyst on 8 Jul 2020
How can I count the pixels in a black and white image?

Answers (1)

Image Analyst
Image Analyst on 8 Jul 2020
Try this:
numberOfPixels = numel(binaryImage)
numberOfWhitePixels = nnz(binaryImage)
numberOfBlackPixels = numberOfPixels - numberOfWhitePixels

Community Treasure Hunt

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

Start Hunting!