Main Content

Segment Image by Drawing Regions Using Image Segmenter

This example shows how to segment an image in the Image Segmenter app by drawing regions of interest. Image Segmenter offers many different ROI shapes including polygons, rectangles, ellipses, and circles. In addition, you can draw freehand shapes or assisted freehand shapes that help you by following the underlying shape of the objects in the image.

Image Segmenter offers many different segmentation methods and using the app can be an iterative process. You might try several different methods until you achieve the results you want.

Load an Image in Image Segmenter

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

For this example, 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);

Open the Image Segmenter app from the MATLAB® toolstrip. 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. Image Segmenter 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 into the app, you can optionally load an existing binary mask. For example, you might have previously created a mask of an RGB image in the Color Thresholder app and you want to refine the segmentation. 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.

Use ROI Tools to Draw Regions for Segmentation

Expand the Add to Mask group and click Draw ROIs. The app opens the ROI tab.


Select the type of ROI you want to draw. For this example, choose Assisted Freehand. As you move the cursor over the image, it changes to the crosshairs shape. Press the mouse button, and begin drawing a freehand shape over the area of the image that you want to segment. With the Assisted Freehand ROI option, which is preselected, you can draw a freehand shape that automatically follows edges in the underlying image to help you draw a more accurate ROI. As you draw, click the mouse to create waypoints. Waypoints can help you make fine adjustments to the shape after you finish drawing. To add additional waypoints after you finish drawing, double-click on the ROI edge.


Continue drawing shapes until all the areas you want to segment are identified. To save the regions your have drawn, click Apply (their color changes to yellow). To return to the Segmentation tab, click Close ROI.


To view the mask image, click Show Binary on the Segmentation tab. To refine the mask image, use the tools in the Refine Mask section of Image Segmenter app toolstrip, such as Clear Borders or Fill Holes. When you are done, click Export to save the mask image to the workspace.


See Also

Related Topics