Wednesday, September 12, 2012

Color Image Segmentation

It is difficult to separate colored parts of a color image if it is converted to grayscale then use thresholding for segmentation. Thus, the only approach is to segment the parts by using the color image itself, no conversion needed. However, in the case of objects with differing level of brightness such as 3D objects, it is not advisable to use the RGB space. Instead, one can convert RGB to NCC (normalized chromaticity coordinates). This color space allows separation of brightness and chromaticity. To compute for the values of the red, green and value for NCC, here is the formulae:



This is done per pixel. The sum of r, g and b must be equal to 1. Since b is just equal to 1- r - g, we only use r and g values. The values obtained from using the formula above must between 0 and 1. The chromatic information is stored in r and g while the brightness information is in I.


 In this activity, two approaches were used for color image segmentation - the parametric and non-parametric probability distribution.

I will be working on the image of a flower below. 



Test Image

My goal is to separate the color yellow from the image. The expected result is an image that only shows the parts of the picture that correspond to the color yellow. So, from the image, I will crop a part of the petal. 
The figure below shows the cropped part.


Cropped part of the image (petal)

This is the shade of yellow that I want to separate from the whole image. 

PARAMETRIC PROBABILITY DISTRIBUTION

First, I will get the RGB values of the cropped image and use the equation above to get the correspond r-g values in the NCC coordinates. Then, I will get the mean (μr g) and standard deviation r g) of the the r and g values. Using the calculated mean and standard deviation, I can get the probability that a particular pixel belongs to my region of interest which is the petals of the flower. The probability is computed by substituting the values of the mean and the standard deviation in the equation below. 


However, the r and g values used in the formula above is the corresponding r and g values of the whole image. The code used to implement parametric probability distribution is as follows:


Code for obtaining the r and values of the cropped image and the whole image
Code for getting the probability that the pixel belongs to the ROI

The result of the color segmentation is shown below. 


Original image (left) and Color Segmentation result (right)

NON-PARAMETRIC PROBABILITY DISTRIBUTION

In this approach, you need not get the mean and standard deviation of the cropped image. You only the histogram of the cropped image. The following two figures show the code for getting the 2D histogram of the cropped image. 


Code for getting the 2D histogram of the image

The 2D histogram of the cropped image must have peak at the point that corresponds to our color of interest if compared to the normalized chromaticity diagram. 


Normalized Chormaticity Diagram (left) and 2D histogram of the cropped image (right)
By estimation, the peak shown in the 2D histogram covers to both the light green and the light yellow in the the normalized chromaticity diagram. Thus, we expect that it will also segment parts of the image that correspond to the light green parts of the image. Using the 2D histogram obtained, we use histogram backprojection to segment the image, leaving only those parts described in the peak of the 2D histogram. 


Code for the Histogram Backprojection

The result of the backprojection is shown below. 


Original Image (left) and result of the histogram backprojection (right)
As expected, it also showed the light green parts. However, comparing the accuracy of the segmentation, the non-parametric probability distribution is better than the parametric probability distribution.

For this activity, I give myself a 10/10 for accomplishing the task at hand. 

I would like to thank Ma'am Jing for helping me understand the concept and for Krizia Lampa for helping me debug the code. :)


Reference:

1. Soriano, M., A11 - Color Image Segmentation 2010

No comments:

Post a Comment