MATLAB: Total area of a region of binary image

area of regionboundariesconnected componentsImage Processing Toolboximage segmentation

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

Best Answer

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