フィルターのクリア

how to count pixel in binary image ?

17 ビュー (過去 30 日間)
ayrie
ayrie 2014 年 8 月 19 日
コメント済み: Image Analyst 2021 年 2 月 27 日
Hi, i'm trying to counting a binary image on handwritting. how to count a high string using pixel? example for counting high of alphabet A.

採用された回答

Image Analyst
Image Analyst 2014 年 8 月 19 日
To get the number of pixels in the entire image
numberOfPixels = numel(binaryImage);
To get the number of white/1/true pixels only , and NOT the number of black/0/false pixels:
numberOfTruePixels = sum(binaryImage(:));
  2 件のコメント
sofia cirne
sofia cirne 2017 年 6 月 22 日
Hello! im doing the same thing apresented above and i used your code to count the black picels and the total number of pixels, but when i submit a completly black image, the number of black pixels is different from the total. Can you help me please?
Image Analyst
Image Analyst 2017 年 6 月 22 日
Bizarre. Of course my code does not count black pixels but I assume you made the obvious alterations (but maybe not). What do you get for this example:
blackImage = false(240, 320);
numberOfPixels = numel(blackImage)
numberOfBlackPixels = sum(~blackImage(:))
The two numbers should be identical.
To know what you're doing wrong, I'll have to see what you're doing, because, as I've said, you're not doing what I posted because I did not post code to count black pixels.

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

その他の回答 (1 件)

Asad Alam
Asad Alam 2021 年 2 月 25 日
How can we count pixels of an image by satisfy a condition?
  1 件のコメント
Image Analyst
Image Analyst 2021 年 2 月 27 日
You can use length() and pass your condition in as a mask. Like if your condition is the pixel value is less than 100, you'd do
condition = yourImage < 100; % tru or false values - a logical 2-d matrix.
pixelsLessThan100 = yourImage(condition); % These are a list (1-d vector) of gray level values.
% Count the number of pixels.
count = length(pixelsLessThan100);

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by