필터 지우기
필터 지우기

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 CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by