-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathminutia.c
3558 lines (3209 loc) · 152 KB
/
minutia.c
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
License:
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
its use by other parties, and makes no guarantees, expressed or implied,
about its quality, reliability, or any other characteristic.
Disclaimer:
This software was developed to promote biometric standards and biometric
technology testing for the Federal Government in accordance with the USA
PATRIOT Act and the Enhanced Border Security and Visa Entry Reform Act.
Specific hardware and software products identified in this software were used
in order to perform the software development. In no case does such
identification imply recommendation or endorsement by the National Institute
of Standards and Technology, nor does it imply that the products and equipment
identified are necessarily the best available for the purpose.
*******************************************************************************/
/***********************************************************************
LIBRARY: LFS - NIST Latent Fingerprint System
FILE: MINUTIA.C
AUTHOR: Michael D. Garris
DATE: 05/11/1999
UPDATED: 10/04/1999 Version 2 by MDG
UPDATED: 09/13/2004
Contains routines responsible for detecting initial minutia
points as part of the NIST Latent Fingerprint System (LFS).
***********************************************************************
ROUTINES:
alloc_minutiae()
realloc_minutiae()
detect_minutiae()
detect_minutiae_V2()
update_minutiae()
update_minutiae_V2()
sort_minutiae_y_x()
sort_minutiae_x_y()
rm_dup_minutiae()
dump_minutiae()
dump_minutiae_pts()
dump_reliable_minutiae_pts()
create_minutia()
free_minutiae()
free_minutia()
remove_minutia()
join_minutia()
minutia_type()
is_minutia_appearing()
choose_scan_direction()
scan4minutiae()
scan4minutiae_horizontally()
scan4minutiae_horizontally_V2()
scan4minutiae_vertically()
scan4minutiae_vertically_V2()
rescan4minutiae_horizontally()
rescan4minutiae_vertically()
rescan_partial_horizontally()
rescan_partial_vertically()
get_nbr_block_index()
adjust_horizontal_rescan()
adjust_vertical_rescan()
process_horizontal_scan_minutia()
process_horizontal_scan_minutia_V2()
process_vertical_scan_minutia()
process_vertical_scan_minutia_V2()
adjust_high_curvature_minutia()
adjust_high_curvature_minutia_V2()
get_low_curvature_direction()
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "lfs.h"
/*************************************************************************
**************************************************************************
#cat: alloc_minutiae - Allocates and initializes a minutia list based on the
#cat: specified maximum number of minutiae to be detected.
Input:
max_minutiae - number of minutia to be allocated in list
Output:
ominutiae - points to the allocated minutiae list
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int alloc_minutiae(MINUTIAE **ominutiae, const int max_minutiae)
{
MINUTIAE *minutiae;
minutiae = (MINUTIAE *)malloc(sizeof(MINUTIAE));
if(minutiae == (MINUTIAE *)NULL){
fprintf(stderr, "ERROR : alloc_minutiae : malloc : minutiae\n");
exit(-430);
}
minutiae->list = (MINUTIA **)malloc(max_minutiae * sizeof(MINUTIA *));
if(minutiae->list == (MINUTIA **)NULL){
fprintf(stderr, "ERROR : alloc_minutiae : malloc : minutiae->list\n");
exit(-431);
}
minutiae->alloc = max_minutiae;
minutiae->num = 0;
*ominutiae = minutiae;
return(0);
}
/*************************************************************************
**************************************************************************
#cat: realloc_minutiae - Reallocates a previously allocated minutia list
#cat: extending its allocated length based on the specified
#cat: increment.
Input:
minutiae - previously allocated list of minutiae points
max_minutiae - number of minutia to be allocated in list
Output:
minutiae - extended list of minutiae points
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int realloc_minutiae(MINUTIAE *minutiae, const int incr_minutiae)
{
minutiae->alloc += incr_minutiae;
minutiae->list = (MINUTIA **)realloc(minutiae->list,
minutiae->alloc * sizeof(MINUTIA *));
if(minutiae->list == (MINUTIA **)NULL){
fprintf(stderr, "ERROR : realloc_minutiae : realloc : minutiae->list\n");
exit(-432);
}
return(0);
}
/*************************************************************************
**************************************************************************
#cat: detect_minutiae - Takes a binary image and its associated IMAP and
#cat: NMAP matrices and scans each image block for potential
#cat: minutia points.
Input:
bdata - binary image data (0==while & 1==black)
iw - width (in pixels) of image
ih - height (in pixels) of image
imap - matrix of ridge flow directions
nmap - IMAP augmented with blocks of HIGH-CURVATURE and
blocks which have no neighboring valid directions.
mw - width (in blocks) of IMAP and NMAP matrices.
mh - height (in blocks) of IMAP and NMAP matrices.
lfsparms - parameters and thresholds for controlling LFS
Output:
minutiae - points to a list of detected minutia structures
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int detect_minutiae(MINUTIAE *minutiae,
unsigned char *bdata, const int iw, const int ih,
const int *imap, const int *nmap, const int mw, const int mh,
const LFSPARMS *lfsparms)
{
int blk_i, blk_x, blk_y;
int scan_x, scan_y, scan_w, scan_h;
int scan_dir;
int ret;
/* Start with first block in IMAP. */
blk_i = 0;
/* Start with first scan line in image. */
scan_y = 0;
/* Foreach row of blocks in IMAP... */
for(blk_y = 0; blk_y < mh; blk_y++){
/* Reset to beginning of new block row. */
scan_x = 0;
/* Foreach block in current IMAP row... */
for(blk_x = 0; blk_x < mw; blk_x++){
/* If IMAP is VALID ... */
if(imap[blk_i] != INVALID_DIR){
/* Choose the feature scan direction based on the block's */
/* VALID IMAP direction. The scan direction will either */
/* be HORIZONTAL or VERTICAL. */
scan_dir = choose_scan_direction(imap[blk_i],
lfsparms->num_directions);
/* Set width of scan region. The image may not be an even */
/* multiple of "blocksize" in width and height, so we must */
/* account for this. */
/* Bump right by "blocksize" pixels, but not beyond the */
/* image boundary. */
scan_w = min(scan_x+lfsparms->blocksize, iw);
/* Make the resulting width relative to the region's starting */
/* x-pixel column. */
scan_w -= scan_x;
/* Bump down by "blocksize" pixels, but not beyond the */
/* image boundary. */
scan_h = min(scan_y+lfsparms->blocksize, ih);
/* Make the resulting height relative to the region's starting */
/* y-pixel row. */
scan_h -= scan_y;
/* Scan the defined region for minutia features. */
if((ret = scan4minutiae(minutiae, bdata, iw, ih,
imap, nmap, blk_x, blk_y, mw, mh,
scan_x, scan_y, scan_w, scan_h, scan_dir,
lfsparms))){
/* Return code may be: */
/* 1. ret<0 (implying system error) */
return(ret);
}
} /* Otherwise, IMAP is INVALID, so ignore the block. This seems */
/* quite drastic! */
/* Advance to the next IMAP block in the row in the image. */
scan_x += lfsparms->blocksize;
/* Advance to the next IMAP block in the row. */
blk_i++;
} /* End foreach blk_x */
/* Advance to the next IMAP row in the image. */
scan_y += lfsparms->blocksize;
} /* End foreach blk_y */
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: detect_minutiae_V2 - Takes a binary image and its associated
#cat: Direction and Low Flow Maps and scans each image block
#cat: with valid direction for minutia points. Minutia points
#cat: detected in LOW FLOW blocks are set with lower reliability.
Input:
bdata - binary image data (0==while & 1==black)
iw - width (in pixels) of image
ih - height (in pixels) of image
direction_map - map of image blocks containing directional ridge flow
low_flow_map - map of image blocks flagged as LOW RIDGE FLOW
high_curve_map - map of image blocks flagged as HIGH CURVATURE
mw - width (in blocks) of the maps
mh - height (in blocks) of the maps
lfsparms - parameters and thresholds for controlling LFS
Output:
minutiae - points to a list of detected minutia structures
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int detect_minutiae_V2(MINUTIAE *minutiae,
unsigned char *bdata, const int iw, const int ih,
int *direction_map, int *low_flow_map, int *high_curve_map,
const int mw, const int mh,
const LFSPARMS *lfsparms)
{
int ret;
int *pdirection_map, *plow_flow_map, *phigh_curve_map;
/* Pixelize the maps by assigning block values to individual pixels. */
if((ret = pixelize_map(&pdirection_map, iw, ih, direction_map, mw, mh,
lfsparms->blocksize))){
return(ret);
}
if((ret = pixelize_map(&plow_flow_map, iw, ih, low_flow_map, mw, mh,
lfsparms->blocksize))){
free(pdirection_map);
return(ret);
}
if((ret = pixelize_map(&phigh_curve_map, iw, ih, high_curve_map, mw, mh,
lfsparms->blocksize))){
free(pdirection_map);
free(plow_flow_map);
return(ret);
}
if((ret = scan4minutiae_horizontally_V2(minutiae, bdata, iw, ih,
pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){
free(pdirection_map);
free(plow_flow_map);
free(phigh_curve_map);
return(ret);
}
if((ret = scan4minutiae_vertically_V2(minutiae, bdata, iw, ih,
pdirection_map, plow_flow_map, phigh_curve_map, lfsparms))){
free(pdirection_map);
free(plow_flow_map);
free(phigh_curve_map);
return(ret);
}
/* Deallocate working memories. */
free(pdirection_map);
free(plow_flow_map);
free(phigh_curve_map);
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: update_minutiae - Takes a detected minutia point and (if it is not
#cat: determined to already be in the minutiae list) adds it to
#cat: the list.
Input:
minutia - minutia structure for detected point
bdata - binary image data (0==while & 1==black)
iw - width (in pixels) of image
ih - height (in pixels) of image
lfsparms - parameters and thresholds for controlling LFS
Output:
minutiae - points to a list of detected minutia structures
Return Code:
Zero - minutia added to successfully added to minutiae list
IGNORE - minutia is to be ignored (already in the minutiae list)
Negative - system error
**************************************************************************/
int update_minutiae(MINUTIAE *minutiae, MINUTIA *minutia,
unsigned char *bdata, const int iw, const int ih,
const LFSPARMS *lfsparms)
{
int i, ret, dy, dx, delta_dir;
int qtr_ndirs, full_ndirs;
/* Check to see if minutiae list is full ... if so, then extend */
/* the length of the allocated list of minutia points. */
if(minutiae->num >= minutiae->alloc){
if((ret = realloc_minutiae(minutiae, MAX_MINUTIAE)))
return(ret);
}
/* Otherwise, there is still room for more minutia. */
/* Compute quarter of possible directions in a semi-circle */
/* (ie. 45 degrees). */
qtr_ndirs = lfsparms->num_directions>>2;
/* Compute number of directions in full circle. */
full_ndirs = lfsparms->num_directions<<1;
/* Is the minutiae list empty? */
if(minutiae->num > 0){
/* Foreach minutia stored in the list... */
for(i = 0; i < minutiae->num; i++){
/* If x distance between new minutia and current list minutia */
/* are sufficiently close... */
dx = abs(minutiae->list[i]->x - minutia->x);
if(dx < lfsparms->max_minutia_delta){
/* If y distance between new minutia and current list minutia */
/* are sufficiently close... */
dy = abs(minutiae->list[i]->y - minutia->y);
if(dy < lfsparms->max_minutia_delta){
/* If new minutia and current list minutia are same type... */
if(minutiae->list[i]->type == minutia->type){
/* Test to see if minutiae have similar directions. */
/* Take minimum of computed inner and outer */
/* direction differences. */
delta_dir = abs(minutiae->list[i]->direction -
minutia->direction);
delta_dir = min(delta_dir, full_ndirs-delta_dir);
/* If directional difference is <= 45 degrees... */
if(delta_dir <= qtr_ndirs){
/* If new minutia and current list minutia share */
/* the same point... */
if((dx==0) && (dy==0)){
/* Then the minutiae match, so don't add the new one */
/* to the list. */
return(IGNORE);
}
/* Othewise, check if they share the same contour. */
/* Start by searching "max_minutia_delta" steps */
/* clockwise. */
/* If new minutia point found on contour... */
if(search_contour(minutia->x, minutia->y,
lfsparms->max_minutia_delta,
minutiae->list[i]->x, minutiae->list[i]->y,
minutiae->list[i]->ex, minutiae->list[i]->ey,
SCAN_CLOCKWISE, bdata, iw, ih)){
/* Consider the new minutia to be the same as the */
/* current list minutia, so don't add the new one */
/* to the list. */
return(IGNORE);
}
/* Now search "max_minutia_delta" steps counter- */
/* clockwise along contour. */
/* If new minutia point found on contour... */
if(search_contour(minutia->x, minutia->y,
lfsparms->max_minutia_delta,
minutiae->list[i]->x, minutiae->list[i]->y,
minutiae->list[i]->ex, minutiae->list[i]->ey,
SCAN_COUNTER_CLOCKWISE, bdata, iw, ih)){
/* Consider the new minutia to be the same as the */
/* current list minutia, so don't add the new one */
/* to the list. */
return(IGNORE);
}
/* Otherwise, new minutia and current list minutia do */
/* not share the same contour, so although they are */
/* similar in type and location, treat them as 2 */
/* different minutia. */
} /* Otherwise, directions are too different. */
} /* Otherwise, minutiae are different type. */
} /* Otherwise, minutiae too far apart in Y. */
} /* Otherwise, minutiae too far apart in X. */
} /* End FOR minutia in list. */
} /* Otherwise, minutiae list is empty. */
/* Otherwise, assume new minutia is not in the list, so add it. */
minutiae->list[minutiae->num] = minutia;
(minutiae->num)++;
/* New minutia was successfully added to the list. */
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: update_minutiae_V2 - Takes a detected minutia point and (if it is not
#cat: determined to already be in the minutiae list or the
#cat: new point is determined to be "more compatible") adds
#cat: it to the list.
Input:
minutia - minutia structure for detected point
scan_dir - orientation of scan when minutia was detected
dmapval - directional ridge flow of block minutia is in
bdata - binary image data (0==while & 1==black)
iw - width (in pixels) of image
ih - height (in pixels) of image
lfsparms - parameters and thresholds for controlling LFS
Output:
minutiae - points to a list of detected minutia structures
Return Code:
Zero - minutia added to successfully added to minutiae list
IGNORE - minutia is to be ignored (already in the minutiae list)
Negative - system error
**************************************************************************/
int update_minutiae_V2(MINUTIAE *minutiae, MINUTIA *minutia,
const int scan_dir, const int dmapval,
unsigned char *bdata, const int iw, const int ih,
const LFSPARMS *lfsparms)
{
int i, ret, dy, dx, delta_dir;
int qtr_ndirs, full_ndirs;
int map_scan_dir;
/* Check to see if minutiae list is full ... if so, then extend */
/* the length of the allocated list of minutia points. */
if(minutiae->num >= minutiae->alloc){
if((ret = realloc_minutiae(minutiae, MAX_MINUTIAE)))
return(ret);
}
/* Otherwise, there is still room for more minutia. */
/* Compute quarter of possible directions in a semi-circle */
/* (ie. 45 degrees). */
qtr_ndirs = lfsparms->num_directions>>2;
/* Compute number of directions in full circle. */
full_ndirs = lfsparms->num_directions<<1;
/* Is the minutiae list empty? */
if(minutiae->num > 0){
/* Foreach minutia stored in the list (in reverse order) ... */
for(i = minutiae->num-1; i >= 0; i--){
/* If x distance between new minutia and current list minutia */
/* are sufficiently close... */
dx = abs(minutiae->list[i]->x - minutia->x);
if(dx < lfsparms->max_minutia_delta){
/* If y distance between new minutia and current list minutia */
/* are sufficiently close... */
dy = abs(minutiae->list[i]->y - minutia->y);
if(dy < lfsparms->max_minutia_delta){
/* If new minutia and current list minutia are same type... */
if(minutiae->list[i]->type == minutia->type){
/* Test to see if minutiae have similar directions. */
/* Take minimum of computed inner and outer */
/* direction differences. */
delta_dir = abs(minutiae->list[i]->direction -
minutia->direction);
delta_dir = min(delta_dir, full_ndirs-delta_dir);
/* If directional difference is <= 45 degrees... */
if(delta_dir <= qtr_ndirs){
/* If new minutia and current list minutia share */
/* the same point... */
if((dx==0) && (dy==0)){
/* Then the minutiae match, so don't add the new one */
/* to the list. */
return(IGNORE);
}
/* Othewise, check if they share the same contour. */
/* Start by searching "max_minutia_delta" steps */
/* clockwise. */
/* If new minutia point found on contour... */
if(search_contour(minutia->x, minutia->y,
lfsparms->max_minutia_delta,
minutiae->list[i]->x, minutiae->list[i]->y,
minutiae->list[i]->ex, minutiae->list[i]->ey,
SCAN_CLOCKWISE, bdata, iw, ih) ||
search_contour(minutia->x, minutia->y,
lfsparms->max_minutia_delta,
minutiae->list[i]->x, minutiae->list[i]->y,
minutiae->list[i]->ex, minutiae->list[i]->ey,
SCAN_COUNTER_CLOCKWISE, bdata, iw, ih)){
/* If new minutia has VALID block direction ... */
if(dmapval >= 0){
/* Derive feature scan direction compatible */
/* with VALID direction. */
map_scan_dir = choose_scan_direction(dmapval,
lfsparms->num_directions);
/* If map scan direction compatible with scan */
/* direction in which new minutia was found ... */
if(map_scan_dir == scan_dir){
/* Then choose the new minutia over the one */
/* currently in the list. */
if((ret = remove_minutia(i, minutiae))){
return(ret);
}
/* Continue on ... */
}
else
/* Othersize, scan directions not compatible...*/
/* so choose to keep the current minutia in */
/* the list and ignore the new one. */
return(IGNORE);
}
else{
/* Otherwise, no reason to believe new minutia */
/* is any better than the current one in the list,*/
/* so consider the new minutia to be the same as */
/* the current list minutia, and don't add the new*/
/* one to the list. */
return(IGNORE);
}
}
/* Otherwise, new minutia and current list minutia do */
/* not share the same contour, so although they are */
/* similar in type and location, treat them as 2 */
/* different minutia. */
} /* Otherwise, directions are too different. */
} /* Otherwise, minutiae are different type. */
} /* Otherwise, minutiae too far apart in Y. */
} /* Otherwise, minutiae too far apart in X. */
} /* End FOR minutia in list. */
} /* Otherwise, minutiae list is empty. */
/* Otherwise, assume new minutia is not in the list, or those that */
/* were close neighbors were selectively removed, so add it. */
minutiae->list[minutiae->num] = minutia;
(minutiae->num)++;
/* New minutia was successfully added to the list. */
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: sort_minutiae_y_x - Takes a list of minutia points and sorts them
#cat: top-to-bottom and then left-to-right.
Input:
minutiae - list of minutiae
iw - width (in pixels) of image
ih - height (in pixels) of image
Output:
minutiae - list of sorted minutiae
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int sort_minutiae_y_x(MINUTIAE *minutiae, const int iw, const int ih)
{
int *ranks, *order;
int i, ret;
MINUTIA **newlist;
/* Allocate a list of integers to hold 1-D image pixel offsets */
/* for each of the 2-D minutia coordinate points. */
ranks = (int *)malloc(minutiae->num * sizeof(int));
if(ranks == (int *)NULL){
fprintf(stderr, "ERROR : sort_minutiae_y_x : malloc : ranks\n");
return(-310);
}
/* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */
for(i = 0; i < minutiae->num; i++)
ranks[i] = (minutiae->list[i]->y * iw) + minutiae->list[i]->x;
/* Get sorted order of minutiae. */
if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){
free(ranks);
return(ret);
}
/* Allocate new MINUTIA list to hold sorted minutiae. */
newlist = (MINUTIA **)malloc(minutiae->num * sizeof(MINUTIA *));
if(newlist == (MINUTIA **)NULL){
free(ranks);
free(order);
fprintf(stderr, "ERROR : sort_minutiae_y_x : malloc : newlist\n");
return(-311);
}
/* Put minutia into sorted order in new list. */
for(i = 0; i < minutiae->num; i++)
newlist[i] = minutiae->list[order[i]];
/* Deallocate non-sorted list of minutia pointers. */
free(minutiae->list);
/* Assign new sorted list of minutia to minutiae list. */
minutiae->list = newlist;
/* Free the working memories supporting the sort. */
free(order);
free(ranks);
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: sort_minutiae_x_y - Takes a list of minutia points and sorts them
#cat: left-to-right and then top-to-bottom.
Input:
minutiae - list of minutiae
iw - width (in pixels) of image
ih - height (in pixels) of image
Output:
minutiae - list of sorted minutiae
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int sort_minutiae_x_y(MINUTIAE *minutiae, const int iw, const int ih)
{
int *ranks, *order;
int i, ret;
MINUTIA **newlist;
/* Allocate a list of integers to hold 1-D image pixel offsets */
/* for each of the 2-D minutia coordinate points. */
ranks = (int *)malloc(minutiae->num * sizeof(int));
if(ranks == (int *)NULL){
fprintf(stderr, "ERROR : sort_minutiae_x_y : malloc : ranks\n");
return(-440);
}
/* Compute 1-D image pixel offsets form 2-D minutia coordinate points. */
for(i = 0; i < minutiae->num; i++)
ranks[i] = (minutiae->list[i]->x * iw) + minutiae->list[i]->y;
/* Get sorted order of minutiae. */
if((ret = sort_indices_int_inc(&order, ranks, minutiae->num))){
free(ranks);
return(ret);
}
/* Allocate new MINUTIA list to hold sorted minutiae. */
newlist = (MINUTIA **)malloc(minutiae->num * sizeof(MINUTIA *));
if(newlist == (MINUTIA **)NULL){
free(ranks);
free(order);
fprintf(stderr, "ERROR : sort_minutiae_x_y : malloc : newlist\n");
return(-441);
}
/* Put minutia into sorted order in new list. */
for(i = 0; i < minutiae->num; i++)
newlist[i] = minutiae->list[order[i]];
/* Deallocate non-sorted list of minutia pointers. */
free(minutiae->list);
/* Assign new sorted list of minutia to minutiae list. */
minutiae->list = newlist;
/* Free the working memories supporting the sort. */
free(order);
free(ranks);
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: rm_dup_minutiae - Takes a list of minutiae sorted in some adjacent order
#cat: and detects and removes redundant minutia that have the
#cat: same exact pixel coordinate locations (even if other
#cat: attributes may differ).
Input:
mintuiae - list of sorted minutiae
Output:
mintuiae - list of sorted minutiae with duplicates removed
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int rm_dup_minutiae(MINUTIAE *minutiae)
{
int i, ret;
MINUTIA *minutia1, *minutia2;
/* Work backward from the end of the list of minutiae. This way */
/* we can selectively remove minutia from the list and not cause */
/* problems with keeping track of current indices. */
for(i = minutiae->num-1; i > 0; i--){
minutia1 = minutiae->list[i];
minutia2 = minutiae->list[i-1];
/* If minutia pair has identical coordinates ... */
if((minutia1->x == minutia2->x) &&
(minutia1->y == minutia2->y)){
/* Remove the 2nd minutia from the minutiae list. */
if((ret = remove_minutia(i-1, minutiae)))
return(ret);
/* The first minutia slides into the position of the 2nd. */
}
}
/* Return successfully. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: dump_minutiae - Given a minutiae list, writes a formatted text report of
#cat: the list's contents to the specified open file pointer.
Input:
minutiae - list of minutia structures
Output:
fpout - open file pointer
**************************************************************************/
void dump_minutiae(FILE *fpout, const MINUTIAE *minutiae)
{
int i, j;
fprintf(fpout, "\n%d Minutiae Detected\n\n", minutiae->num);
for(i = 0; i < minutiae->num; i++){
/* Precision of reliablity added one decimal position */
/* on 09-13-04 */
fprintf(fpout, "%4d : %4d, %4d : %2d : %6.3f :", i,
minutiae->list[i]->x, minutiae->list[i]->y,
minutiae->list[i]->direction, minutiae->list[i]->reliability);
if(minutiae->list[i]->type == RIDGE_ENDING)
fprintf(fpout, "RIG : ");
else
fprintf(fpout, "BIF : ");
if(minutiae->list[i]->appearing)
fprintf(fpout, "APP : ");
else
fprintf(fpout, "DIS : ");
fprintf(fpout, "%2d ", minutiae->list[i]->feature_id);
for(j = 0; j < minutiae->list[i]->num_nbrs; j++){
fprintf(fpout, ": %4d,%4d; %2d ",
minutiae->list[minutiae->list[i]->nbrs[j]]->x,
minutiae->list[minutiae->list[i]->nbrs[j]]->y,
minutiae->list[i]->ridge_counts[j]);
}
fprintf(fpout, "\n");
}
}
/*************************************************************************
**************************************************************************
#cat: dump_minutiae_pts - Given a minutiae list, writes the coordinate point
#cat: for each minutia in the list to the specified open
#cat: file pointer.
Input:
minutiae - list of minutia structures
Output:
fpout - open file pointer
**************************************************************************/
void dump_minutiae_pts(FILE *fpout, const MINUTIAE *minutiae)
{
int i;
/* First line in the output file contians the number of minutia */
/* points to be written to the file. */
fprintf(fpout, "%d\n", minutiae->num);
/* Foreach minutia in list... */
for(i = 0; i < minutiae->num; i++){
/* Write the minutia's coordinate point to the file pointer. */
fprintf(fpout, "%4d %4d\n", minutiae->list[i]->x, minutiae->list[i]->y);
}
}
/*************************************************************************
**************************************************************************
#cat: dump_reliable_minutiae_pts - Given a minutiae list, writes the
#cat: coordinate point for each minutia in the list that has
#cat: the specified reliability to the specified open
#cat: file pointer.
Input:
minutiae - list of minutia structures
reliability - desired reliability level for minutiae to be reported
Output:
fpout - open file pointer
**************************************************************************/
void dump_reliable_minutiae_pts(FILE *fpout, const MINUTIAE *minutiae,
const double reliability)
{
int i, count;
/* First count the number of qualifying minutiae so that the */
/* MFS header may be written. */
count = 0;
/* Foreach minutia in list... */
for(i = 0; i < minutiae->num; i++){
if(minutiae->list[i]->reliability == reliability)
count++;
}
/* First line in the output file contians the number of minutia */
/* points to be written to the file. */
fprintf(fpout, "%d\n", count);
/* Foreach minutia in list... */
for(i = 0; i < minutiae->num; i++){
if(minutiae->list[i]->reliability == reliability)
/* Write the minutia's coordinate point to the file pointer. */
fprintf(fpout, "%4d %4d\n",
minutiae->list[i]->x, minutiae->list[i]->y);
}
}
/*************************************************************************
**************************************************************************
#cat: create_minutia - Takes attributes associated with a detected minutia
#cat: point and allocates and initializes a minutia structure.
Input:
x_loc - x-pixel coord of minutia (interior to feature)
y_loc - y-pixel coord of minutia (interior to feature)
x_edge - x-pixel coord of corresponding edge pixel (exterior to feature)
y_edge - y-pixel coord of corresponding edge pixel (exterior to feature)
idir - integer direction of the minutia
reliability - floating point measure of minutia's reliability
type - type of the minutia (ridge-ending or bifurcation)
appearing - designates the minutia as appearing or disappearing
feature_id - index of minutia's matching feature_patterns[]
Output:
ominutia - ponter to an allocated and initialized minutia structure
Return Code:
Zero - minutia structure successfully allocated and initialized
Negative - system error
*************************************************************************/
int create_minutia(MINUTIA **ominutia, const int x_loc, const int y_loc,
const int x_edge, const int y_edge, const int idir,
const double reliability,
const int type, const int appearing, const int feature_id)
{
MINUTIA *minutia;
/* Allocate a minutia structure. */
minutia = (MINUTIA *)malloc(sizeof(MINUTIA));
/* If allocation error... */
if(minutia == (MINUTIA *)NULL){
fprintf(stderr, "ERROR : create_minutia : malloc : minutia\n");
return(-230);
}
/* Assign minutia structure attributes. */
minutia->x = x_loc;
minutia->y = y_loc;
minutia->ex = x_edge;
minutia->ey = y_edge;
minutia->direction = idir;
minutia->reliability = reliability;
minutia->type = type;
minutia->appearing = appearing;
minutia->feature_id = feature_id;
minutia->nbrs = (int *)NULL;
minutia->ridge_counts = (int *)NULL;
minutia->num_nbrs = 0;
/* Set minutia object to output pointer. */
*ominutia = minutia;
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: free_minutiae - Takes a minutiae list and deallocates all memory
#cat: associated with it.
Input:
minutiae - pointer to allocated list of minutia structures
*************************************************************************/
void free_minutiae(MINUTIAE *minutiae)
{
int i;
/* Deallocate minutia structures in the list. */
for(i = 0; i < minutiae->num; i++)
free_minutia(minutiae->list[i]);
/* Deallocate list of minutia pointers. */
free(minutiae->list);
/* Deallocate the list structure. */
free(minutiae);
}
/*************************************************************************
**************************************************************************
#cat: free_minutia - Takes a minutia pointer and deallocates all memory
#cat: associated with it.
Input:
minutia - pointer to allocated minutia structure
*************************************************************************/
void free_minutia(MINUTIA *minutia)
{
/* Deallocate sublists. */
if(minutia->nbrs != (int *)NULL)
free(minutia->nbrs);
if(minutia->ridge_counts != (int *)NULL)
free(minutia->ridge_counts);
/* Deallocate the minutia structure. */
free(minutia);
}
/*************************************************************************
**************************************************************************
#cat: remove_minutia - Removes the specified minutia point from the input
#cat: list of minutiae.
Input:
index - position of minutia to be removed from list
minutiae - input list of minutiae
Output:
minutiae - list with minutia removed
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int remove_minutia(const int index, MINUTIAE *minutiae)
{
int fr, to;
/* Make sure the requested index is within range. */
if((index < 0) && (index >= minutiae->num)){
fprintf(stderr, "ERROR : remove_minutia : index out of range\n");
return(-380);
}
/* Deallocate the minutia structure to be removed. */
free_minutia(minutiae->list[index]);
/* Slide the remaining list of minutiae up over top of the */
/* position of the minutia being removed. */
for(to = index, fr = index+1; fr < minutiae->num; to++, fr++)
minutiae->list[to] = minutiae->list[fr];
/* Decrement the number of minutiae remaining in the list. */
minutiae->num--;
/* Return normally. */
return(0);
}
/*************************************************************************