📄 face1.m
字号:
clear all;
numb=64; %Retain 64 Principal components
pp1=56;pp2=46; % Row Size of FACE Image is 112; Column Size of FACE Image is 92
%for i=1:1:300 % Read 420 YALE FACE Images
% st=num2str(i); s=double(imread(st,'jpg'));
% x(:,i)=reshape(s(1:2:112,1:2:92),pp1*pp2,1); %Chang FACE Image Into 1*10304 Vector
%end
k=1;
for i=1:35 % Read 420 YALE FACE Images
for j=1:6
t=(i-1)*6+j
st=num2str(t);
s=double(imread(st,'jpg'));
x(:,k)=reshape(s(1:2:112,1:2:92),pp1*pp2,1);k=k+1; %Chang FACE Image Into 1*10304 Vector
end
end
for i=36:70 % Read 420 YALE FACE Images
for j=1:6
t=(i-1)*6+j
st=num2str(t);
s=double(imread(st,'jpg'));
x(:,k)=reshape(s(1:2:112,1:2:92),pp1*pp2,1);k=k+1; %Chang FACE Image Into 1*10304 Vector
end
end
%P=size(x,1);% Column size 112*92 of PCA Input Variable;
N=size(x,1); % Row size 112*92 of PCA Input Variable;
mb=mean(x);B1=x-ones(N,1)*mb;%********subtract mean
%********Find eigenvectors vi of B'B (PxP)
%[V,D] = eig (1/(N-1)*(B1*B1')); %scale factor gives eigvals correct
%magnitude for large cov mat
%(assuming sample cov)
%(assuming sample cov)
%********Sort eigenvectors
[V,D] = eig (B1*B1');
eigvalvec = max(D);[seigvals, index] = sort(eigvalvec); % sort goes low to high
Vsort = V(:,[fliplr(index)]);
x1=(Vsort(:,1:200))';%(U(:,1:64,))';
figure
for i=1:numb
subplot(8,8,i)
t=mat2gray(reshape(x1(i,:),pp1,pp2),[min(x1(i,:)) max(x1(i,:))]);
imshow(t);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -