-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathsegmentiris.m
146 lines (109 loc) · 3.05 KB
/
segmentiris.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
% segmentiris - peforms automatic segmentation of the iris region
% from an eye image. Also isolates noise areas such as occluding
% eyelids and eyelashes.
%
% Usage:
% [circleiris, circlepupil, imagewithnoise] = segmentiris(image)
%
% Arguments:
% eyeimage - the input eye image
%
% Output:
% circleiris - centre coordinates and radius
% of the detected iris boundary
% circlepupil - centre coordinates and radius
% of the detected pupil boundary
% imagewithnoise - original eye image, but with
% location of noise marked with
% NaN values
%
% Author:
% Libor Masek
% School of Computer Science & Software Engineering
% The University of Western Australia
% November 2003
function [circleiris, circlepupil, imagewithnoise] = segmentiris(eyeimage)
% define range of pupil & iris radii
%CASIA
lpupilradius = 28;
upupilradius = 75;
lirisradius = 80;
uirisradius = 150;
% %LIONS
% lpupilradius = 32;
% upupilradius = 85;
% lirisradius = 145;
% uirisradius = 169;
% define scaling factor to speed up Hough transform
scaling = 0.4;
reflecthres = 240;
% find the iris boundary
[row, col, r] = findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.20, 0.19, 1.00, 0.00);
circleiris = [row col r];
rowd = double(row);
cold = double(col);
rd = double(r);
irl = round(rowd-rd);
iru = round(rowd+rd);
icl = round(cold-rd);
icu = round(cold+rd);
imgsize = size(eyeimage);
if irl < 1
irl = 1;
end
if icl < 1
icl = 1;
end
if iru > imgsize(1)
iru = imgsize(1);
end
if icu > imgsize(2)
icu = imgsize(2);
end
% to find the inner pupil, use just the region within the previously
% detected iris boundary
imagepupil = eyeimage( irl:iru,icl:icu);
%find pupil boundary
[rowp, colp, r] = findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.25,0.25,1.00,1.00);
rowp = double(rowp);
colp = double(colp);
r = double(r);
row = double(irl) + rowp;
col = double(icl) + colp;
row = round(row);
col = round(col);
circlepupil = [row col r];
% set up array for recording noise regions
% noise pixels will have NaN values
imagewithnoise = double(eyeimage);
%find top eyelid
topeyelid = imagepupil(1:(rowp-r),:);
lines = findline(topeyelid);
if size(lines,1) > 0
[xl yl] = linecoords(lines, size(topeyelid));
yl = double(yl) + irl-1;
xl = double(xl) + icl-1;
yla = max(yl);
y2 = 1:yla;
ind3 = sub2ind(size(eyeimage),yl,xl);
imagewithnoise(ind3) = NaN;
imagewithnoise(y2, xl) = NaN;
end
%find bottom eyelid
bottomeyelid = imagepupil((rowp+r):size(imagepupil,1),:);
lines = findline(bottomeyelid);
if size(lines,1) > 0
[xl yl] = linecoords(lines, size(bottomeyelid));
yl = double(yl)+ irl+rowp+r-2;
xl = double(xl) + icl-1;
yla = min(yl);
y2 = yla:size(eyeimage,1);
ind4 = sub2ind(size(eyeimage),yl,xl);
imagewithnoise(ind4) = NaN;
imagewithnoise(y2, xl) = NaN;
end
%For CASIA, eliminate eyelashes by thresholding
ref = eyeimage < 100;
coords = find(ref==1);
imagewithnoise(coords) = NaN;