User's Guide
Image Segmentation
7.6 Example: Color Image Segmentation
In this example we use clustering to segment an example image according to color features. Subsequently we show examples of color-selective masking operations. This is accomplished by clustering the pixel values in the 3D RGB color space. The determination of the number of clusters comes from a visual examination of the example image. Iterative refinement of the clustering outcome is possible based on a global classification measure. Alternatively, the classification result may be refined in a postprocessing step, by removing outliers from each of the clusters and appropriately labeling them as belonging to none of the selected color classes.
In[1]:=
This reads the
beans
image and extracts a subregion for further processing.
In[2]:=
Here we cluster the color pixel values into three groupings according to their RGB values. The clusters define background, green bean, and red bean pixels. The initial seed values are estimates of typical color values in these three regions.
In[3]:=
Here we verify the resulting clustering by listing the cluster centers.
In[4]:=
Out[4]=
This shows the number of pixels in each of the color clusters.
In[5]:=
Out[5]=
This shows a scatter diagram of the cluster assignment of all the image pixels.
In[6]:=
Given these classification results, we can now proceed with selective image operations. Here we find the positions of all the red pixels in the example image.
In[7]:=
Here we flood the region occupied by red beans with a uniform red color.
In[8]:=
This shows the result.
In[9]:=
Here we mask all the nonred pixels, which includes the background and green bean pixels, with a uniform gray value. First we find the positions of all the pixels that belong to this category.
In[10]:=
This replaces all affected pixels with a uniform gray value.
In[11]:=
This shows the result.
In[12]:=
© 2008 Wolfram Research, Inc.
•
Terms of Use
•
Privacy Policy
Sign up for our newsletter: