Main Content

Segment Image Using Auto Cluster in Image Segmenter

This example shows how to use theAuto Clusteroption in theImage Segmenterapp to segment an image. TheAuto Clusteroption is an automatic segmentation technique that you can use to segment an image into foreground and background elements. TheAuto Clusteroption does not require initialization.

Load Image into the Image Segmenter App

Read an image into the workspace.

coins = imread('coins.png');

From the MATLAB® Toolstrip, open theImage Segmenterapp. On theAppstab, in theImage Processing and Computer Vision节中,clickImage Segmenter.

On the app toolstrip, clickLoad Image, and then selectLoad Image from Workspace. In the Import from Workspace dialog box, select the image you read into the workspace.Image Segmenterdisplays the image you selected.

You can also open the app using theimageSegmentercommand, specifying the image:

imageSegmenter(coins);

Use Auto Cluster to Segment Image

On theImage Segmentertoolstrip, expand the Create Mask section and chooseAuto Cluster.

Image Segmenterautomatically segments the image, displaying the result. TheAuto Clusteroption has correctly segmented all the circles. However, some of the circles have holes.

Clean up the holes in the segmented image using theFill Holesoption in the Refine Mask toolstrip group.

Save the Mask Image to the Workspace

When you are satisfied with the segmentation, clickShow Binaryto view the mask image. To save the binary mask, use theExportoption. You can also obtain the code used for the segmentation.

See Also

|

Related Topics