-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtnm034.m
55 lines (41 loc) · 1.48 KB
/
tnm034.m
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
function id = tnm034(im)
load('data/FisherFaces.mat', 'F');
load('data/ClassWeight.mat', 'Class_weight');
% Read the input image
face = double(im);
face = face / max(face(:));
% Perform gray world assumption for color correction
facegw = grayWorld(face);
% Perform face segmentation to isolate the face region
[faceSeg, topBoundary, lowerBoundary] = FaceSegmentation(facegw);
% Calculate the threshold for eye detection
threshold = lowerBoundary - (0.8 * (lowerBoundary - topBoundary));
% Generate eye map
[eyeImg, ~, il, co] = eyeMap(face, faceSeg);
% Generate mouth map for mouth detection
mouthImg = mouthMap(face, faceSeg);
% Get the positions of the eyes
eyePos = getEyes(eyeImg, mouthImg, threshold, il, co);
if(eyePos == -1)
disp('Could not detect eyes, quitting program')
id = -1;
return;
end
% Determine the positions of the left and right eyes
if (eyePos(1, 1) < eyePos(2, 1))
leftEye = eyePos(1, :);
rightEye = eyePos(2, :);
else
leftEye = eyePos(2, :);
rightEye = eyePos(1, :);
end
% Crop the image
img = CropImages(face, leftEye, rightEye);
% Convert the cropped image to grayscale and flatten it to a vector
img = rgb2gray(img);
img = img(:);
% Calculate weights
Wimg = calculateWeights(img, F);
% Get the closest face identity using calculated weights
id = getClosestFace(Wimg, Class_weight);
end