How to calculate Black area?
9 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
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 Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!