Thursday, August 6, 2009

あのぉさ。。 大丈夫か? (Activity # 12)



Again, we were fortunate enough to have an activity which has something to do with taking pictures using a camera (and not generating our own images using scilab and/or paint.) The activity was entitled Color Image Segmentation, yet another concept in image processing.

In an image segmentation process, a Region of Interest (ROI) is picked out from the rest of the image in order to do further processing. It can be done by grayscaling, however that is not always the case. Sometimes, we don't want to lose some of the color information, nor do we want to lose the shading variations in 3D images.

The best way to do it is to convert the RGB values for each pixel into its normalized chromaticity coordinates. Once can easily do this by letting the sum

R + G + B = I

and dividing each channel by I. After this procedure, we can then use either the Parametric Probability Distribution Estimation by assuming a Gaussian Distribution independently along r and g (i.e. the probability that a pixel r belongs to the ROI is seen in the equation below, repeat for g),

or the Non-Parametric Probability Distribution by using the histogram itself to tag the membership of the pixels.

I used three different patches from my original picture (above).

I will leave it to the reader to guess where these patches were taken from my image.

I don't really like putting code snippets in my blog site, but I guess I'll have to put this one in since it's not mine:

I = double(I); //I is the image of the region of interest
R = I(:,:,1); G = I(:,:,2); B = I(:,:,3);
Int= R + G + B;
Int(find(Int==0))=100000;
r = R./ Int; g = G./Int;

BINS = 32;
rint = round( r*(BINS-1) + 1);
gint = round (g*(BINS-1) + 1);
colors = gint(:) + (rint(:)-1)*BINS;
hist = zeros(BINS,BINS);

for row = 1:BINS
for col = 1:(BINS-row+1)
hist(row,col) = length( find(colors==( ((col + (row-1)*BINS)))));
end;
end;

scf(2);
imshow(hist,[]);

The snippet was provided in our activity manual by our professor. The following images are my results for this activity (I didn't bother to post all of them). I also included an image of the chromaticity space for verification.

For the wood-patch [non-parametric (L), parametric (R)]:

For the blue-patch [non-parametric (L), parametric (R)]:

Since this is one of those activities I get to complete in a single meeting.. and I believe I completely understood what I'm doing this time.. I get a 10.

I thank Gilbert for verifying some of the answers for Me and Neil.