Main Content

Refine Segmentation Using Morphology in Image Segmenter

This example shows how to use the capabilities of the Image Segmenter app to polish the appearance of the mask image you created with the app. The Image Segmenter app includes several morphological operations that you can use to fix small imperfections in the mask image.

This example creates a mask image using hand-drawn ROIs and active contours (see Segment Image Using Active Contours in Image Segmenter).

Load an Image in the Image Segmenter

Open the Image Segmenter app and load an image to be segmented. The Image Segmenter can open any file that can be read by imread.

For this example, first read an image into the workspace. This example uses an MRI image of a knee. The goal is to create a mask image that segments the bone from the soft tissue in the image.

I = dicomread('knee1');
knee = mat2gray(I);

From the MATLAB® toolstrip, open the Image Segmenter app. On the Apps tab, in the Image Processing and Computer Vision section, click Image Segmenter .

On the app toolstrip, click Load, and then select Load image from Workspace. In the Import from Workspace dialog box, select the image you read into the workspace. The Image Segmenter app displays the image you selected.


You can also open the image in the Image Segmenter app using the imageSegmenter command, as follows:


After you load an image, you can optionally load an existing binary mask. For example, you might have previously created a mask by drawing ROIs. To load an existing mask, click Load Mask. The segmentation mask image must be a logical image of the same size as the image you are segmenting.

Create the Mask Image

Create a rough segmentation of the image using ROI drawing tools. Use active contours to finish the segmentation. For more details on this process, see Segment Image Using Active Contours in Image Segmenter.

After finishing the segmentation, click Show Binary on the Segmentation tab to view the mask image. Upon close examination, you can see several small holes in the mask image.


The Image Segmenter includes morphological tools to refine the binary mask. Expand the Refine Mask section of the app toolstrip and click Fill Holes.


This removes the holes in the binary mask.


To save the binary mask, click Export and select Export Images.

See Also

Related Topics