Image Segmentation Using Point Clouds in the Color Thresholder App
This example shows how to segment an image using the point cloud control in the Color Thresholder app. The example segments the human face from the background.
Load Image into the Color Thresholder App
Read an image into the workspace. For this example, read the sample image
mandi.tif into the workspace. The image is a Bayer pattern-encoded image. To work with the image in the Color Thresholder, you must convert the image into an RGB image, using the
demosaic function. After converting the image, display it with the
X = imread('mandi.tif'); rgb = demosaic(X,'bggr'); imshow(rgb)
Open the Image in the Color Thresholder
From the MATLAB® Toolstrip, open the Apps tab and under Image Processing and Computer Vision, click the Color Thresholder icon . The Color Thresholder app opens.
To bring an image into the Color Thresholder app, click Load Image. Because the image is already in the workspace, choose the Load Image from Workspace option. In the Import from Workspace dialog box, select the variable you created and click OK. You can also load an image by specifying its file name.
You can also open the app using the
colorThresholder command, specifying the name of the image you want to open:
colorThresholder(rgb). For information about acquiring an image from a camera, see Acquire Live Images in the Color Thresholder App.
Choose a Color Space
When it opens, the Color Thresholder app displays the Choose a color space tab. This tab displays the image, and point cloud representations of the image, in several popular color spaces: RGB, HSV, YCbCr, and L*a*b*.
Explore the point cloud representations of the image in each color space. Rotate the 3-D depiction in each color space to see how well the colors are differentiated. You select the color to segment from this 3-D display, so it is important to choose a representation that allows you to select the colors of the area you want to segment. For this example, choose the L*a*b* color space.
Segment the Image Using the Color Cloud
When you choose a color space, the app opens a new tab, displaying the image along with a set of controls for each color component of the color space you chose. For the L*a*b* color space, the Color Thresholder displays three histograms representing the three components in the color space. The tab also includes a 3-D point cloud representation of the colors of the image in the color space. Other color spaces use different types of controls.
To explore the image, move the cursor over the image and use the pan and zoom controls.
To segment the image, rotate the 3-D color cloud, using the mouse, to find a view of the color cloud that isolates the colors that you want to segment. To select the colors in the image, click the drawing tool in the upper-left corner of the point cloud. Then, using the mouse, draw a polygon around the colors you want to segment. When you close the polygon, the Color Thresholder app performs the segmentation based on the colors you selected. You can use the histograms to refine your segmentation.
For information about creating a mask and saving it, see Segment Image and Create Mask Using Color Thresholder App.