-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreateTemplate.cpp
More file actions
280 lines (243 loc) · 7.91 KB
/
Copy pathCreateTemplate.cpp
File metadata and controls
280 lines (243 loc) · 7.91 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include "CreateTemplate.h"
#include "Masek.h"
#include "EncodeLee.h"
#include "ImageUtility.h"
#include "FindPupilCircleNew.h"
#include "FindIrisCircle.h"
#include "FindHighLights.h"
#include "FindEyelidCurve.h"
#include "Normalization.h"
// Run left and right eye together for video
void CreateTemplate::newCreateIrisTemplate(const char *fileName,
int **template1, int **mask1,
int *width, int *height,
int dataType)
{
ImageUtility *imgUtil = NULL;
// Load the image as gray scale
IplImage* eyeImg = NULL;
eyeImg = cvLoadImage(fileName,0);
if(eyeImg == NULL)
{
cout << "Failed to load the file" << endl;
return;
}
// Create an image
//IplImage* grayImg = NULL;
//grayImg = cvCloneImage(eyeImg);
IplImage* grayImg = NULL;
grayImg = cvCreateImage(cvSize(eyeImg->width, eyeImg->height), 8, 1);
cvCopyImage(eyeImg, grayImg);
if(grayImg == NULL)
{
cout << "Failed to load the file" << endl;
return;
}
/********************************************************
* Iris Segmentation
*********************************************************/
//PUPIL INPUTS
float nScale = 1.0;
const int speed_m = 1;// Default 1
int alpha = 20; // Alpha value for contrast threshold
// Setup the parameters to avoid that noise caused by reflections and
// eyelashes covers the pupil
double ratio4Circle = 1.0;
// Initialize for Closing and Opening process
int closeItr = 2;//dilate->erode
int openItr = 3;//erode->dilate
double norm = 256.0;
//IRIS INPUTS
double scaling = 0.4;// Default
double lowThres = 0.11;// Default
double highThres = 0.19;// Default
if(dataType == NIR_IRIS_STILL) //classical iris image
{
nScale = 2.0;
alpha = 25;
ratio4Circle = 0.90;
closeItr = 2;
openItr = 3;
scaling = 0.4;
}
else if(dataType == NIR_FACE_VIDEO) // Distant video frame
{
nScale = 1.0;
alpha = 20;
ratio4Circle = 0.65;
closeItr = 0;
openItr = 3;
scaling = 0.45;
}
/*defined
ICE2005_IRIS_LG2200 01 (CODE: ICE)
MBGC_IRIS_LG2200 02 (CODE: MIL)
MBGC_FACE_IOM 03 (CODE: MFI)
ND_IRIS20_LG4000 04 (CODE: N20)
ND_IRIS48_LGICAM 05 (CODE: N48)
ND_IRIS49_IRISGUARD 06 (CODE: N49)
ND_IRIS59_CFAIRS 07 (CODE: N59)*/
if(dataType == ICE2005_IRIS_LG2200) // Classic still images
{
nScale = 2.0;
alpha = 20;
ratio4Circle = 0.92;
closeItr = 2;
openItr = 3;
scaling = 0.25;
}
else if(dataType == MBGC_IRIS_LG2200) //02 (CODE: MIL)
{
nScale = 2.0;
alpha = 30;
ratio4Circle = 0.92;
closeItr = 2;
openItr = 1;
scaling = 0.2;
}
else if(dataType == MBGC_FACE_IOM) // Distant video imagery
{
nScale = 1.0;
alpha = 20;
ratio4Circle = 0.65;
closeItr = 0;
openItr = 3;
scaling = 0.45;
}
else if(dataType == ND_IRIS20_LG4000) //04 (CODE: N20)
{
nScale = 2.0;
alpha = 38;
ratio4Circle = 0.92;
closeItr = 0;
openItr = 4;
scaling = 0.3;
}
else if(dataType == ND_IRIS48_LGICAM) //05 (CODE: N48)
{
nScale = 2.0;
alpha = 40;
ratio4Circle = 0.92;
closeItr = 0;
openItr = 4;
scaling = 0.2;
}
else if(dataType == ND_IRIS49_IRISGUARD) //06 (CODE: N49)
{
nScale = 2.0;
alpha = 18;
ratio4Circle = 0.92;
closeItr = 3;//best for noScaled Still
openItr = 2;//best for noScaled Still
scaling = 0.2;
}
else if(dataType == ND_IRIS59_CFAIRS) //07 (CODE: N59)
{
nScale = 2.0;
alpha = 4;
ratio4Circle = 0.92;
closeItr = 0;//best for noScaled Still
openItr = 3;//best for noScaled Still
scaling = 0.4;
}
const int rPupilMax = (int) (42*nScale);// Maximum radius of pupil's circle
const int rIrisMax = (int) (82*nScale);// Maximum radius of iris' circle
//fine the pupil circle using contours
int pupilCircle[6]={0};
FindPupilCircleNew::doDetect(grayImg, rPupilMax, ratio4Circle, closeItr, openItr, speed_m, alpha, norm, nScale, pupilCircle);
CvPoint xyPupil;
xyPupil.x = pupilCircle[0];
xyPupil.y = pupilCircle[1];
int rPupil = pupilCircle[2];
//ROI for detecting the iris circle
ImageUtility::SETVALUE setVal = imgUtil->setImage(grayImg, xyPupil, rPupil, rIrisMax, rIrisMax); //82 is the best for video images, previous 80
IplImage* setImg = NULL;
setImg = imgUtil->getROIImage(grayImg, setVal.rect.x, setVal.rect.width, setVal.rect.y, setVal.rect.height);
if(setImg == NULL)
{
cout << "Failed to load the file" << endl;
return;
}
int centerAdjust=(int)(rIrisMax/4);//(rIrisMax/5); //for video dataset
//find the iris circle using Hough Transform
int irisCircle[3]={0};
FindIrisCircle::doDetect(setImg, rPupil, rIrisMax, scaling, lowThres, highThres, irisCircle);
CvPoint xyIris;
xyIris.x = irisCircle[0];
xyIris.y = irisCircle[1];
int rIris = irisCircle[2];
xyIris = FindIrisCircle::getOriginPoints(xyPupil, xyIris, setVal.p, centerAdjust);
cvReleaseImage(&setImg);
//find the upper and lower eyelids
double x[3]={0}, ty[3]={0}, by[3]={0};
FindEyelidCurve *eyelid = NULL;
Masek::IMAGE* noiseImage = imgUtil->convertIplToImage(eyeImg);
eyelid->findCurves(grayImg, xyPupil.x, xyPupil.y, rPupil,
xyIris.x, xyIris.y, rIris,
x, ty, by);
int size =(int)(x[2]-x[0]+1);
int *destTY = new int[size];
int *destBY = new int[size];
eyelid->calcCurvePoints(grayImg, x, ty, destTY);
eyelid->calcCurvePoints(grayImg, x, by, destBY);
//error at this function
eyelid->maskOutNoise(noiseImage, x, destTY, destBY);
delete[] destTY;
delete[] destBY;
delete eyelid;
/// \todo Possible to optimize?
//Find the eyelashes and reflections on the iris region
const int min=3, max=250;
//FindHighLights::removeHighLights2(noiseImage, min, max);//5, 230
FindHighLights::removeHighLights2(noiseImage,min, max);
cvReleaseImage(&grayImg);
cvReleaseImage(&eyeImg);
/********************************************************
* Iris Normalization
*********************************************************/
/// \todo Possible to optimize?
//size of the normalized image
//Evaluation: April 11 2012 (better)
int radialRes = 34;//orginal value: 20
int angularRes = 260;//orignal value: 240
Masek::filter polarArray;
Masek::IMAGE noiseArray;
Masek::filter* imgWithNoise;
imgWithNoise = (Masek::filter*) malloc(sizeof(Masek::filter));
imgWithNoise->hsize[0] = noiseImage->hsize[0];
imgWithNoise->hsize[1] = noiseImage->hsize[1];
imgWithNoise->data = (double*) malloc(sizeof(double)*noiseImage->hsize[0]*noiseImage->hsize[1]);
for (int y = 0; y < noiseImage->hsize[0]; y++)
{
for (int x = 0; x < noiseImage->hsize[1]; x++)
{
if(noiseImage->data[x + y*noiseImage->hsize[1]] < 1)
imgWithNoise->data[x + y*imgWithNoise->hsize[1]] = sqrt((double) -1);
else
imgWithNoise->data[x + y*imgWithNoise->hsize[1]] = (double)noiseImage->data[x + y*noiseImage->hsize[1]];
}
}
free(noiseImage->data);
free(noiseImage);
Normalization::normalizeiris(imgWithNoise, xyIris.x, xyIris.y, rIris,
xyPupil.x, xyPupil.y, rPupil, (const int)radialRes, (const int)angularRes,
&polarArray, &noiseArray);
free(imgWithNoise->data);
free(imgWithNoise);
/********************************************************
/* Iris Encoding
*********************************************************/
const int encodeScales = 1;
const int mult = 1; //not applicable if using encodeScales = 1
int minWaveLength = 18;
double sigmaOnf = 0.55;//0.5
//float coefThresRate = 0.0f;// for FX: 0.25 and 0.10
float magLowerThresRate = 0.02f;
float magUpperThresRate = 0.85f;
EncodeLee::newEncodeLee(&polarArray, &noiseArray, encodeScales, (const int)minWaveLength,
mult, (const double)sigmaOnf, template1, mask1, width, height,
magLowerThresRate, magUpperThresRate);
free(polarArray.data);
free(noiseArray.data);
delete imgUtil;
}