Lesson 3/11 and moved eigenfaces folder from 29/9 lesson folder

This commit is contained in:
elvis
2023-11-05 21:28:07 +01:00
parent 17928b1f32
commit 33d89b6bba
183 changed files with 400609 additions and 0 deletions

Binary file not shown.

View File

@ -1,38 +0,0 @@
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

View File

@ -1,18 +0,0 @@
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

View File

@ -1,29 +0,0 @@
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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

View File

@ -1,34 +0,0 @@
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;

View File

@ -1,13 +0,0 @@
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')

View File

@ -1,7 +0,0 @@
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;

View File

@ -1,29 +0,0 @@
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).

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

Some files were not shown because too many files have changed in this diff Show More