-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcayontemi.m
52 lines (51 loc) · 1.32 KB
/
pcayontemi.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function [taninma dbadi recognized_img]=pcayontemi(datapath,test_image)
D = dir(datapath);
imgcount = 0;
for i=1 : size(D,1)
if not(strcmp(D(i).name,'.')|strcmp(D(i).name,'..')|strcmp(D(i).name,'Thumbs.db'))
imgcount = imgcount + 1;
end
end
X = [];
for i = 1 : imgcount
str = strcat(datapath,'\',int2str(i),'.jpg');
img = imread(str);
img = rgb2gray(img);
[r c] = size(img);
temp = reshape(img',r*c,1);
X = [X temp];
end
m = mean(X,2);
imgcount = size(X,2);
A = [];
for i=1 : imgcount
temp = double(X(:,i)) - m;
A = [A temp];
end
L= A' * A;
[V,D]=eig(L);
L_eig_vec = [];
for i = 1 : size(V,2)
L_eig_vec = [L_eig_vec V(:,i)];
end
eigenfaces = A * L_eig_vec; %
projectimg = [ ];
for i = 1 : size(eigenfaces,2)
temp = eigenfaces' * A(:,i);
projectimg = [projectimg temp];
end
test_image = test_image(:,:,1);
[r c] = size(test_image);
temp = reshape(test_image',r*c,1);
temp = double(temp)-m;
projtestimg = eigenfaces'*temp;
euclide_dist = [ ];
for i=1 : size(eigenfaces,2)
temp = (norm(projtestimg-projectimg(:,i)))^2;
euclide_dist = [euclide_dist temp];
end
euclide_dist/1.0e+17
[euclide_dist_min recognized_index] = min(euclide_dist);
taninma = euclide_dist_min/1.0e+17;
dbadi = recognized_index;
recognized_img = strcat(int2str(recognized_index),'.jpg');