Wednesday, September 17, 2008

Activity 16 - Color Image Segmentation

In this activity, a sample from the whole image is picked out to get the Region Of Interest (ROI) from the image.
Example of this is the human skin recognition.
There are two basic techniques in segmentation; (1) Probability Distribution Estimation and (2) Histogram Backprojection.

The image and the used in this activity is shown below:
Figure 1. The original image
Figure 2. Sample from the original image

Probability Distribution Estimation

In this technique, a sample from the original image is cropped from the original image. Per pixel, the r value and the g of both the original image and the cropped image are normalized by dividing it to the sum of r, g and b values of that pixel. The probability that the the r value and the g value of the original image belong to the ROI is given by the equation:

Equation 1


The resulting ROI is shown below:Figure 3


Histogram Backprojection

In this technique, the 2D histogram of the portion of the original image was obtained. The obtained histogram was normalized to obtain the probability distribution function(PDF). The r and the g values of the original image per pixel were back-projected (or replaced) by finding the r and the g values from the PDF. The resulting image is shown below:


Figure 4

Comparing the two techniques, for me the Probability Distribution Estimation is a better technique for segmentation because of the expected ROI was obtained. In contrast to the Histogram Back-projection, not all the expected ROI was obtained.


For this activity, I will give ,myself a grade of 8 because of the late submission.
I would like to acknowledge Abraham Latimer Camba for helping me in the Histogram Back-projection part.



Appendix:
Source code


//First: Segmentation via probability
I = imread("F:\AP 186\act16\pic.jpg");
I2 = imread("F:\AP 186\act16\small.jpg");
n1 = size(I);
scf(1);imshow(I);
r1 = I(:,:,1)./(I(:,:,1)+I(:,:,2)+I(:,:,3));
g1 = I(:,:,2)./(I(:,:,1)+I(:,:,2)+I(:,:,3));
b1 = I(:,:,3)./(I(:,:,1)+I(:,:,2)+I(:,:,3));
r2 = I2(:,:,1)./(I2(:,:,1)+I2(:,:,2)+I2(:,:,3));
g2 = I2(:,:,2)./(I2(:,:,1)+I2(:,:,2)+I2(:,:,3));
b2 = I2(:,:,3)./(I2(:,:,1)+I2(:,:,2)+I2(:,:,3));
pr = (1/(stdev(r2)*sqrt(2*%pi)))*exp(-1*((r1-mean(r2)).^2/(2*stdev(r2))));
pg = (1/(stdev(g2)*sqrt(2*%pi)))*exp(-1*((g1-mean(g2)).^2/(2*stdev(g2))));
new = (pr.*pg);
scf(3);imshow((new),[]);

//Second: Segmentation via Histogram


r2_1 = floor(r2*255);
g2_1 = floor(g2*255);
n = size(r2);
Hist = zeros(256,256);
for i = 1:n(1)
for j =1:n(2)
x = r2_1(i,j)+1;
y = g2_1(i,j)+1;
Hist(x,y) = Hist(x,y) +1;
end
end
scf(5);plot3d(0:255,0:255,Hist);
Hist = Hist/max(Hist);

scf(2);imshow(log(Hist+0.0000000001),[]);
r1 = round(r1*255);
g1 = round(g1*255);
for i = 1:n1(1)
for j = 1:n1(2)
T(i,j) = Hist(r1(i,j)+1,g1(i,j)+1);
end
end
scf(4);imshow(T,[]);
imwrite(new/max(new),"F:\AP 186\act16\1_1.jpg");
imwrite(T,"F:\AP 186\act16\2_2.jpg");

No comments: