I wish to find the number of black pixels in a color image using MATLAB, how can I do it?
Thanks.
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))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.