how to calculate number of zeroes in an image array?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
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
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.
Weitere Antworten (0)
Siehe auch
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!