-
Notifications
You must be signed in to change notification settings - Fork 7
/
rubberSheetNormalisation.m
129 lines (114 loc) · 4.84 KB
/
rubberSheetNormalisation.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
function image = rubberSheetNormalisation( img, xPosPupil, yPosPupil, rPupil , xPosIris , yPosIris , rIris , varargin )
%rubberSheetNormalisation, function that normalizes the iris region. This is
%the region between the pupil boundary and the limbus. This is done
%according to the rubber sheet model proposed by Daugman (1).
%
% SYNOPSIS
% - image = rubberSheetNormalisation( img, xPosPupil, yPosPupil, rPupil , xPosIris , yPosIris , rIris )
% - image = rubberSheetNormalisation( img, xPosPupil, yPosPupil, rPupil , xPosIris , yPosIris , rIris , 'DebugMode' , 1 )
%
% INPUTS
% - img <double>
% Eye image from the cassini, preferably a NIR image. If no image
% is supplied, a pop up will ask to select one.
% - xPosPupil <integer>, yPosPupil <integer>, rPupil <integer>
% The x,y-position of the pupil center and the pupil radius
% - xPosIris <integer>, yPosIris <integer>, rIris <integer>
% The x,y-position of the iris center and the iris radius
% - varargin <optional>, input scheme
% 'DebugMode': {0: off, 1: on} - if set to 1 shows extra info
% 'AngleSamples': <integer> - number of radial samples
% 'RadiusSamples': <integer> - number of radius samples
% 'UseInterpolation': <boolean> - if 1, the samples will be
% interpolated else nearest neighbor interpolation is used.
%
% OUTPUT
% - image, containing the normalized iris region
%
% DEPENDANCIES
% - Communications Toolbox
% - Computer Vision System Toolbox (for debugmode)
%
% HISTORY
% - 26th may 2017: removed Communications Toolbox
% - 19th June 2016: added the interpolation option
%
% REFERENCES
% (1) How iris recognition works, Daugman, J.G.
%
% AUTHOR
% F.C. Martin <frank@grafikus.nl>
% 19th of May 2015 - 26th may 2017
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%todo: remove for-loop for line detection
if(size(img, 3) == 3) % if RGB image is inputted
img = rgb2gray(img);
end
% parse input
p = inputParser();
addRequired( p , 'xPosPupil' , @isnumeric );
addRequired( p , 'yPosPupil' , @isnumeric );
addRequired( p , 'rPupil' , @isnumeric );
addRequired( p , 'xPosIris' , @isnumeric );
addRequired( p , 'yPosIris' , @isnumeric );
addRequired( p , 'rIris' , @isnumeric );
addOptional( p , 'AngleSamples', 360 ,@isnumeric );
addOptional( p , 'RadiusSamples', 360 ,@isnumeric );
addOptional( p , 'DebugMode', 0, @isnumeric );
addOptional( p , 'UseInterpolation', 1, @isnumeric );
parse( p , xPosPupil, yPosPupil, rPupil , xPosIris , yPosIris , rIris , varargin{:} )
% Note that internally matrix coordinates are used
xp = p.Results.yPosPupil;
yp = p.Results.xPosPupil;
rp = p.Results.rPupil;
xi = p.Results.yPosIris;
yi = p.Results.xPosIris;
ri = p.Results.rIris;
angleSamples = p.Results.AngleSamples;
RadiusSamples = p.Results.RadiusSamples;
debug = p.Results.DebugMode;
interpolateQ = p.Results.UseInterpolation;
% Initialize samples
angles = (0:pi/angleSamples:pi-pi/angleSamples) + pi/(2*angleSamples);%avoiding infinite slope
r = 0:1/RadiusSamples:1;
nAngles = length(angles);
% Calculate pupil points and iris points that are on the same line
x1 = ones(size(angles))*xi;
y1 = ones(size(angles))*yi;
x2 = xi + 10*sin(angles);
y2 = yi + 10*cos(angles);
dx = x2 - x1;
dy = y2 - y1;
slope = dy./dx;
intercept = yi - xi .* slope;
xout = zeros(nAngles,2);
yout = zeros(nAngles,2);
for i = 1:nAngles
[xout(i,:),yout(i,:)] = linecirc(slope(i),intercept(i),xp,yp,rp);
end
% Get samples on limbus boundary
xRightIris = yi + ri * cos(angles);
yRightIris = xi + ri * sin(angles);
xLeftIris = yi - ri * cos(angles);
yLeftIris = xi - ri * sin(angles);
% Get samples in radius direction
xrt = (1-r)' * xout(:,1)' + r' * yRightIris;
yrt = (1-r)' * yout(:,1)' + r' * xRightIris;
xlt = (1-r)' * xout(:,2)' + r' * yLeftIris;
ylt = (1-r)' * yout(:,2)' + r' * xLeftIris;
% Create Normalized Iris Image
if interpolateQ
image = uint8(reshape(interp2(double(img),[yrt(:);ylt(:)],[xrt(:);xlt(:)]),length(r), 2*length(angles))');
else
image = reshape(img(sub2ind(size(img),round([xrt(:);xlt(:)]),round([yrt(:);ylt(:)]))),length(r), 2*length(angles));
end
% Show all points on original input image
if debug
img = insertShape(img, 'circle', [yrt(:),xrt(:),2*ones(size(xrt(:)))],'Color','r');
img = insertShape(img, 'circle', [ylt(:),xlt(:),2*ones(size(xrt(:)))],'Color','r');
figure('name','Sample scheme of the rubber sheet normalization');
imshow(img);
drawnow;
end
end