-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathImageUtility.h
More file actions
369 lines (330 loc) · 11 KB
/
Copy pathImageUtility.h
File metadata and controls
369 lines (330 loc) · 11 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
/*********************************************************//**
** @file ImageUtility.h
** Utility functions to process an image.
**
** @date 12/2010
** @author Yooyoung Lee
**
** Note: Please send BUG reports to yooyoung@<NOSPAM>nist.gov.
** For more information, refer to: http://www.nist.gov/itl/iad/ig/vasir.cfm
**
** @par Disclaimer
** This software was developed at the National Institute of Standards
** and Technology (NIST) by employees of the Federal Government in the
** course of their official duties. Pursuant to Title 17 Section 105
** of the United States Code, this software is not subject to copyright
** protection and is in the public domain. NIST assumes no responsibility
** whatsoever for use by other parties of its source code or open source
** server, and makes no guarantees, expressed or implied, about its quality,
** reliability, or any other characteristic.
/*********************************************************//**
** @file ImageUtility.h
** Utility functions to process an image.
**
** @date 12/2010
** @author Yooyoung Lee
**
** Note: Please send BUG reports to yooyoung@<NOSPAM>nist.gov.
** For more information, refer to: http://www.nist.gov/itl/iad/ig/vasir.cfm
**
** @par Disclaimer
** This software was developed at the National Institute of Standards
** and Technology (NIST) by employees of the Federal Government in the
** course of their official duties. Pursuant to Title 17 Section 105
** of the United States Code, this software is not subject to copyright
** protection and is in the public domain. NIST assumes no responsibility
** whatsoever for use by other parties of its source code or open source
** server, and makes no guarantees, expressed or implied, about its quality,
** reliability, or any other characteristic.
**************************************************************/
#ifndef IMAGE_UTILITY_H
#define IMAGE_UTILITY_H
//#undef max
#include "Masek.h"
#include <opencv2/core/core.hpp>
#include <opencv2/legacy/compat.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include <time.h>
#include <iostream>
using namespace std;
/** Valid data types. */
#define NIR_IRIS_STILL 88 /// Classical still: Near-infrared iris still image.
#define NIR_FACE_VIDEO 99 /// Distant video: Near-infrared face video image.
#define ICE2005_IRIS_LG2200 01// (CODE: ICE)
#define MBGC_IRIS_LG2200 02// (CODE: MIL)
#define MBGC_FACE_IOM 03// (CODE: MFI)
#define ND_IRIS20_LG4000 04// (CODE: N20)
#define ND_IRIS48_LGICAM 05// (CODE: N48)
#define ND_IRIS49_IRISGUARD 06// (CODE: N49)
#define ND_IRIS59_CFAIRS 07// (CODE: N59)
/** Number of gray levels. */
#define GRAY_LEVEL 256
/**
* Image processing utility class.
*/
class ImageUtility
{
public:
/**
* Region of Interest and center points information
*/
typedef struct
{
CvRect rect; ///< ROI.
CvPoint p; ///< Center point.
} SETVALUE;
ImageUtility();
virtual ~ImageUtility();
/**
* Set an ROI of an image as IplImage.
*
* @param img Input image.
* @param x X starting point
* @param y X end point
* @param wd Width
* @param ht Height
* @return Returns IplImage type image of ROI
*/
static IplImage* setROIImage(IplImage* img, int x, int y, int wd, int ht);
/**
* Set an ROI of an image as IMAGE.
*
* @param image Input image.
* @param x X starting point
* @param y X end point
* @param wd Width
* @param ht Height
* @return Returns IMAGE type image of ROI
*/
static Masek::IMAGE * setROIImage_C(Masek::IMAGE *image, int x, int y, int wd, int ht);
/**
* Calculate the mean of an image.
*
* @param img Input image
* @param n Total number of pixels
* @return Mean value
*/
static float myMean(IplImage* img, double n);
/**
* Calculate the standard deviation of an image.
*
* @param img Input image
* @param n Total number of pixels
* @param mean Previously calculated mean value
* @return Standard deviation value
* @see myMean
*/
static float mySD(IplImage* img, double n, float mean);
/**
* Displays an image and waits for a keypress.
*
* @note Uses OpenCV to display the image
*
* @param name Window name (= caption)
* @param img Input image
*/
static void showImage(const char* name, IplImage* img);
/**
* Displays an image overlaid with circles and ellipses.
*
* @note The image is modified in the process!
*
* @param name Window name (= caption)
* @param img Input image
* @param eyeFileName If you would like to save the image, specify a filename
* @param xyPupil Pupil's center point
* @param rPupil Pupil's radius
* @param xyIris Iris' center point
* @param rIris Iris' radius
* @param ellipseVal (OUT) Used to return the ellipse info
* @param angleVal (OUT) Used to return the orientation
*/
static void showCircles(const char* name, IplImage* img, const char* eyeFileName,
CvPoint xyPupil, int rPupil, CvPoint xyIris, int rIris,
int* ellipseVal, double* angleVal);
/**
* Display an image overlaid with a cross.
*
* @param eyeImg Input image
* @param centerx Center X
* @param centery Center Y
* @param xCrossLength Cross' length of X
* @param yCrossLength Cross' length of Y
* @param color Cross' color
*/
static void drawCross(IplImage* eyeImg, int centerx, int centery,
int xCrossLength, int yCrossLength, CvScalar color);
/**
* Convert a color image to a gray-scale image.
*
* @note The returned image needs to be deallocated
*
* @param img Input image
* @return Created gray-scale image
*/
static IplImage* convertToGray(IplImage* img);
/**
* Convert an IplImage to an IMAGE.
*
* @note The returned image needs to be deallocated
*
* @param iplImg Input IPL type image
* @return IMAGE type image
* @see convertImageToIpl
*/
static Masek::IMAGE* convertIplToImage(IplImage* iplImg);
//static IplImage* convertFilterToIpl(Masek::filter* image);
/**
* Convert an IMAGE to an IplImage
*
* @note The returned image needs to be deallocated
*
* @param image Input IMAGE type image
* @return IPL type image
* @see convertIplToImage
*/
static IplImage* convertImageToIpl(Masek::IMAGE* image);
/**
* Save an IplImage as BMP file.
*
* Resulting filename: "<fileName>_<ch>.bmp"
*
* @param img Input image
* @param fileName Filename of the input image
* @param ch Append the following prefix to the output filename
* @param format Image file format
* @return Name of the created file
* @see SaveImageOptions
*/
static char* SaveEyeImages(IplImage* img, char* fileName,
const char* ch, const char* format);
/**
* Save an IplImage along with the position and sequence info encoded in
* the output filename.
*
* Resulting filename: "<fileName>_F<frame>_<str><num>"
*
* @param img Input image
* @param fileName Filename of the input image
* @param frame Frame sequence
* @param str "L" (left) or "R" (right) position
* @param num Detected eye image sequence
* @param totalFrame Total number of frames
* @see SaveEyeImages
*/
static void SaveImageOptions(IplImage* img, char* fileName, int frame, const char* str, int num, int totalFrame);
/**
* Extract a rectangular part out of an image.
*
* @note The returned image needs to be deallocated
*
* @param img Input image.
* @param rect Rectangle info
* @param x Starting x
* @param y Starting y
* @param wd Width
* @param ht Height
* @return Extracted image.
*/
static IplImage* extractImagePart(IplImage* img, CvRect& rect, int x, int y, int wd, int ht);
/**
* Return the ROI of an image as IplImage.
*
* @param eyeImg Input image.
* @param startX X starting point
* @param endX X end point
* @param startY Y starting point
* @param endY X end point
* @return Returns IPL image of ROI
*
* @see getROIImage_C
*/
static IplImage* getROIImage(IplImage* eyeImg, int startX, int endX, int startY, int endY);
/**
* Returns an ROI of an image as IMAGE.
*
* @param eyeImg Input image.
* @param startX X starting point
* @param endX X end point
* @param startY Y starting point
* @param endY Y end point
* @return Returns IMAGE type image of ROI
*
* @see getROIImage
*/
static Masek::IMAGE* getROIImage_C(Masek::IMAGE* eyeImg, int startX, int endX, int startY, int endY);
/**
* Calculates the rectangular info and center point.
*
* @param eyeImg Input image.
* @param center Input center point Rectangle info
* @param cr Input radius
* @param xLimit Max. distance of X from the center
* @param yLimit Max. distance of Y from the center
* @return Rect info and center point
*
* See also SETVALUE
*/
static SETVALUE setImage(IplImage* eyeImg, CvPoint center, int cr, int xLimit, int yLimit);
/**
* Calculate the square rectangular info.
*
* @param img Input image.
* @param x Input x
* @param y Input y
* @param radius Input radius
* @param destVal (OUT) Used to return the rect info (0:left, 1:right, 2:bottom, 3:top)
*/
static void myRect(IplImage* img, int x, int y, int radius, int* destVal);
/**
* Calculates the rectangular info with different X and Y radius.
*
* @param img Input IPL image.
* @param x Input x
* @param y Input y
* @param width Input X radius
* @param height Input Y radius
* @param destVal (OUT) Used to return the rect info (0:left, 1:right, 2:bottom, 3:top)
*/
static void myXYRect(IplImage* img, int x, int y, int width, int height, int* destVal);
/**
* Calculates the rectangular info with different X and Y radius.
*
* @param image Input IMAGE image.
* @param x Input x
* @param y Input y
* @param width Input X radius
* @param height Input Y radius
* @param destVal (OUT) Used to return the rect info (0:left, 1:right, 2:bottom, 3:top)
*/
static void myXYRect_C(Masek::IMAGE *image, int x, int y, int width, int height, int* destVal);
/**
* Calculate the square rectangular info of an IMAGE type image.
*
* @param lidImg Input image.
* @param x Input x
* @param y Input y
* @param radius Input radius
* @param destVal (OUT) Used to return the rect info (0:left, 1:right, 2:bottom, 3:top)
*/
static void myRect_C(Masek::IMAGE *lidImg, int x, int y, int radius, int* destVal);
/**
* Debug values.
*
* @param value Actual value.
* @param maxSize Max width or height
* @return Proper value
*/
static int getValue(int value, int maxSize);
/**
* Time elapsed.
*
* @param clock1 Ending time
* @param clock2 Begining time
* @return Difference in ms
*/
static double diffclock(clock_t clock1, clock_t clock2);
};
#endif // !IMAGE_UTILITY_H