Reputation: 496
I wish to find the number of black pixels in a color image using MATLAB, how can I do it?
Thanks.
Upvotes: 3
Views: 1049
Reputation: 221514
Use nnz
like this -
nnz(all(im==0,3))
where im
is your image data.
Alternatives - sum(reshape(all(im==0,3),[],1))
and sum(sum(all(im==0,3)))
.
The assumption here is that black pixels are triplets (0,0,0)
.
Instead if you define black pixels as pixels that have values in the interval [0 th]
for the same pixel location across all channels, use this -
nnz(all(im<=th,3))
Upvotes: 7