-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewFace.m
More file actions
53 lines (43 loc) · 1.46 KB
/
newFace.m
File metadata and controls
53 lines (43 loc) · 1.46 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
%% Using our faces now
% Make sure you have run the file "eigenfaces_svd.m"
% before running this file
%Set the number of eigenfaces to use for the reconstruction (100)
n_eigen = 150;
% mean image vector from the database
M = mean(x,1)';
F=fea';
%initializing to store variables in forloop
G = zeros(1024, 2414);
% solving Image vector - mean image vector
for j=1:n
IV= (F(:,j)- M); %get the jth vector and subtract the mean
G(:,j)=IV; %store the centered vector as the jth vector of G
end
%forming the weight vector for the database
Wd = RIGHT(:,1:n_eigen)'*G;
%getting my face
myFace = imread('Kristenblack.jpg');
myFace = rgb2gray(myFace); % convert to grayscale
myFace = double(myFace);
%resizing the image
myFace = imresize(myFace, [32 32]);
%centering the image
myFace=bsxfun(@minus, myFace, mean(myFace,2));
Rtest = reshape(myFace, [h*w,1]);
Wt = RIGHT(:,1:n_eigen)' *(Rtest-M);
% now we wish to find the euclidean distance between Wd and Wt
distance = zeros(2414,1);
for j = 1:n
distance(j) = norm(Wt-Wd(:,j));
end
% Find the closest face based on the minimum distance
closestFace = find(distance == min(distance));
disp("The distance between yours and the closest face is:")
disp(closestFace)
disp("The index number of the closest face is:")
disp(gnd(closestFace))
% Display the face that was selected as the closest
figure()
colormap default
imagesc(reshape(fea(closestFace,:), [h,w]))
%%