-
Notifications
You must be signed in to change notification settings - Fork 0
/
eyeright_corner.m
129 lines (127 loc) · 3.32 KB
/
eyeright_corner.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
%% Ham tim ra vi tri goc trai va goc phai cua con mat phai.
% Dau vao :
% Imag : Anh dau vao.
% Dau ra :
% eR_cL : Toa do goc trai cua mat phai.
% eR_cR : Toa do goc phao cua mat phai.
% o_eye : Duong tron bao quanh con nguoi.
% C1 : Toa do hang cua tam con nguoi
% C2 : Toa do cot cua tam con nguoi
% C3 : Ban kinh cua con nguoi.
% By : Nguyen Van Linh
% SipLab_K52, Dien tu vien thong, Dai hoc Bach Khoa Ha Noi
function [eR_cL,eR_cR,C1,C2,C3,o_eye]=eyeright_corner(Imag,r)
[C2,C1,C3,o_eye] = out_iris(Imag,r);
[m,n,p] = size(Imag);
% Cat tu tam con nguoi ra hai phia trai, phai
reg_left = Imag(1:m,1:(C2-C3),:);
reg_right = Imag(1:m,(C2+C3):n,:);
reg_left = im2double(reg_left);
reg_right = im2double(reg_right);
% Bat dau lam viec voi phan ben trai
%eye1 = colorgrad(reg_left);
eye1 = rgb2gray(reg_left);
se1 = [1 1 1 -1 -1 -1;1 1 -1 -1 -1 -1;1 -1 -1 -1 -1 -1;1 1 1 1 1 1];
f1 = imfilter(eye1,se1);
[mf1,nf1] = size(f1);
T_max = max(max(abs(f1)));
if(T_max==0)
T_max = 1;
end
scale_T1 = linspace(0.1*T_max,0.04*T_max,4);
for l=1:size(scale_T1,2)
T1 = scale_T1(l);
if ((3*C3)<nf1)
f1(C1,round(nf1-3*C3)) = T1;
elseif (nf1>2*C3)
f1(C1,(nf1-2*C3)) = T1;
end
f1 = f1>=T1;
for i=1:mf1
for j=1:nf1
if(j>(nf1/2))
f1(i,j) = 0;
end
if (j<(nf1-2.5*C3))
f1(i,j) = 0;
end
if ((i<C1)| (i>(C1+C3)))
f1(i,j) = 0;
end
end
end
f1 = imfill(f1,'holes');
[f1 cf1] = maxregion(f1);
%f1 = imfill(f1,'holes');
[X1 Y1] = find(f1);
[y i] = min(Y1(:));
if(max(X1(i))+1<=mf1)
x1 = max(X1(i))+1;
else
x1 = max(X1(i))-1;
end
if(min(Y1(i))+1<nf1)
y1 = min(Y1(i))+1;
else
y1 = min(Y1(i));
end
% Do diem toa do cua anh reg_left giong voi anh goc
eR_cL = [x1,y1];
if (isempty(eR_cL)==0)
break;
end
end
% Bat dau lam viec voi phan ben phaii
eye2 = rgb2gray(reg_right);
se2 = [-1 -1 -1 1 1 1;-1 -1 -1 -1 1 1;-1 -1 -1 -1 -1 1;1 1 1 1 1 1];
f2 = imfilter(eye2,se2);
[mf2,nf2] = size(f2);
T_max = max(max(abs(f2(:))));
if(T_max==0)
T_max = 1;
end
scale_T2 = linspace(0.1*T_max,0.01*T_max,4);
for l=1:size(scale_T2,2)
T2 = scale_T2(l);
if (round(3*C3/2)<nf2)
f2(C1,round(3*C3/2)) = T2;
else
f2(C1,C3) = T2;
end
f2 = f2>=T2;
for i=1:mf2
for j=1:nf2
if (j<=5*C3/3)
f2(i,j) = 0;
end
if (j>=round((2*C3)))
f2(i,j) = 0;
end
if ((i<(C1-(2*C3)/3)| (i>(C1))))
f2(i,j) = 0;
end
end
end
f2 = imfill(f2,'holes');
[f2 cf2] = maxregion(f2);
%f2 = imfill(f2,'holes');
[X2 Y2] = find(f2);
[y i] = max(Y2(:));
x2 = max(X2(i))+1;
y2 = max(Y2(i))-2;
x2_root = x2; y2_root = y2+C2 +C3;
eR_cR = [x2_root,y2_root];
if(isempty(eR_cR)==0)
break;
end
end
if(isempty(eR_cL)==1)
eR_cL = [C1,round(nf1/2)];
end
if(isempty(eR_cR)==1)
if(2*C3/3<round(nf2/3))
eR_cR = [C1,(C2+C3+2*C3/3)];
else
eR_cR = [C1,(C2+C3+round(nf2/3))];
end
end