Filter Images on Region Properties Using Image Region Analyzer App

This example shows how to create a new binary image by filtering an existing binary image based on the properties of regions in the image.

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.

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, perimeter, and orientation. The Image Region Analyzer app uses regionprops to identify regions in the image and calculate properties of these regions.

To filter on the value of a region property, click Filter and select the property on which you want to filter.

Next, specify the filter criteria. For example, to create an image that removes all but the largest regions, choose the greater than or equal to symbol (>=) and then specify the minimum value. Sometimes it’s useful to sort the values in the table by the property you are interested in to determine what the minimum value should be. The app changes the elements of this dialog box, depending on which criteria you pick. The app uses the bwpropfilt and bwareafilt function to filter binary images.

To filter on another property, click Add. The app displays another row in which you can select a property and specify filter criteria. The result is the intersection (logical AND) of the two filtering operations.

If you are creating a mask image, you can optionally perform some cleanup operations on the mask, such as clearing all foreground pixels that touch the border and filling holes in objects.

When you are done filtering the image, you can save it. Click Export and select Export Image.

In the Export to Workspace dialog box, accept the default name for the mask image, or specify another name, and click OK.