forked from aldebaro/ufpa-reconhecimento-face
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patheigenfaces_example.m
More file actions
56 lines (48 loc) · 1.82 KB
/
eigenfaces_example.m
File metadata and controls
56 lines (48 loc) · 1.82 KB
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
% Copyright (c) Philipp Wagner. All rights reserved.
% Licensed under the BSD license. See LICENSE file in the project root for full license information.
% load function files from subfolders aswell
addpath (genpath ('.'));
% load data
[X y width height names] = urf_readImages('/home/cleversonahum/ufpa-reconhecimento-face/att_faces/');
% Compute the model (full PCA):
eigenface = urf_eigenfaces(X,y);
% Plot the first (atmost) 16 eigenfaces:
figure; hold on;
title('Eigenfaces (AT&T Facedatabase)');
for i=1:min(16, size(eigenface.W,2))
subplot(4,4,i);
comp = urf_cvtCinza(eigenface.W(:,i), width, height);
imshow(comp);
colormap(jet(256)); % Comment this out, if you don't want colored images
title(sprintf('Eigenface #%i', i));
end
%% 2D plot of projection (add the classes you want):
figure; hold on;
for i = urf_acharClasses(eigenface.y, [1,2,3])
text(eigenface.P(1,i), eigenface.P(2,i), num2str(eigenface.y(i)));
end
%% 3D plot of projection (first three classes, add those you want):
if(size((eigenface.P),2) >= 3)
figure; hold on;
for i = urf_acharClasses(eigenface.y, [1,2,3])
% LineSpec: red dots 'r.'
plot3(eigenface.P(1,i), eigenface.P(2,i), eigenface.P(3,i), 'r.'), view(45,-45);
text(eigenface.P(1,i), eigenface.P(2,i), eigenface.P(3,i), num2str(eigenface.y(i)));
end
end
%% Plot eigenfaces reconstruction
steps = 10:20:min(eigenface.num_eigenfaces,320) ;
Q = X (:,1) ; % first image to reconstruct (each image is a column!)
figure;
title ('Reconstruction (AT&T Facedatabase)');
hold on;
for i =1:min(16,length(steps))
subplot (4, 4, i);
numEvs = steps(i);
P = urf_project(Q, eigenface.W(:,1:numEvs), eigenface.media);
R = urf_reconstrucao(eigenface.W(:,1:numEvs), P, eigenface.media);
comp = urf_cvtCinza(R, width, height);
imshow(comp);
title(sprintf('%i Eigenvectors', numEvs));
end
pause;