first commit with current lessons
BIN
09-29/eigenfaces/cameraman.tif
Executable file
38
09-29/eigenfaces/eigenfaces_classify.m
Executable file
@ -0,0 +1,38 @@
|
||||
function [matched_individual,bestmatchdistance]=eigenfaces_classify(test,training,n);
|
||||
%classifies using n principal components, closest match
|
||||
[w, h, nExpressions, nIndividuals]=size(training);
|
||||
X=reshape(training,[w*h,nIndividuals*nExpressions]);
|
||||
avg=mean(X,2);
|
||||
Xd=bsxfun(@minus,X,avg);
|
||||
[U,S,V]=svd(Xd,0);
|
||||
Xt=reshape(test,w*h,numel(test)/(w*h));
|
||||
Xtd=bsxfun(@minus,Xt,avg);
|
||||
scores=U(:,1:n)'*Xtd;
|
||||
trainingscores=U(:,1:n)'*Xd;
|
||||
%normalize scores and samples
|
||||
%scores=bsxfun(@rdivide,scores,sqrt(sum(abs(scores).^2)));
|
||||
%trainingscores=bsxfun(@rdivide,trainingscores,sqrt(sum(abs(trainingscores).^2)));
|
||||
%cosine similarity
|
||||
%C=scores'*trainingscores;
|
||||
%[bestmatchdistance bestmatchindex]=max(C,[],2);
|
||||
%matched_individual=ceil(bestmatchindex/nExpressions);
|
||||
|
||||
%Euclidean distance
|
||||
distanceMatrix=nan(size(scores,2),size(trainingscores,2));
|
||||
for i=1:size(scores,2)
|
||||
for j=1:size(trainingscores,2)
|
||||
distanceMatrix(i,j)=norm(scores(:,i)-trainingscores(:,j));
|
||||
end
|
||||
end
|
||||
[bestmatchdistance bestmatchindex]=min(distanceMatrix,[],2);
|
||||
matched_individual=ceil(bestmatchindex/nExpressions);
|
||||
if numel(test)==w*h
|
||||
subplot(1,2,1);
|
||||
imagesc(test);
|
||||
colormap(gray);
|
||||
subplot(1,2,2);
|
||||
imagesc(reshape(X(:,bestmatchindex),[w,h]));
|
||||
colormap(gray);
|
||||
disp('best match distance=');
|
||||
disp(bestmatchdistance);
|
||||
end
|
||||
18
09-29/eigenfaces/eigenfaces_scatter.m
Executable file
@ -0,0 +1,18 @@
|
||||
function eigenfaces_scatter(images, indices);
|
||||
|
||||
[w, h, nExpressions, nIndividuals]=size(images);
|
||||
X=reshape(images,[w*h,nIndividuals*nExpressions]);
|
||||
avg=mean(X,2);
|
||||
Xd=bsxfun(@minus,X,avg);
|
||||
[U,S,V]=svd(Xd,0);
|
||||
scores=U(:,indices)'*Xd;
|
||||
%normalize scores and samples
|
||||
%scores=bsxfun(@rdivide,scores,sqrt(sum(abs(scores).^2)));
|
||||
|
||||
if length(indices) == 3
|
||||
scatter3(scores(1,:),scores(2,:),scores(3,:),50*ones(size(scores(1,:))),kron(1:nIndividuals,ones(1,nExpressions)));
|
||||
elseif length(indices) == 2
|
||||
scatter(scores(1,:),scores(2,:),50*ones(size(scores(1,:))),kron(1:nIndividuals,ones(1,nExpressions)));
|
||||
else
|
||||
error('wrong indices size');
|
||||
end
|
||||
29
09-29/eigenfaces/interactiverec.m
Executable file
@ -0,0 +1,29 @@
|
||||
function interactiverec(F)
|
||||
% given a 243x320 image F, displays it as sum of components
|
||||
stdsize=[243,320];
|
||||
|
||||
F = F(:);
|
||||
|
||||
if not(numel(F) == prod(stdsize))
|
||||
error('The first argument must be the picture to reconstruct');
|
||||
end
|
||||
|
||||
X=readyalefaces_to_tensor;
|
||||
X=reshape(X,[prod(stdsize),numel(X)/prod(stdsize)]);
|
||||
avg=mean(X,2);
|
||||
Xs=bsxfun(@minus,X,avg);
|
||||
[U,S,V]=svd(X,0);
|
||||
colormap(gray);
|
||||
ncolors=size(gray,1);
|
||||
h = image(reshape(avg,stdsize)*ncolors);
|
||||
|
||||
% Add a slider
|
||||
uicontrol('Style', 'slider', 'Min', 0, 'Max', size(U,2), ...
|
||||
'Callback', @callback,'Position',[10 0 300 20]);
|
||||
|
||||
function callback(src,evt)
|
||||
d=round(get(src, 'Value'))
|
||||
set(h, 'CData', reshape(ncolors*(avg+U(:,1:d)*(U(:,1:d)'*F)),stdsize));
|
||||
end
|
||||
|
||||
end
|
||||
BIN
09-29/eigenfaces/otherfaces/bart.png
Executable file
|
After Width: | Height: | Size: 18 KiB |
BIN
09-29/eigenfaces/otherfaces/bart.xcf
Executable file
BIN
09-29/eigenfaces/otherfaces/bart_unedited.jpg
Executable file
|
After Width: | Height: | Size: 12 KiB |
BIN
09-29/eigenfaces/otherfaces/car.png
Executable file
|
After Width: | Height: | Size: 37 KiB |
BIN
09-29/eigenfaces/otherfaces/car.xcf
Executable file
BIN
09-29/eigenfaces/otherfaces/car_unedited.jpg
Executable file
|
After Width: | Height: | Size: 12 KiB |
34
09-29/eigenfaces/readyalefaces_to_tensor.m
Executable file
@ -0,0 +1,34 @@
|
||||
function [F,descr] = readyalefaces_to_tensor(str)
|
||||
|
||||
if not(exist('str','var'))
|
||||
str='all';
|
||||
end
|
||||
switch str
|
||||
case 'easy'
|
||||
extensions = {'happy', 'normal', 'sad', 'sleepy', 'surprised', 'wink' };
|
||||
case 'easy-nowink'
|
||||
extensions = {'happy', 'normal', 'sad', 'sleepy', 'surprised' };
|
||||
case 'nowink'
|
||||
extensions = {'centerlight', 'glasses', 'happy', 'leftlight', 'noglasses', 'normal', 'rightlight', 'sad', 'sleepy', 'surprised' };
|
||||
case {'hard','all'}
|
||||
extensions = {'centerlight', 'glasses', 'happy', 'leftlight', 'noglasses', 'normal', 'rightlight', 'sad', 'sleepy', 'surprised', 'wink' };
|
||||
otherwise
|
||||
error 'unknown selector';
|
||||
end
|
||||
|
||||
for i = 1 : 15,
|
||||
basename = 'yalefaces/subject';
|
||||
if( i < 10 )
|
||||
basename = [basename, '0', num2str(i)];
|
||||
else
|
||||
basename = [basename, num2str(i)];
|
||||
end;
|
||||
|
||||
for j = 1:length(extensions),
|
||||
fullname = [basename, '.', extensions{j}, '.gif'];
|
||||
X = imread(fullname);
|
||||
F(:,:,j,i) = double(X)/255;
|
||||
end;
|
||||
|
||||
end;
|
||||
descr=extensions;
|
||||
13
09-29/eigenfaces/showyalefaces.m
Executable file
@ -0,0 +1,13 @@
|
||||
X=readyalefaces_to_tensor;
|
||||
%X = X(:,:,1:4,[12,9,6,1]); %filters out only some faces
|
||||
[w h expr ind]=size(X);
|
||||
clf;
|
||||
for i=1:expr
|
||||
for j=1:ind
|
||||
subplot('position', [(i-1)/expr, (j-1)/ind,1/expr,1/ind]);
|
||||
% subplot(expr,ind,j+(i-1)*ind);
|
||||
imagesc(X(:,:,i,j));
|
||||
colormap(gray);
|
||||
end
|
||||
end
|
||||
set(findobj(gcf, 'type','axes'), 'Visible','off')
|
||||
7
09-29/eigenfaces/tightsubplot.m
Executable file
@ -0,0 +1,7 @@
|
||||
function tightsubplot(dim, i, data)
|
||||
|
||||
row = mod(i-1, dim);
|
||||
col = floor((i-1) / dim);
|
||||
subplot('position', [row*(1/dim), (dim-col-1)*(1/dim), 1/dim-.001, 1/dim-0.001 ]);
|
||||
imagesc(data);
|
||||
axis off;
|
||||
29
09-29/eigenfaces/yalefaces/README
Executable file
@ -0,0 +1,29 @@
|
||||
The Yale Face Database
|
||||
----------------------
|
||||
|
||||
The database contains 165 GIF images of 15 subjects (subject01,
|
||||
subject02, etc.). There are 11 images per subject, one for each
|
||||
of the following facial expressions or configurations: center-light,
|
||||
w/glasses, happy, left-light, w/no glasses, normal, right-light,
|
||||
sad, sleepy, surprised, and wink. Note that the image "subject04.sad"
|
||||
has been corrupted and has been substituted by "subject04.normal".
|
||||
|
||||
All the images including this readme file are contained in the file
|
||||
"yalefaces.tar". It can be unpacked with:
|
||||
|
||||
tar xvf yalefaces.tar
|
||||
|
||||
A directory called "yalefaces" will be created containing all the images.
|
||||
These can be viewed using "xv" or ported with any software package that
|
||||
can understand the GIF format.
|
||||
|
||||
You are free to use the Yale Face Database for research purposes.
|
||||
If experimental results are obtained that use images from within the
|
||||
database, all publications of these results should acknowledge the use
|
||||
of the "Yale Face Database." Without permission from Yale, images
|
||||
from within the database cannot be incorporated into a larger database
|
||||
which is then publicly distributed.
|
||||
|
||||
If you have any trouble or questions please email Prof. David Kriegman
|
||||
(kriegman@yale.edu) or Prof. Peter Belhumeur (Belhumeur@ledoux.eng.yale.edu).
|
||||
|
||||
BIN
09-29/eigenfaces/yalefaces/subject01.centerlight.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.glasses.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.happy.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.leftlight.gif
Executable file
|
After Width: | Height: | Size: 42 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.noglasses.gif
Executable file
|
After Width: | Height: | Size: 33 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.normal.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.rightlight.gif
Executable file
|
After Width: | Height: | Size: 70 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.sad.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.sleepy.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.surprised.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject01.wink.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.centerlight.gif
Executable file
|
After Width: | Height: | Size: 30 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.glasses.gif
Executable file
|
After Width: | Height: | Size: 44 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.happy.gif
Executable file
|
After Width: | Height: | Size: 43 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.leftlight.gif
Executable file
|
After Width: | Height: | Size: 37 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.noglasses.gif
Executable file
|
After Width: | Height: | Size: 43 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.normal.gif
Executable file
|
After Width: | Height: | Size: 43 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.rightlight.gif
Executable file
|
After Width: | Height: | Size: 61 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.sad.gif
Executable file
|
After Width: | Height: | Size: 42 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.sleepy.gif
Executable file
|
After Width: | Height: | Size: 42 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.surprised.gif
Executable file
|
After Width: | Height: | Size: 44 KiB |
BIN
09-29/eigenfaces/yalefaces/subject02.wink.gif
Executable file
|
After Width: | Height: | Size: 42 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.centerlight.gif
Executable file
|
After Width: | Height: | Size: 26 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.glasses.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.happy.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.leftlight.gif
Executable file
|
After Width: | Height: | Size: 34 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.noglasses.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.normal.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.rightlight.gif
Executable file
|
After Width: | Height: | Size: 57 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.sad.gif
Executable file
|
After Width: | Height: | Size: 28 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.sleepy.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.surprised.gif
Executable file
|
After Width: | Height: | Size: 28 KiB |
BIN
09-29/eigenfaces/yalefaces/subject03.wink.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.centerlight.gif
Executable file
|
After Width: | Height: | Size: 28 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.glasses.gif
Executable file
|
After Width: | Height: | Size: 38 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.happy.gif
Executable file
|
After Width: | Height: | Size: 37 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.leftlight.gif
Executable file
|
After Width: | Height: | Size: 40 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.noglasses.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.normal.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.rightlight.gif
Executable file
|
After Width: | Height: | Size: 66 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.sad.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.sleepy.gif
Executable file
|
After Width: | Height: | Size: 37 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.surprised.gif
Executable file
|
After Width: | Height: | Size: 37 KiB |
BIN
09-29/eigenfaces/yalefaces/subject04.wink.gif
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.centerlight.gif
Executable file
|
After Width: | Height: | Size: 30 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.glasses.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.happy.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.leftlight.gif
Executable file
|
After Width: | Height: | Size: 39 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.noglasses.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.normal.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.rightlight.gif
Executable file
|
After Width: | Height: | Size: 68 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.sad.gif
Executable file
|
After Width: | Height: | Size: 34 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.sleepy.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.surprised.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject05.wink.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.centerlight.gif
Executable file
|
After Width: | Height: | Size: 35 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.glasses.gif
Executable file
|
After Width: | Height: | Size: 47 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.happy.gif
Executable file
|
After Width: | Height: | Size: 51 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.leftlight.gif
Executable file
|
After Width: | Height: | Size: 46 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.noglasses.gif
Executable file
|
After Width: | Height: | Size: 51 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.normal.gif
Executable file
|
After Width: | Height: | Size: 51 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.rightlight.gif
Executable file
|
After Width: | Height: | Size: 38 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.sad.gif
Executable file
|
After Width: | Height: | Size: 50 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.sleepy.gif
Executable file
|
After Width: | Height: | Size: 48 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.surprised.gif
Executable file
|
After Width: | Height: | Size: 47 KiB |
BIN
09-29/eigenfaces/yalefaces/subject06.wink.gif
Executable file
|
After Width: | Height: | Size: 48 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.centerlight.gif
Executable file
|
After Width: | Height: | Size: 28 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.glasses.gif
Executable file
|
After Width: | Height: | Size: 28 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.happy.gif
Executable file
|
After Width: | Height: | Size: 28 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.leftlight.gif
Executable file
|
After Width: | Height: | Size: 37 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.noglasses.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.normal.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.rightlight.gif
Executable file
|
After Width: | Height: | Size: 46 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.sad.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.sleepy.gif
Executable file
|
After Width: | Height: | Size: 27 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.surprised.gif
Executable file
|
After Width: | Height: | Size: 26 KiB |
BIN
09-29/eigenfaces/yalefaces/subject07.wink.gif
Executable file
|
After Width: | Height: | Size: 26 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.centerlight.gif
Executable file
|
After Width: | Height: | Size: 29 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.glasses.gif
Executable file
|
After Width: | Height: | Size: 29 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.happy.gif
Executable file
|
After Width: | Height: | Size: 38 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.leftlight.gif
Executable file
|
After Width: | Height: | Size: 43 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.noglasses.gif
Executable file
|
After Width: | Height: | Size: 37 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.normal.gif
Executable file
|
After Width: | Height: | Size: 29 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.rightlight.gif
Executable file
|
After Width: | Height: | Size: 66 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.sad.gif
Executable file
|
After Width: | Height: | Size: 39 KiB |
BIN
09-29/eigenfaces/yalefaces/subject08.sleepy.gif
Executable file
|
After Width: | Height: | Size: 37 KiB |