-
Notifications
You must be signed in to change notification settings - Fork 10
/
eigen_reconstruction.m
66 lines (50 loc) · 1.46 KB
/
eigen_reconstruction.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
row=112;
column=92;
NN=row*column;
Class_Train_NUM=5;
Class_Sample_NUM=10; % total
Class_Test_NUM=Class_Sample_NUM-Class_Train_NUM;
Class_NUM=40;
Train_NUM=Class_NUM*Class_Train_NUM; %
Test_NUM=Class_NUM*(Class_Sample_NUM-Class_Train_NUM); %
Eigen_NUM=10;
Disc_NUM=Eigen_NUM;
Train_DAT=zeros(NN,Train_NUM);
s=1;
for r=1:Class_NUM
for t=1:Class_Train_NUM
string=['E:\ORL_face\orlnumtotal\s' int2str(r) '_' int2str(t)];
A=imread(string,'bmp');
B=im2double(A);
Train_DAT(:,s)=B(:);
s=s+1;
end
end
Test_DAT=zeros(NN,Test_NUM);
s=1;
for r=1:Class_NUM
for t=Class_Train_NUM+1:Class_Sample_NUM
string=['E:\ORL_face\orlnumtotal\s' int2str(r) '_' int2str(t)];
A=imread(string,'bmp');
B=im2double(A);
Test_DAT(:,s)=B(:);
s=s+1;
end
end
% to center the each training sample and testing sample
% !!! Note that: Centralization have great effection when
% Cos distance is used, but it has no impact when L2 or L1 distance is used
Mean_Image=mean(Train_DAT,2);
Train_DAT=Train_DAT-Mean_Image*ones(1,Train_NUM);
Test_DAT=Test_DAT-Mean_Image*ones(1,Test_NUM);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[Projection,disc_value]=Eigenface_f(Train_DAT, Disc_NUM);
Eigen_face=zeros(NN,10);
for k=1:1:10
Eigen_face(:,k)=Projection(:,k);
Eigen_face(:,k)=mat2gray(Eigen_face(:,k));
end
Eigen_face=reshape(Eigen_face,[row,column,10]);
for count=1:1:10
subplot(1,10,count);imshow(Eigen_face(:,:,count))
end