Wednesday, September 10, 2008
Activity 16: Parametric versus Non-Parametric Probability Distribution
Continuing our excursion on colorimetry we move on to color image segmentation. We know that there are three levels in a true color image, the red, the green, and the blue. If we pick a region of interest (ROI) in an image and obtain its RGB values, we can see which among the entire image has the same probability as our ROI. The applications of this procedure are manifold, it can be a tool for face recognition, cell recognition in microscopy, etc.

The math is all in the lecture so instead of dwelling in the math, let's move on to explaining the methodology and results.

In parametric estimation we have a fundamental assumption: that is, our ROI has a normally distributed RGB value. Having said that we can compare the value of our ROI to every pixel in the entire image. Those with a value of 1 ("white") indicates that the probability of the pixel falling into our region of interest is very high. Here is the code:

stacksize(1e7);
chdir('G:\poy\poy backup\physics\186\paper 16')
im = imread('blue ball.jpg');
im1 = imread('blue ball cropped.jpg');
//imshow(im1);

R = im(:,:,1);
G = im(:,:,2);
B = im(:,:,3);
I = R + G + B;

R1 = im1(:,:,1);
G1 = im1(:,:,2);
B1 = im1(:,:,3);
I1 = R1 + G1 + B1;

r = R./I;
g = G./I;
b = B./I;

r1 = R1./I1;
g1 = G1./I1;
b1 = B1./I1;

Mr = mean(r1);
Sr = stdev(r1);
Mg = mean(g1);
Sg = stdev(g1);

Pr = 1.0*exp(-((r-Mr).^2)/(2*Sr^2))/(Sr*sqrt(2*%pi));
Pg = 1.0*exp(-((g-Mg).^2)/(2*Sg^2))/(Sg*sqrt(2*%pi));

Prob = Pr.*Pg;
Prob = Prob/max(Prob);
imshow(Prob,[]);

The next method is by histogram backprojection. This works by assigning the probability by using the 3D histogram as a scale. That is, if the pixel falls on the peak of the histogram, it is white, if at the bottom then it is black. The histogram for a blue and orange ball is shown below.

The code is shown below: (Note that the code is connected with the code above)

//3D histogram
r2 = linspace(0,1,32); g2 =linspace(0,1,32);
P1 = zeros(32,32);
[x,y] = size(im1);
for i = 1:x
for j = 1:y
xr = find(r2 <= im1(i,j,1));
xg = find(g2 <= im1(i,j,2));
P1(xr(length(xr)), xg(length(xg))) = P1(xr(length(xr)), xg(length(xg)))+1;
end
end
P1 = P1/sum(P1);
surf(P1);

//backprojection
[x,y] = size(im);
recons = zeros(x,y);
for i = 1:x
for j = 1:y
xr = find(r2 <= im(i,j,1));
xg = find(g2 <= im(i,j,2));
recons(i,j) = P1(xr(length(xr)), xg(length(xg)));
end
end
//imshow(recons, []);

Now to compare the results:

The result shows that the assumption of whether the ROI has a distributed RGB value or not matters. In the parametric method, we see a grainy output indicating the smooth transition that a Gaussian distribution (assumption) gives. The non-parametric method shows a sharp transition of values which indicates the sharp distribution from the histogram plot.

Acknowledgments:

I did everything ALMOST on my own. But thanks for Jeric and Cole for their assistance. I give myself 10 neutrinos!
posted by poy @ 3:52 PM  
2 Comments:
Post a Comment
<< Home
 
 
About Me

Name: poy
Home: Quezon City, NCR, Philippines
About Me:
See my complete profile
Previous Post
Archives
Template by
Blogger templates