MATLAB: How to calculate number of zeroes in an image array

digital image processingimage matchingimage processing

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

Best Answer

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))