Main Content

段图像使用阈值图像Segmenter

This example shows how to segment an image in theImage Segmenterapp by using thresholding. TheImage Segmenterapp supports three different types of thresholding: Global, Manual, and Adaptive.

TheImage Segmenterapp supports 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 Image into the Image Segmenter

Open theImage Segmenterapp and load an image to be segmented. The app can open any file that can be read byimread.

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 theImage Segmenterapp. On theAppstab, in theImage Processing and Computer Visionsection, clickImage Segmenter.

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

You can also open the image in theImage Segmenterapp using theimageSegmentercommand, as follows:

imageSegmenter(knee);

After you load an image, you can optionally load an existing binary mask. For example, you might have previously created a mask of an RGB image in theColor Thresholderapp and you want to refine the segmentation. To load an existing mask, clickLoad Mask. The segmentation mask image must be a logical image of the same size as the image you are segmenting.

Use Thresholding to Segment Image

ClickThresholdin the Create Mask section of theImage Segmenterapp toolstrip. The app displays the thresholded image in the Threshold tab. By default, the app uses global thresholding.

You can also chooseManualorAdaptivethresholding. Each thresholding option supports controls that you can use to fine-tune the thresholding. For example, with Manual thresholding, you can choose the threshold value using the slider. With Adaptive thresholding, you can choose the sensitivity using the slider. Try each option to see which thresholding method performs the best segmentation.

The following figure shows the results of usingManualthresholding.

The knee image does not have well-defined pixel intensity differences between foreground and background and thresholding does not seem like the best choice to segment this image.

To save the segmentation, clickCreate Mask. If you want to try another segmentation method in theImage Segmenterapp, clickCancelto return to the main segmentation app window.

See Also

Related Topics