Saturday, October 4, 2008

Activity 18 - Pattern Recognition

In this activity, we gathered different samples with same quantities. Our samples are Piatos, Pillows, Kwek-Kwek and Vcut. Per sample, we gathered 8 of this samples.


Half of these samples are the training samples and half are the test samples. To identify the membership of the test samples to what classification it belongs, feature of that sample and the training samples should be obtained. For example, the color of the training samples of piatos should share the same color as the test samples of piatos.


The mean of the feature vectors are extracted from the training samples. In my case, the feature vectors I used are the mean and the standard deviation of the red and grenn values of the training samples. I added all features vectors and values are given below:




piatos = 0.8979285


vcut = 0.9626847


kwek-kwek = 1.0137804


pillows = 0.9057169




Same feature vectors were also obtained from the test samples and obtaied the sum of these feature vectors. To find the classification of that test sample, the summed feature vector of the test sample is subtracted to the summed feature vector of the training sample and find where it is minimum. The results are given below:

Note that for samples Pillow and Piatos, the percentage of classification did not obtain a perfect classification becuase the feature vector has small difference. But for both Vcut and KwekKwek, 100% classification were obtained.

For this activity, I will give myself a grade of 8 because I think I've met all the objectives though the classification was'nt perfect.
Appendix:
Source code:
I = [];
I1 = [];
for i =5:8
I = imread("kwekkwek" + string(i) + ".JPG");
I1 = imread("kwekkwekc"+string(i)+".JPG");
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 = I1(:,:,1)./(I1(:,:,1)+I1(:,:,2)+I1(:,:,3));
g2 = I1(:,:,2)./(I1(:,:,1)+I1(:,:,2)+I1(:,:,3));
b2 = I1(:,:,3)./(I1(:,:,1)+I1(:,:,2)+I1(:,:,3));
r2_1 = floor(r2*255); g2_1 = floor(g2*255);
Standr2(i) = stdev(r2);
Standg2(i) = stdev(g2);
Meanr2(i) = mean(r2);
Meang2(i) = mean(g2);
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);
new2 = new/max(new);
new3 = im2bw(new2,0.7);
[x,y] = follow(new3);
n = size(x);
x2 = x;
y2 = y;
x2(1) = x(n(1));
x2(2:n(1))=x(1:(n(1)-1));
y2(1) = y(n(1));
y2(2:n(1))=y(1:(n(1)-1));
area(i) = abs(0.5*sum(x.*y2 - y.*x2));//Green's Theorem imwrite(new3,"pill" + string(i)+".JPG");
end
training = [0.8979285 0.9626847 1.0137804 0.9057169];
train = mean(Meanr2(1:4))+mean(Meang2(1:4))+mean(Standr2(1:4))+mean(Standg2(1:4));
for i = 1:4
for j = 1:4
test(i,j) = abs((Meanr2(4+i) +Meang2(4+i) + Standr2(4+i) + Standg2(4+i)) - training(j));
end
end


No comments: