Hi, does anyone know how do I calculate black pixels in a colour image using Matlab? Thank you.

 채택된 답변

Image Analyst
Image Analyst 2015년 4월 12일

0 개 추천

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

Hui Shi Lim
Hui Shi Lim 2015년 4월 12일
Thank you. But where is the line to add in my own picture in order to calculate it?
Image Analyst
Image Analyst 2015년 4월 12일
편집: Image Analyst 2015년 4월 12일
I called your image rgbImage. What did you call it? In the line below:
rgbImage = imread(yourFileName);
what is the variable name you used instead of "rgbImage"? Whatever it is, that's what you'd use in my code.
By the way, you can also use the sum() function
blackPixelImage = sum(rgbImage, 3) == 0;
numBlackPixels = sum(blackPixelImage(:));
message = sprintf('The number of pure black pixels = %d', numBlackPixels);
uiwait(helpdlg(message));
Hui Shi Lim
Hui Shi Lim 2015년 4월 12일
Thank you:)
Image Analyst
Image Analyst 2015년 4월 12일
You're welcome. If we're done here, can you mark the Answer as Accepted. Thanks in advance.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Blue에 대해 자세히 알아보기

질문:

2015년 4월 12일

댓글:

2015년 4월 12일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by