Calculating black pixels in colour image
2 views (last 30 days)
Show older comments
Hui Shi Lim
on 12 Apr 2015
Commented: Image Analyst
on 12 Apr 2015
Hi, does anyone know how do I calculate black pixels in a colour image using Matlab? Thank you.
0 Comments
Accepted Answer
Image Analyst
on 12 Apr 2015
Find pixels that are black in all three color channels. One way to do it is:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1) == 0;
greenChannel = rgbImage(:, :, 2) == 0;
blueChannel = rgbImage(:, :, 3) == 0;
blackPixelImage = redChannel & greenChannel & blueChannel;
numBlackPixels = sum(blackPixelImage(:));
message = sprintf('The number of pure black pixels = %d', numBlackPixels);
uiwait(helpdlg(message));
4 Comments
Image Analyst
on 12 Apr 2015
You're welcome. If we're done here, can you mark the Answer as Accepted. Thanks in advance.
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!