Color Image Segmentation

download notebookDownload this example as a Mathematica notebook.


Digital Image Processing allows you to manipulate color images as conveniently and easily as monochrome images. Color images may be represented in three different color formats and two different color interleaving methods, allowing you to select the most appropriate format for any color processing application.

[Graphics:Images/index_gr_1.gif]

We use amplitude thresholding and masking to segment an example image according to color features. In particular, we are interested in extracting the yellow beans from the "bean" image.

This reads a color image.

[Graphics:Images/index_gr_2.gif]

Here are the histograms of the individual color channels.

[Graphics:Images/index_gr_3.gif]

[Graphics:Images/index_gr_4.gif]

This applies thresholding to the individual color channels. The threshold values were chosen based on a visual inspection of the histograms.

[Graphics:Images/index_gr_5.gif]
[Graphics:Images/index_gr_6.gif]

[Graphics:Images/index_gr_7.gif]

We now find all the image regions that do not have yellow-colored pixels. We use the ImageProcessing function Where.

[Graphics:Images/index_gr_8.gif]

We now use RegionProcessing to set all non-yellow pixels in the original "bean" image to the background color. This is basically a masking operation, but it may also be implemented as a matrix multiplication operation.

[Graphics:Images/index_gr_9.gif]

We "clean" the resulting color image with a compact morphological filter to reduce small, isolated color patches.

[Graphics:Images/index_gr_10.gif]

Here we display the original and segmented images.

[Graphics:Images/index_gr_11.gif]

[Graphics:Images/index_gr_12.gif]