how to get black & white pixels count from grayscale image...???

답변 (1개)

Nitin
Nitin 2014년 5월 1일
black corresponds to zeros in your image and white corresponds to ones if your image is double format.
I_double = im2double(img);
% Find black pixels
b = find(I_double==0);
% Find white pixels
w = find(I_double==1);

댓글 수: 2

EM geo
EM geo 2018년 10월 26일
편집: Image Analyst 2018년 10월 26일
Does it do a count of white and black pixels?
No it does not.
You'd have to do
numBlackPixels = numel(b); % Count the number of linear indexes returned.
numWhitePixels = numel(w);
For a uint8 image, you'd do
pureWhitePixels = grayImage == 255;
numberOfWhitePixels = sum(pureWhitePixels(:));
pureBlackPixels = grayImage == 0;
numberOfBlackPixels = sum(pureBlackPixels(:));

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

질문:

2014년 5월 1일

댓글:

2018년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by