-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheyeDetect.m
More file actions
77 lines (61 loc) · 2.17 KB
/
Copy patheyeDetect.m
File metadata and controls
77 lines (61 loc) · 2.17 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function [P1,P2] = eyeDetect(eyeMapImage, faceMaskIm, Image)
%EYEDETECT From an eye map, this function detects the eyes and calculate
%the distance between them
%% Make a mask from eyeMap and faceMask.
Mask = combinedMask(eyeMapImage, faceMaskIm);
%% Find eyes
[NumOfPoints, Points] = blobData(Mask);
% Find circles inside masked area in the image
resultMask = Mask .* im2double(rgb2gray(Image));
[centers,radii] = imfindcircles(resultMask,[6 17],'ObjectPolarity','dark', ...
'Sensitivity',0.93);
%% Selection of which points to choose
if(NumOfPoints < 2) % Not enough areas inside the mask
P1 = -1;
P2 = -1;
else
if(size(radii) < 2) % Can't find circles in original image
P1 = [Points(1,2) Points(1,1)];
P2 = [Points(2,2) Points(2,1)];
else %Find the closest circles to the blobs position
Blob1 = [Points(1,2) Points(1,1)];
Blob2 = [Points(2,2) Points(2,1)];
Blob1array = repmat(Blob1, [ size(radii), 1]);
Blob2array = repmat(Blob2, [ size(radii), 1]);
dist1 = abs(Blob1array-centers);
dist2 = abs(Blob2array-centers);
Min1 = dist1(1,:);
index1 = 1;
Min2 = dist2(1,:);
index2 = 1;
for i = 1:size(radii)
if( (Min1(1) * Min1(1)) + (Min1(2) * Min1(2)) > (dist1(i,1) * dist1(i,1)) + (dist1(i,2) * dist1(i,2)) )
Min1 = dist1(i,:);
index1 = i;
end
if( (Min2(1) * Min2(1)) + (Min2(2) * Min2(2)) > (dist2(i,1) * dist2(i,1)) + (dist2(i,2) * dist2(i,2)) )
Min2 = dist2(i,:);
index2 = i;
end
end
% If a circle is close to a blobs min point, the circle is selected
% as eye point
MaxDist = 10;
if( sqrt((Min1(1) * Min1(1)) + (Min1(2) * Min1(2))) < MaxDist )
P1 = centers(index1,:);
else
P1 = Blob1;
end
if( sqrt((Min2(1) * Min2(1)) + (Min2(2) * Min2(2))) < MaxDist )
P2 = centers(index2,:);
else
P2 = Blob2;
end
end
end
% Make sure P1 is left to P2.
if(P1(1) > P2(1) )
temp = P1;
P1 = P2;
P2 = temp;
end