Monday, September 15, 2008

Activity 18: Pattern Recognition

The task: to apply pattern recognition to images of objects.

Pattern recognition is basically deciding whether a given feature vector (an ordered set of a quantifiable property, features that make up a pattern, such as color, shape, size, etc.) belongs to one of several classes (a set of patterns that share a common property).

Procedure:
**A set of objects are assembled that may be classified into 2 to 5 classes, with 10 samples for each class. Half serves as a training set, while the other half serves as a test set.
[Photo]

**Images of these objects are captured while features are chosen and extracted from them. These features are then separated into test feature vectors and training feature vectors.
Here we choose:

**The training feature vectors are then used to find the class representatives mj.
Letting wj (where j=1,2,3...W) be a set of classes and W be the total number of classes. The class representative is defined as the mean feature vector and obtained using the following equation:
where xj is the set of all feature vectors and Nj is the number of samples of class wj

**The test feature vectors are then classified using Minimum Distance, and the percent correct classification of the classifier evaluated.
A way of determining class membership is classifying an unknown feature vector x (in this case our test feature vectors) into the class whose mean or representative it is nearest to. Minimum Distance is then computed using the equation (derived from the Eucledian distance):
where j=1,2,3,...W
x is then classified into the index with the smallest distance.

The images of objects to be classified:

(a) (b) (c)
images of kwekwek (a), pillows (b), and squidballs (c)

The objects are first segmented manually so that only one object remains per image (gimp). then color image segmentation (activity 16) was used to isolate the region of interest (from this step we obtain the R G B values of the objects to use as features).
Then using a simple code:
im=imread('kwek1.jpg');
kwek1b=im2bw(im);

[x,y] = follow(kwek1b);

wid= max(x) - min(x);

hgt= max(y) - min(x)

wh = wid/hgt


we obtain the ratio of the width of the object over the height (easier than obtaining area) as a last feature.

Then the first equation above is applied to the obtained values to obtain the class representative, the results of which are given below.

Applying the second equation mentioned above to obtain the minimum distance:
table where smallest values indicate classification

as we can see above, all objects from the test set were classified correctly, although the minimum distance values were close to each other.

i give myself a grade of 10 for this activity. the classification was 100% effective.

thank you to julie ting from whom i obtained the images, since i was absent that day. thank you also to jeric for explaining the concept to me.





Wednesday, September 3, 2008

Activity 17: Basic Video Processing

The task: to perform basic video processing to obtain kinematic constants/variables.

The process:
We made short video clips that demonstrate simple kinematic motion. Marge Maallo, Julie Ting and I made a video of a glass marble bouncing off the floor after being dropped from a certain height then measured its coefficient of restitution. The coefficient of restitution of an object is a fractional value representing the ratio of velocities before and after an impact given by the following equation:
C_R = \sqrt{\frac{h}{H}}
where h is the bounce height and H is the drop (original) height.
The program VideoHub was used to parse the original .avi file into .jpg images. Below is a sample of the image obtained from VideoHub after being converted to greyscale.

greyscaled image of marble in its "drop" position

As can be seen in the image, one problem was the orientation of the camera when we took the video. To fix this Scilab was used to obtain the angle at which the camera was tilted, and then Gimp was used to manually rotate the images then crop them.

(a) (b)
cropped images of the marble in its drop (a) and bounce (b) positions

The distance of the marble from the floor was measured and we obtained
h = 62 pixels
H = 66 pixels

applying the equation for coefficient of restitution, we obtain:
coefficient of restitution = 0.94


**I give myself a grade of 8 for this activity because although the desired kinematic variable was obtained, a sizeable part of the process was done manually.

**acknowledgement goes to my groupmates in this activity, Julie and Marge. The equation and definition for Coefficient of Restitution (COF) were obtained from Wikipedia.

Monday, September 1, 2008

Activity 16: Color Image Segmentation

The task: to segment the Region of Interest(ROI) of an image by their color.

Two methods are investigated. parametric and non-parametric (histogram backprojection) probability distribution.

First though, for both methods, the RGB values of the region of interest are obtained and converted into normalized chromaticity coordinates (NCC), using the following equations:
[ncc.jpg]
since b (blue) can now be expressed as a function of r(red) and g(green) now though, we can discard it and only consider the latter 2.

The original image:
we want to segment the heart-shaped royal blue swarovski pendant.

The histogram of the crystal is shown below in chromaticity space:

Looking at this representation of the RG(b) color space,
[rgcc.jpg]
we can say that the above histogram is a valid representation of the colors in our region of interest.

Now we compare the results after using both methods:
Parametric Probability Distribution
Histogram Back-Projection
For my image, contrary to what expected from I've learned from my classmates' results, both methods gave about the same quality of image. One can clearly see the heart shape and even some hints of the 3D shape of the pendant after the application of both methods.

Code:
stacksize(4e7);

im1 = imread('act16c.jpg');
im2 = imread('act16b.jpg');
//imshow(im1);

R1 = im1(:,:,1);
G1 = im1(:,:,2);
B1 = im1(:,:,3);
I1 = R1 + G1 + B1;
R2 = im2(:,:,1);
G2 = im2(:,:,2);
B2 = im2(:,:,3);
I2 = R2 + G2 + B2;

r1 = R1./I1;
g1 = G1./I1;
b1 = B1./I1;
r2 = R2./I2;
g2 = G2./I2;
b2 = B2./I2;

//parametric
ur = mean(r2); sr = stdev(r2);
ug = mean(g2); sg = stdev(g2);

pr = 1.0*exp(-((r1-ur).^2)/(2*sr^2))/(sr*sqrt(2*%pi));
pg = 1.0*exp(-((g1-ug).^2)/(2*sg^2))/(sg*sqrt(2*%pi));

prob = pr.*pg;
prob = prob/max(prob);
//imshow(prob,[]);

//histogram
r = linspace(0,1,32);
g = linspace(0,1, 32);
P = zeros(32,32);
[x,y] = size(im2);
for i = 1:x
for j = 1:y
xr = find(r <= im2(i,j,1));
xg = find(g <= im2(i,j,2));
P(xr(length(xr)), xg(length(xg))) = P(xr(length(xr)), xg(length(xg)))+1;
end
end
P = P/sum(P);
//surf(P);

//backprojection
[x,y] = size(im1);
recons = zeros(x,y);
for i = 1:x
for j = 1:y
xr = find(r <= im1(i,j,1));
xg = find(g <= im1(i,j,2));
recons(i,j) = P(xr(length(xr)), xg(length(xg)));
end
end
recons1 = im2bw(recons, 0.5);
//imshow(recons1, []);


**I give myself a grade of 10 for this activity, the region of interest was successfully segmented using either method.

**Thank you to Jeric Tugaff.