Color Image Segmentation





Color Segmentation using normalized chromaticity coordinates (NCC)



For this blog, I’ll teach you how to segment a certain portion in an image. I think it’s better to show what will happen in pictures.





Okay, the picture below is an image of different colors of plastic balls. And guess where I got it: http://gayguidetoronto.com/2009/05/24/big-bold-bouncy-balls/ Yeah. Gay Guide. Hahahaha. :)))) I really haven’t notice that it was a gay site until I copied the link where I got the image. Oh well. It is really an epic picture. The picture above shows the pictures of the balls to be segmented.


Well enough of our giggling. Let’s go back to work! So, what we will do is separate (or segment) the balls according to color. We are going to use two ways in order to do this. In both ways, we are required to represent the color space (not the usual Red-Green-Blue) into pure color information. The normalized chromaticity coordinates (NCC) can be used where the brightness and chromaticity of the picture is well-represented [1].


To represent the color space into NCC:

R = Ic(:,:,1); G = Ic(:,:,2); B = Ic(:,:,3);

Int= R + G + B;

Int(find(Int==0))=1;

rc = R./Int; gc = G./Int;


We first separate the Red, Green and Blue component of the image. Then we get the sum of these components. To prevent the world from destroying, we avoid dividing by zero by assigning all values with zero to 1. Finally, we divide the R component with the sum of the RGB components to get the NCC for red, and by dividing G component with the sum of the RGB component to get the NCC for green. Only two components are needed.


Next is we need a Region of Interest (ROI), where we compare the bigger image. For the image of the balls, a ROI can be a small square of a certain color. Don’t worry, I’ll show more examples later. Aaaand, we are ready! I’ll tell you the two ways for segmentation:


1) Parametric Segmentation (PS)


In PS, we shall find the NCC of both the original picture and the ROI first. Let’s call this r_original and g_original for the NCC of the original picture while r_ROI and g_ROI for the NCC of the ROI. The next thing we do it we get the standard deviation and mean of r_ROI. After this step, we get a single value of the standard deviation and the mean. We then substitute it to the Gaussian equation. With r being the r_original (which will be a matrix). After that, we shall do it again for the green NCC. Finally, we multiply the probability distribution of the red and green to get the segmented image.


2) Non-parametric segmentation(NPS)


In NPS, we shall first obtain a 2D histogram of the ROI using the NCC. Then, the histogram using the ROI will be back projected to the original image’s NCC. It really sounds simple but its more complicated than that so I’ll just provide the code later.


RESULTS


I’ll try to extend this work by investigating the use of different ROI colors and sizes. From the figure above, different ROIs were obtained as seen in the figure below. Five colors were used.


Different ROI sizes where also used:


1. Parametric Segmentation


Figure below shows the segmented images. As you can see the colors blue, green and violet were successfully segmented while the colors red and orange had some noise. This is because red and orange are slightly of the same hue.


The effect of the size of the ROI was also studied. It can be seen that a larger ROI produces larger segmented image. This is probably because larger ROI has higher standard deviation allowing more colors to be segmented.


2. Non-parametric segmentation


Figures below show the segmented image using different colors and different ROI sizes. For the colors, it is almost the same as PS but the color violet has more residues. The code actually detects the blue-ish colors as violet. This is understandable because blue and violet is near to each other in the visible spectrum. As for the increasing ROI size, as expected, larger ROI has larger standard deviation and therefore has a larger are segmented.


Comparing the PS and NPS technique, I prefer the PS method. First is that the run time for PS is faster than that of the NPS. NPS utilizes the for loop in back projection and it takes some time while the PS just loads in an instant. Second is that PS produces segmented images with a more defined edge.