
Two methods were used in this activity - parametric and nonparametric. For parametric a Gaussian Probability Distribution is used. The equation of which is given by

Although both estimations would suffice, a better segmentation is achieved with parametric estimation. It is also interesting that even the red "thingy" is well seen for parametric estimation. For the image used, the objects were separated from the background and from each other. Note however that we are only interested in segmenting the blue cups. Strictly speaking we did not segment the red "thingy". It just so happened that the background is violet (both with red and blue) which are the colors of the object that is why a gray color can be observed. Recall that when segmenting, what happens is that the region of interest becomes white. Any other color has different value.
Code:
stacksize(4e7);
chdir("C:\Documents and Settings\mimie\Desktop\186-12"); patch = imread("patch.jpg"); image = imread("cups.jpg"); ave = patch(:,:,1)+patch(:,:,2)+patch(:,:,3)+1e-7;
R = patch(:,:,1)./ave;
G = patch(:,:,2)./ave;
B = patch(:,:,3)./ave;
r = R*255;
g = G*255;
ave2 = image(:,:,1)+image(:,:,2)+image(:,:,3)+1e-7;
r2 = image(:,:,1)./ave2;
g2 = image(:,:,2)./ave2;
b2 = image(:,:,3)./ave2;
f = zeros(256,256);
for i=1:size(r,1)
for j=1:size(r,2)
x = abs(round(r(i,j)))+1;
y = abs(round(g(i,j)))+1;
f(x,y) = f(x,y)+1;
end
end
//imshow((frequency+0.0000000001));
//mesh(frequency);
//xset("colormap",jetcolormap(256));
\\\\parametric
rmean = mean(R);
rdev = stdev(R);
gmean = mean(G);
gdev = stdev(G);
rprob = (1/(rdev*sqrt(2*%pi)))*exp(-((r2-rmean).^2)/2*rdev);
gprob = (1/(gdev*sqrt(2*%pi)))*exp(-((g2-gmean).^2)/2*gdev);
prob = rprob.*gprob;
prob = prob/max(prob);
scf(0); imshow(image);
scf(1); imshow(prob,[]);
\\\\nonparametric
R2 = r2*255;
G2 = g2*255;
s = zeros(size(image,1),size(image,2));
for i = 1:size(R2,1)
for j = 1:size(R2,2)
x = abs(round(R2(i,j)))+1;
y = round(G2(i,j))+1;
s(i,j) = f(x,y);
end
end
scf(1); imshow(log(s+0.000000000001),[]);
scf(2); imshow(image);
Note:
Comment the parametric to use nonparametric
For this activity, I give myself an 8/10 since I'm not sure if I fully understand the activity.