-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmildamain5.m
175 lines (161 loc) · 4.19 KB
/
smildamain5.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
clc;
close all;
clear all;
TrainDatabasePath = uigetdir('C:\Users\Fathima\Desktop\thesis folder\orl', 'Select training database path');
M=40;
N=9;
%P=2;
M1=M*N;
gama=[];
num_lines= 1;
def = {'1','10'};
prompt={'Enter test image name (a number between 1 to 40):','enter a no:between 1 to 10'};
dlg_title = 'Input of PCA-Based Face Recognition System';
TestDatabasePath = uigetdir('C:\Users\Fathima\Desktop\thesis folder\orl', 'Select test database path');
answer = inputdlg(prompt,dlg_title,num_lines,def);
x = str2num(answer{1});
y = str2num(answer{2});
TestImage= strcat('\S',sprintf('%d',x),'\',int2str(y),'.pgm');
TestImage = strcat(TestDatabasePath,TestImage);
for i=1:M
for j=1:N
% if (i==x)&&(j==y)
% continue;
% end
str = strcat('\S',sprintf('%d',i),'\',int2str(j),'.pgm');
str = strcat(TrainDatabasePath,str);
img = imread(str);
temp=transpose(img);
temp=reshape(temp,numel(temp),1);
gama=[gama temp];
end
end
mean_All= mean(gama,2);
A = [];
for i = 1 : M1
t = double(gama(:,i)) - mean_All;
A = [A t];
end
L=A'*A;
[V D] = eig(L);
L_eig_vec = [];
for i=360:-1:320;
L_eig_vec = [L_eig_vec V(:,i)];
end
Eigenfaces = A * L_eig_vec;
ProjectedImages_PCA= [];
for i = 1 :M1
temp = Eigenfaces'*A(:,i); % Projection of centered images into facespace
ProjectedImages_PCA = [ProjectedImages_PCA temp];
end
P=M*N;
Class_population=N;
Class_number=M;
m_PCA = mean(ProjectedImages_PCA,2); % Total mean in eigenspace
m = zeros(41,Class_number);
Sw = zeros(41,41); % Initialization os Within Scatter Matrix
Sb = zeros(41,41); % Initialization of Between Scatter Matrix
for i = 1 : Class_number
m(:,i) = mean( ( ProjectedImages_PCA(:,((i-1)*Class_population+1):i*Class_population) ), 2 )';
S = zeros(41,41);
for j = ( (i-1)*Class_population+1 ) : ( i*Class_population )
S = S + (ProjectedImages_PCA(:,j)-m(:,i))*(ProjectedImages_PCA(:,j)-m(:,i))';
end
Sw = Sw + S; % Within Scatter Matrix
Sb = Sb + Class_number*((m(:,i)-m_PCA) * (m(:,i)-m_PCA)'); % Between Scatter Matrix
end
[J_eig_vec, J_eig_val] = eig(Sb,Sw); % Cost function J = inv(Sw) * Sb
J_eig_vec = fliplr(J_eig_vec);
%%%%%%%%%%%%%%%%%%%%%%%% Eliminating zero eigens and sorting in descend order
for i = 1 : Class_number-1
V_Fisher(:,i) = J_eig_vec(:,i); % Largest (C-1) eigen vectors of matrix J
end
for i = 1 : Class_number*Class_population
ProjectedImages_Fisher(:,i) = V_Fisher' * ProjectedImages_PCA(:,i);
end
InputImage= imread(TestImage);
figure;
imshow(InputImage);title('Input Test Image');
temp = InputImage(:,:,1);
[irow icol] = size(temp);
InImage = reshape(temp',irow*icol,1);
Difference = double(InImage)- mean_All; % Centered test image
ProjectedTestImage = V_Fisher' * Eigenfaces' * Difference; % Test image feature vectorED = [];
ED=[];
for i=1:M1
q = ProjectedImages_Fisher(:,i);
d= ProjectedTestImage - q;
d1=sum(d.*d);
ED=[ED d1];
end
[Euc_dist_min , Recognized_index] = min(ED);
n = Recognized_index;
for L=1:M
if n<=9*L
str = strcat('Matched person is : ',int2str(L));
disp(str);
break
end
end
b= mod(n,9);
if b==0
b=9;
end
outputname= strcat('\S',sprintf('%d',L),'\',int2str(b),'.pgm');
disp(outputname);
outputname = strcat(TestDatabasePath,outputname);
outputname=imread(outputname);
figure,imshow(outputname);
title('Matched Image');
INDEX=[];
% for i=1:M1
%
% if ED(i)<=0.5
% INDEX=[INDEX i];
% end
% end
u=[];
t=[];
for i=1:10
[Euc_dist_min , Recognized_index] = min(ED);
n = Recognized_index;
u=[u n];
t=[t Euc_dist_min];
ED(n)=100
end
INDEX=u;
T=size(INDEX,2)
if T==0
display('Not authenticated');
break
end
FT=[];
for i=1:10
fvi=u(i);
FM=FINGERFIN5(fvi);
FT=[FT FM];
end
k=smipcamain5(INDEX,InputImage,gama);
%[tem in]=min(k);
f=k;
u1=[];
t1=[];
for i=1:5
[Euc_dist_min , Recognized_index] = min(k);
n = Recognized_index;
u1=[u1 FT(n)];
t1=[t1 Euc_dist_min];
k(n)=100
end
% fvi=INDEX(in);
% FM=FINGERFIN5(fvi);
% disp(FM);
% d=mainedt5()
% g=size(d);
% for i=1:g
% if d(g)==FM
% str = strcat('Matched person is : ',int2str(FM));
% disp(str);
% display('Authenticated');
% end
% end