Segment Image Using Thresholding in Image Segmenter
This example shows how to segment an image in the Image Segmenter app by using thresholding. The Image Segmenter app supports three different types of thresholding: Global, Manual, and Adaptive.
The Image Segmenter app 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 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, 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:
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 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 Thresholding to Segment Image
Click Threshold in the Create Mask section of the Image Segmenter app toolstrip. The app displays the thresholded image in the Threshold tab. By default, the app uses global thresholding.
You can also choose Manual or Adaptive thresholding. 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 using Manual thresholding.
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, click Create Mask. If you want to try another segmentation method in the Image Segmenter app, click Cancel to return to the main segmentation app window.