フィルターのクリア

How to calculate Black area?

11 ビュー (過去 30 日間)
Steven
Steven 2013 年 12 月 19 日
コメント済み: Image Analyst 2013 年 12 月 25 日
In one question in which I wanted to calculate the dark (black) area in a binary image, you guys answered to me:
"If all you need is the area of the dark region then you don't need to find the edge at all. You just need to threshold and sum
binaryImage = grayImage < 128; % or whatever.
darkArea = sum(binaryImage);
darkArea2 = bwarea(binaryImage); % Another way using different algorithm. "
Now a problem comes to me. I wonder:
We want the area of black region not white, so when we use sum (or bwarea), we are actually calculating the white area region. right? because white pixels are 1 and black ones are 0 and by summing we are summing the white ones not black ones.
Thus, the area of black region should be this:
image_size = size(binary_image)
whole_area = image_size(1)*image_size(2)
white_area = sum(sum(binary_image)); % or
% white_area = bwarea(binary_image);
black_area = whole_area - white_area;
Am I right?
Sorry for such a trivial question, but I was really confused!
Thanks so much.

採用された回答

Image Analyst
Image Analyst 2013 年 12 月 19 日
No, that's not right. It's as I told you at first.
When you do
binaryImage = grayImage < 128; % Find dark pixels. Dark = true, 1, white.
you're creating a matrix that is "true" wherever the image is dark . If you sum that, it treats the "true" pixels as 1, and thus, counts them - counts the dark pixels. So you're getting the sum of the "true/1/white" pixels in the binary image which means your getting the count of the dark pixels of the gray scale image. Doing it your complicated way would count the bright pixels. By the way, if you wanted the binary image to be false where the gray scale image was dark, you'd flip the less than sign and then sum the inverse, which is much simpler than doing the multi-step process you did.
binaryImage = grayImage > 128; % Find bright pixels instead of dark pixels.
numDarkPixels = sum(~binaryImage(:)); % Notice I had to invert the image with~.
  8 件のコメント
Steven
Steven 2013 年 12 月 19 日
Thanks!
So with this case above, does my old long method (mentioned at the first question) give the black area (semicircle)?
Thanks Setven
Image Analyst
Image Analyst 2013 年 12 月 25 日
Maybe - I'm not sure what your binaryImage refers to. Maybe you can just post your whole m-file and I can fix it.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by