Matlab: How can I find the number of black pixels in a color image?
1 answer
Use nnz
like this -
nnz(all(im==0,3))
where im
is your image data.
The alternatives are sum(reshape(all(im==0,3),[],1))
and sum(sum(all(im==0,3)))
.
The black pixels are assumed to be triplets (0,0,0)
.
Instead, if you are defining black pixels as pixels that have range values [0 th]
for the same pixel location across all channels, use this -
nnz(all(im<=th,3))
+7
source to share