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

11 ビュー (過去 30 日間)
Drashti
Drashti 2014 年 5 月 1 日
コメント済み: Image Analyst 2018 年 10 月 26 日
input image is grayscale image. how can i get black & white no. of pixels

回答 (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?
Image Analyst
Image Analyst 2018 年 10 月 26 日
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(:));

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by