Total area of a region of binary image

12 views (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 24 Jun 2014
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 Comments
Image Analyst
Image Analyst on 25 Jun 2014
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).

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!