📄 runfacedetection.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% faceDetection DP solun
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[lEyes, rEyes, mouths] = inputFacialFeatures(6, 6, 6);
figure;
[faces] = faceDetection(lEyes, rEyes, mouths, 0.1, 'b');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% faceDetection BF solun
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:2
[le, re, mo] = inputFacialFeatures(3, 3, 3);
[p, stats] = eyesMouthLikelihood(le, re, mo);
p
end
[le, re, mo] = inputFacialFeatures(4,4,4);
[faces] = getFaces(le,re,mo, 0.5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% test readPgm()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
facePath='D:/data/ATT-Face/s1/';
offs = 0;
for k=offs+1:4
pgm = sprintf('%s%d.pgm', facePath, k);
[f1]=readPgm(pgm);
subplot(2,2,k);
colormap('gray');
imagesc(f1);
end
clear;
j = 8;
f1=loadATTFace(j, 1);
f2=loadATTFace(j, 4);
f3=loadATTFace(j, 8);
f4=loadATTFace(j, 10);
colormap('gray');
subplot(2,2,1); imagesc(f1);
subplot(2,2,2); imagesc(f2);
subplot(2,2,3); imagesc(f3);
subplot(2,2,4); imagesc(f4);
for
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Face Detection: Null space energy detection
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% full face model: 25x20
clear;
side = 0.5; top= 1.0; low = 1.5; fw=20; fh=25;
[T1, lat1, mf1, faceIcons]=computeFeretFacePCA(side, top, low, fw, fh);
first='n';
if first=='y'
save 'faceIconsW20H25.dat' faceIcons -ascii;
save 'T-fd1.dat' T1 -ascii;
save 'Mf-fd1.dat' mf1 -ascii;
save 'lat-fd1.dat' lat1 -ascii;
else
faceIcons = load('faceIconsW20H25.dat');
[n d]=size(faceIcons);
T1 = load('T-fd1.dat');
mf1 = load('Mf-fd1.dat');
lat1 = load('lat-fd1.dat');
end
% get non face samples
W=20; H=25; nSample=500;
nf1=getNonFaceSamples('data\nf1.jpg', W, H, nSample);
nf2=getNonFaceSamples('data\nf2.jpg', W, H, nSample);
nf3=getNonFaceSamples('data\nf3.jpg', W, H, nSample);
nf4=getNonFaceSamples('data\nf4.jpg', W, H, nSample);
nonFace=[nf1 nf2 nf3 nf4];
nonFace=double(nonFace);
[d, m]=size(nonFace);
% projection
pNonFace = T1*(nonFace - mf1');
ef=zeros(n,1); ex1=zeros(n,1); ex2=zeros(n,1);
K=24;
for j=1:n
f = faceIcons(j,:); ef(j)=f*f';
x = T1*(f-mf1)'; x1=x(1:K); x2=x(K+1:d);
e1=x1'*x1; e2=x2'*x2; ex1(j)=e1; ex2(j)=e2;
end
[ef2, indx]=sort(ef);
ey1=ex1(indx); ey2=ex2(indx);
subplot(3,1,1); plot(ey1/ef2);
subplot(3,1,2); plot(ey2/ef2);
subplot(3,1,3); plot(ey2/ey1);
k1=1; k2=n;
subplot(2,1,1); plot(ef2(k1:k2)); subplot(2,1,2); plot(ey2(k1:k2)/ey1(k1:k2)); xlabel('\fontsize{14} K=32');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ECE 432 proj
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Fisherface
Given:
same training & recognition images, also sized N by N pixels
P1 = eigenface result
Feature Extraction:
% same as eigenface
A = X - [me me ... me]
% compute N^2 by N^2 between-class scatter matrix
for i=1:c
Sb = Sb + clsMeani*clsMeani'
% compute N^2 by N^2 within-class scatter matrix
for i=1:c, j=1:ci
Sw = Sw + (X(j)-clsMeani)*(X(j)-clsMeani)'
% project into (N-c) by (N-c) subspace using PCA
Sbb = P1'*Sb*P1
Sww = P1'*Sw*P1
% generalized eigenvalue decomposition
% solves Sbb*V = Sww*V*D
[V,D] = eig(Sbb,Sww)
eigVals = diag(D)
lmda = eigVals(1:Mp)
P = P1*V(:,1:Mp)
% store training weights
train_wt = P'*A
Nearest-Neighbor Classification:
% same as eigenface
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -