Tuesday, September 21, 2010

Color Image Segmentation

     Color image segmentation is very useful in separating parts of the images when the gray level values of the region of interest (ROI) is almost the same as the background.  Figure 1 shows an image of a red bell pepper that will be used in this activity.  The goal is to separate the red bell pepper from the background.  Can it be done using thresholding of the gray level values?  Let's see. :)
     The histogram of the gray level image was obtained, as shown in figure 3.  Since the bell pepper has darker tones than the rest of the image, its pixel values are expected to be near 0.  Based on the histogram values, the image was converted into a binary image with a threshold of 0.3.  Figure 4 shows the resulting image.  Though some parts of the bell pepper are apparent, it is not entirely separated from the background since some part of its leaves are also apparent.  Is there a better way????
     In fact, there is. :)
     Notice that the image has differing brightness of the same color.  For better representation of the color space, brightness is separated from the hue.  This can be done by normalizing the RGB values per pixel.  The normalized RGB values can be used to know the chromaticity of the ROI and consequently use it to discriminate the ROI from the background.
     In this activity, parametric and non-parametric probability distribution will be used as the criteria for segmenting the image.

Figure 1.  Image used to demonstrate color image segmentation.


Figure 2.  Graylevel version of figure 1.

Figure 3.  Histogram of the pixel values of the image in figure 1.
Figure 4.  Image segmentation using thresholding.


A.  Parametric Segmentation
     In parametric segmentation, the distribution of the  R and G values are assumed to be a gaussian.  The probability distribution function for R is shown in equation 1, and the distribution for G has the same form.  The mean µ and the standard deviation σ of the pixel values are obtained from the cropped sub-image of the ROI. Note that the pixel values of the sub-image were normalized.  Figure 5 shows the cropped sub-image of the ROI.  The probability that a pixel belongs to the ROI is the product of the probability for R and G.  Note that the variable r in the equation refers to the normalized pixel values for red. 
     
Equation 1.  Gaussian probability distribution function. [1]
 
Figure 5. Cropped sub-image of the region of interest .

Figure 6. Parametric segmentation of the red bell pepper.

     Figure 6 shows the segmented image.  It can be seen that the pepper was successfully separated from the background. :)

B.  Non-parametric segmentation.
     Instead of assuming a gaussian distribution for the r and g values, the histogram of the image was used to discriminate the pixel values of the ROI from the background.  The value of a particular pixel location will be replaced by its histogram value.  Figure 7 shows the histogram of the cropped sub-image of the ROI.  To check if the histogram is correct, the peaks must lie on the red part of the normalized chromaticity space (figure 8) since the ROI is color red.  Comparing figures 7 and 8, it can be seen that the peaks in the histogram lies in the red portion of the chromaticity space.  Then, the R and G values of the image were replaced by their corresponding histogram values.  Figure 9 shows the resulting segmented image.

Figure 7. 2D histogram of the cropped sub-image of the region of interest.
Figure 8.  Normalized chromaticity diagram.


Figure 9.  Non-parametric segmentation of the red bell pepper.
     Notice that the parametric segmentation gave a smoother segmented image than the non-parametric segmentation.  This is due to the fact that there is an assumed gaussian distribution for the pixel values in the parametric.  The gaussian is a smooth continuous function, that is why the segmented image also have a refined image.  Non-parametric segmentation on the other hand, uses histogram values that can have an abrupt change in the histogram values per pixel value.  So, this will result in the segmented image having apparent blots.

     I would like to thank Dennis Ivan Diaz and Ma'am Jing for the help in this activity.  Since I produced all the required outputs and understood the concepts, I would give myself a grade of 10/10.

References:
[1] Color Image Segmentation Activity Manual
[2] Red pepper image downloaded from this site. 
          

No comments:

Post a Comment