Counting black pixels in a binary image

How can I write a code to count the black pixels and the white pixels in a binary image?

 Risposta accettata

Let's say you have a binary image B. You can get the number of black pixels by:
numBlack=nnz(~B);
and the number of white pixels by:
numWhite=nnz(B);

2 Commenti

Fatema, did this help/work?
Yes it did, thank you.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Images in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by