This example shows how to calculate the properties of regions in binary images using the Image Region Analyzer app. This example finds the 10 largest regions in the image as measured by their area.
Read a binary image into the MATLAB workspace.
BW = imread('text.png');
Open the Image Region Analyzer app from the MATLAB® Toolstrip. On the Apps tab, in the Image Processing and Computer Vision group, click .
In the Image Region Analyzer app, click Load Image, and
then select Load Image from Workspace, since you have
already read the image into the workspace. You can also open the app from the
command line using the
In the Import From Workspace dialog box, select the image you read into the workspace, and click OK.
The Image Region Analyzer app displays the image you selected next to a table
where every row is a region identified in the image and every column is a
property of that region, such as the area of the region, perimeter, and
orientation. (The Image Region Analyzer app uses
regionprops to identify regions
in the image and calculate properties of these regions.)
The app calculates more properties than are displayed initially. To view more properties in the table, click Choose Properties and select the properties you want to view. Properties displayed are marked with a check. The app updates the table automatically, adding a new column to the table.
To explore the image, sort the information in the table. For example, if you sort on the Area property, the table lists the regions in order by size. Click the Sort Table button in the Properties group and select the property you want to sort on.
To view the region in the image with the largest area, click the item in the table. The app highlights the corresponding region in the image.
To save this data, click Export to see options.
If you want to save the table of region property values in a workspace variable, select Export Properties. To save the data in both a structure and a table, click OK.
View the results returned in an array of MATLAB structures, named
propsStruct. The following code displays the first
structure in the array.
ans = Area: 106 MajorAxisLength: 16.5975 MinorAxisLength: 12.8996 Eccentricity: 0.6292 Orientation: -18.7734 EulerNumber: 0 EquivDiameter: 11.6174 Perimeter: 64.7960
View the results returned in a MATLAB table, named
propsTable. The following code displays the first four
elements of the first table row.
ans = Area MajorAxisLength MinorAxisLength Eccentricity ____ _______________ _______________ ____________ 106 16.598 12.9 0.62925