主要内容

Filter Images on Properties Using Image Region Analyzer App

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

Read a binary image into the workspace.

bw = imread("text.png");

Open theImage Region Analyzerapp from the toolstrip. On theApps标签,在Image Processing and Computer Visionsection, click Image Region Analyzer.

在应用程序工具条上,单击Load Image,然后选择从工作区加载图像to load the image from the workspace into the app. In the Import from Workspace dialog box, select the image you read into the workspace, and then click好的.

You can also open the app from the command line using theimageRegionAnalyzer功能, specifying the image you want to analyze:

imageRegionAnalyzer(BW)

Image Region Analyzerdisplays the binary image and a table with region properties. In the table, each row is a region identified in the image and each column is a property of that region, such as the area, perimeter, and orientation.

To filter on the value of a region property, on the app toolstrip, click筛选。选择要过滤并指定过滤条件的属性。例如,要创建一个删除除最大区域以外所有区域的图像,请选择Area属性,选择大于或等于symbol (>=), and then specify the minimum value.

要过滤另一个属性,请单击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.

As you apply filters on properties, the app updates the binary image and the table automatically.

If you are creating a mask image, then you can optionally perform cleanup operations on the mask, such as clearing all foreground pixels that touch the border and filling holes in objects. Filling holes can change the area of regions and therefore the regions that appear in the filtered image. For this example, the area of letters such as "b", "d", and "g" is larger after filling holes. A new region (a letter "o") with an area of 105 pixels now appears in the filtered image because the filled area of that region is above the threshold.

When you are done filtering the image, you can save it. ClickExport>Export Image. In the Export to Workspace dialog box, accept the default name for the mask image, or specify another name. Then, click好的.

You can save the list of properties as a structure or table. ClickExport>Export Properties.

You can also export a function that filters binary images using the same filters and cleanup operations that you specify. The function returns the filtered binary image and the property measurements in a table. ClickExport>导出功能, then save the function as an M file.

功能[BW_OUT,属性] = FilterRigions(BW_IN)%过滤器区使用来自ImagereGionanalyzer应用程序的自动生成代码过滤BW图像。% Auto-generated by imageRegionAnalyzer app on 31-Oct-2021%------------------------------------------------------------------------------------BW_out = BW_in;% Fill holes in regions.BW_out = imfill(BW_out,'holes');% Filter image based on image properties.BW_out = bwpropfilt(BW_out,'Area',[85, 124]);% Get properties.properties = regionprops(BW_out, {'Area','convexarea','EulerNumber','FilledArea',“主要Xislength”,'MinorAxisLength','方向','Perimeter'});

See Also

|||

相关话题