how to calculate number of zeroes in an image array?

1 Ansicht (letzte 30 Tage)
Adnan Saify
Adnan Saify am 10 Jan. 2016
Kommentiert: Image Analyst am 10 Jan. 2016
suppose i have an image array for example
1 2 3 1 2 1 1
0 1 2 5 8 7 9
4 7 8 9 2 3 0
0 0 0 1 2 0 0
the above array has 7 zeroes so how to calculate it using a matlab code

Akzeptierte Antwort

Image Analyst
Image Analyst am 10 Jan. 2016
Here are two ways:
m=[...
1 2 3 1 2 1 1
0 1 2 5 8 7 9
4 7 8 9 2 3 0
0 0 0 1 2 0 0]
numZeros = numel(m) - nnz(m)
numZeros = sum(sum(m==0))
  5 Kommentare
Adnan Saify
Adnan Saify am 10 Jan. 2016
i need one more help ,can we determine number of'0' as well as '1' in an array
Image Analyst
Image Analyst am 10 Jan. 2016
I already showed you how to do that - find 0's. For example:
numZeros = sum(sum(m==0))
or in general, to find any integer:
countOfThisNumber = sum(sum(yourArray == yourInteger))
so, to count the 1's, you'd do this:
countOf1s = sum(sum(yourArray == 1))
Of course you can use whatever name for the variables you want. You don't have to use the names I used but I do encourage you to use descriptive names, rather than just single letters, so that your code is maintainable/understandable by others (and you) later, and not just an incomprehensible alphabet soup like we see far too often.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by