MATLAB Language Image processing Measuring Properties of Connected Regions


Starting with a binary image, bwImg, which contains a number of connected objects.

>> bwImg = imread('blobs.png');
>> figure, imshow(bwImg), title('Binary Image')

enter image description here

To measure properties (e.g., area, centroid, etc) of every object in the image, use regionprops:

>> stats = regionprops(bwImg, 'Area', 'Centroid');

stats is a struct array which contains a struct for every object in the image. Accessing a measured property of an object is simple. For example, to display the area of the first object, simply,

>> stats(1).Area

ans =


Visualize the object centroids by overlaying them on the original image.

>> figure, imshow(bwImg), title('Binary Image With Centroids Overlaid')
>> hold on
>> for i = 1:size(stats)
scatter(stats(i).Centroid(1), stats(i).Centroid(2), 'filled');

enter image description here