Total area of a region of binary image

7 次查看(过去 30 天)
Hi every ones I have a question of area of region of binary image.
That mean I have a list of boundary of a region in a image. Use bwboundaries or use bwlabel. Now I want to find there is total how many pixel - areas ( include black and white) in this area ?
I can't use regionprops funtion in matlab because it return only number of black pixel.
Please help me, thanks so much

采纳的回答

Image Analyst
Image Analyst 2014-6-24
Huh? Of course you can use regionprops. No need to use bwboundaries() at all, unless you just want to show the outlines of the segmented areas in the overlay above your original gray scale or color image.
If you want the area of all the white pixels in your binary image you can do it two ways, with slightly different results because they use different calculation methods
pixelSum1 = bwarea(binaryImage);
pixelSum2 = sum(binaryImage(:));
If you want the area of each blob in the image individually, you can do it like this:
labeledImage = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'Area');
allAreas = [measurements.Area]; % List of all the blob areas.
totalAreaOfAllBlobs = sum(allAreas); % Will be the same as pixelSum2
  3 个评论
Image Analyst
Image Analyst 2014-6-25
Please show/attach an image. The later code I gave shows you how to how to get the white pixels in a region (blob). To also get the black pixels in only that blob, you'd have to call
binaryImage = imfill(binaryImage, 'holes')
before calling regionprops. That will also count the black pixels in the blob. Obviously if you count all the black and white pixels in the entrie image, that's just the number of pixels in the image, numel(grayImage).

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by