-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathremove.c
3180 lines (2821 loc) · 142 KB
/
remove.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: REMOVE.C
AUTHOR: Michael D. Garris
DATE: 08/02/1999
UPDATED: 10/04/1999 Version 2 by MDG
UPDATED: 03/16/2005 by MDG
Contains routines responsible for detecting and removing false
minutiae as part of the NIST Latent Fingerprint System (LFS).
***********************************************************************
ROUTINES:
remove_false_minutia()
remove_false_minutia_V2()
remove_holes()
remove_hooks()
remove_hooks_islands_overlaps()
remove_islands_and_lakes()
remove_malformations()
remove_near_invblocks()
remove_near_invblocks_V2()
remove_pointing_invblock()
remove_pointing_invblock_V2()
remove_overlaps()
remove_pores()
remove_pores_V2()
remove_or_adjust_side_minutiae()
remove_or_adjust_side_minutiae_V2()
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "lfs.h"
/*************************************************************************
**************************************************************************
#cat: remove_false_minutia - Takes a list of true and false minutiae and
#cat: attempts to detect and remove the false minutiae based
#cat: on a series of tests.
Input:
minutiae - list of true and false minutiae
bdata - binary image data (0==while & 1==black)
iw - width (in pixels) of image
ih - height (in pixels) of image
nmap - IMAP ridge flow matrix with invalid, high-curvature,
and no-valid-neighbor regions identified
mw - width in blocks of the NMAP
mh - height in blocks of the NMAP
lfsparms - parameters and thresholds for controlling LFS
Output:
minutiae - list of pruned minutiae
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int remove_false_minutia(MINUTIAE *minutiae,
unsigned char *bdata, const int iw, const int ih,
int *nmap, const int mw, const int mh,
const LFSPARMS *lfsparms)
{
int ret;
/* Sort minutiae points top-to-bottom and left-to-right. */
if((ret = sort_minutiae_y_x(minutiae, iw, ih))){
return(ret);
}
if((ret = link_minutiae(minutiae, bdata, iw, ih, nmap, mw, mh, lfsparms))){
return(ret);
}
if((ret = remove_hooks_islands_lakes_overlaps(minutiae, bdata, iw, ih,
lfsparms))){
return(ret);
}
if((ret = remove_pointing_invblock(minutiae, nmap, mw, mh, lfsparms))){
return(ret);
}
if((ret = remove_holes(minutiae, bdata, iw, ih, lfsparms))){
return(ret);
}
if((ret = remove_or_adjust_side_minutiae(minutiae,
bdata, iw, ih, lfsparms))){
return(ret);
}
if((ret = remove_near_invblock(minutiae, nmap, mw, mh, lfsparms))){
return(ret);
}
if((ret = remove_pores(minutiae, bdata, iw, ih, nmap, mw, mh, lfsparms))){
return(ret);
}
return(0);
}
/*************************************************************************
**************************************************************************
#cat: remove_false_minutia_V2 - Takes a list of true and false minutiae and
#cat: attempts to detect and remove the false minutiae based
#cat: on a series of tests.
Input:
minutiae - list of true and false minutiae
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 - list of pruned minutiae
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int remove_false_minutia_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;
/* 1. Sort minutiae points top-to-bottom and left-to-right. */
if((ret = sort_minutiae_y_x(minutiae, iw, ih))){
return(ret);
}
/* 2. Remove minutiae on lakes (filled with white pixels) and */
/* islands (filled with black pixels), both defined by a pair of */
/* minutia points. */
if((ret = remove_islands_and_lakes(minutiae, bdata, iw, ih, lfsparms))){
return(ret);
}
/* 3. Remove minutiae on holes in the binary image defined by a */
/* single point. */
if((ret = remove_holes(minutiae, bdata, iw, ih, lfsparms))){
return(ret);
}
/* 4. Remove minutiae that point sufficiently close to a block with */
/* INVALID direction. */
if((ret = remove_pointing_invblock_V2(minutiae, direction_map, mw, mh,
lfsparms))){
return(ret);
}
/* 5. Remove minutiae that are sufficiently close to a block with */
/* INVALID direction. */
if((ret = remove_near_invblock_V2(minutiae, direction_map, mw, mh,
lfsparms))){
return(ret);
}
/* 6. Remove or adjust minutiae that reside on the side of a ridge */
/* or valley. */
if((ret = remove_or_adjust_side_minutiae_V2(minutiae, bdata, iw, ih,
direction_map, mw, mh, lfsparms))){
return(ret);
}
/* 7. Remove minutiae that form a hook on the side of a ridge or valley. */
if((ret = remove_hooks(minutiae, bdata, iw, ih, lfsparms))){
return(ret);
}
/* 8. Remove minutiae that are on opposite sides of an overlap. */
if((ret = remove_overlaps(minutiae, bdata, iw, ih, lfsparms))){
return(ret);
}
/* 9. Remove minutiae that are "irregularly" shaped. */
if((ret = remove_malformations(minutiae, bdata, iw, ih,
low_flow_map, mw, mh, lfsparms))){
return(ret);
}
/* 10. Remove minutiae that form long, narrow, loops in the */
/* "unreliable" regions in the binary image. */
if((ret = remove_pores_V2(minutiae, bdata, iw, ih,
direction_map, low_flow_map, high_curve_map,
mw, mh, lfsparms))){
return(ret);
}
return(0);
}
/*************************************************************************
**************************************************************************
#cat: remove_holes - Removes minutia points on small loops around valleys.
Input:
minutiae - list of true and false minutiae
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 - list of pruned minutiae
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int remove_holes(MINUTIAE *minutiae,
unsigned char *bdata, const int iw, const int ih,
const LFSPARMS *lfsparms)
{
int i, ret;
MINUTIA *minutia;
i = 0;
/* Foreach minutia remaining in list ... */
while(i < minutiae->num){
/* Assign a temporary pointer. */
minutia = minutiae->list[i];
/* If current minutia is a bifurcation ... */
if(minutia->type == BIFURCATION){
/* Check to see if it is on a loop of specified length (ex. 15). */
ret = on_loop(minutia, lfsparms->small_loop_len, bdata, iw, ih);
/* If minutia is on a loop ... or loop test IGNORED */
if((ret == LOOP_FOUND) || (ret == IGNORE)){
/* Then remove the minutia from list. */
if((ret = remove_minutia(i, minutiae))){
/* Return error code. */
return(ret);
}
/* No need to advance because next minutia has "slid" */
/* into position pointed to by 'i'. */
}
/* If the minutia is NOT on a loop... */
else if (ret == FALSE){
/* Simply advance to next minutia in the list. */
i++;
}
/* Otherwise, an ERROR occurred while looking for loop. */
else{
/* Return error code. */
return(ret);
}
}
/* Otherwise, the current minutia is a ridge-ending... */
else{
/* Advance to next minutia in the list. */
i++;
}
}
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: remove_hooks - Takes a list of true and false minutiae and
#cat: attempts to detect and remove those false minutiae that
#cat: are on a hook (white or black).
Input:
minutiae - list of true and false minutiae
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 - list of pruned minutiae
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int remove_hooks(MINUTIAE *minutiae,
unsigned char *bdata, const int iw, const int ih,
const LFSPARMS *lfsparms)
{
int *to_remove;
int i, f, s, ret;
int delta_y, full_ndirs, qtr_ndirs, deltadir, min_deltadir;
MINUTIA *minutia1, *minutia2;
double dist;
/* Allocate list of minutia indices that upon completion of testing */
/* should be removed from the minutiae lists. Note: That using */
/* "calloc" initializes the list to FALSE. */
to_remove = (int *)calloc(minutiae->num, sizeof(int));
if(to_remove == (int *)NULL){
fprintf(stderr, "ERROR : remove_hooks : calloc : to_remove\n");
return(-640);
}
/* Compute number directions in full circle. */
full_ndirs = lfsparms->num_directions<<1;
/* Compute number of directions in 45=(180/4) degrees. */
qtr_ndirs = lfsparms->num_directions>>2;
/* Minimum allowable deltadir to consider joining minutia. */
/* (The closer the deltadir is to 180 degrees, the more likely the join. */
/* When ndirs==16, then this value is 11=(3*4)-1 == 123.75 degrees. */
/* I chose to parameterize this threshold based on a fixed fraction of */
/* 'ndirs' rather than on passing in a parameter in degrees and doing */
/* the conversion. I doubt the difference matters. */
min_deltadir = (3 * qtr_ndirs) - 1;
f = 0;
/* Foreach primary (first) minutia (except for last one in list) ... */
while(f < minutiae->num-1){
/* If current first minutia not previously set to be removed. */
if(!to_remove[f]){
/* Set first minutia to temporary pointer. */
minutia1 = minutiae->list[f];
/* Foreach secondary (second) minutia to right of first minutia ... */
s = f+1;
while(s < minutiae->num){
/* Set second minutia to temporary pointer. */
minutia2 = minutiae->list[s];
/* The binary image is potentially being edited during each */
/* iteration of the secondary minutia loop, therefore */
/* minutia pixel values may be changed. We need to catch */
/* these events by using the next 2 tests. */
/* If the first minutia's pixel has been previously changed... */
if(*(bdata+(minutia1->y*iw)+minutia1->x) != minutia1->type){
/* Then break out of secondary loop and skip to next first. */
break;
}
/* If the second minutia's pixel has been previously changed... */
if(*(bdata+(minutia2->y*iw)+minutia2->x) != minutia2->type)
/* Set to remove second minutia. */
to_remove[s] = TRUE;
/* If the second minutia not previously set to be removed. */
if(!to_remove[s]){
/* Compute delta y between 1st & 2nd minutiae and test. */
delta_y = minutia2->y - minutia1->y;
/* If delta y small enough (ex. < 8 pixels) ... */
if(delta_y <= lfsparms->max_rmtest_dist){
/* Compute Euclidean distance between 1st & 2nd mintuae. */
dist = distance(minutia1->x, minutia1->y,
minutia2->x, minutia2->y);
/* If distance is NOT too large (ex. < 8 pixels) ... */
if(dist <= lfsparms->max_rmtest_dist){
/* Compute "inner" difference between directions on */
/* a full circle and test. */
if((deltadir = closest_dir_dist(minutia1->direction,
minutia2->direction, full_ndirs)) ==
INVALID_DIR){
free(to_remove);
fprintf(stderr,
"ERROR : remove_hooks : INVALID direction\n");
return(-641);
}
/* If the difference between dirs is large enough ... */
/* (the more 1st & 2nd point away from each other the */
/* more likely they should be joined) */
if(deltadir > min_deltadir){
/* If 1st & 2nd minutiae are NOT same type ... */
if(minutia1->type != minutia2->type){
/* Check to see if pair on a hook with contour */
/* of specified length (ex. 15 pixels) ... */
ret = on_hook(minutia1, minutia2,
lfsparms->max_hook_len,
bdata, iw, ih);
/* If hook detected between pair ... */
if(ret == HOOK_FOUND){
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Set to remove second minutia. */
to_remove[s] = TRUE;
}
/* If hook test IGNORED ... */
else if (ret == IGNORE){
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Skip to next 1st minutia by breaking out of */
/* inner secondary loop. */
break;
}
/* If system error occurred during hook test ... */
else if (ret < 0){
free(to_remove);
return(ret);
}
/* Otherwise, no hook found, so skip to next */
/* second minutia. */
}
/* End different type test. */
}/* End deltadir test. */
}/* End distance test. */
}
/* Otherwise, current 2nd too far below 1st, so skip to next */
/* 1st minutia. */
else{
/* Break out of inner secondary loop. */
break;
}/* End delta-y test. */
}/* End if !to_remove[s] */
/* Bump to next second minutia in minutiae list. */
s++;
}/* End secondary minutiae loop. */
}/* Otherwise, first minutia already flagged to be removed. */
/* Bump to next first minutia in minutiae list. */
f++;
}/* End primary minutiae loop. */
/* Now remove all minutiae in list that have been flagged for removal. */
/* NOTE: Need to remove the minutia from their lists in reverse */
/* order, otherwise, indices will be off. */
for(i = minutiae->num-1; i >= 0; i--){
/* If the current minutia index is flagged for removal ... */
if(to_remove[i]){
/* Remove the minutia from the minutiae list. */
if((ret = remove_minutia(i, minutiae))){
free(to_remove);
return(ret);
}
}
}
/* Deallocate flag list. */
free(to_remove);
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: remove_hooks_islands_lakes_overlaps - Removes minutia points on hooks,
#cat: islands, lakes, and overlaps and fills in small small
#cat: loops in the binary image and joins minutia features in
#cat: the image on opposite sides of an overlap. So, this
#cat: routine not only prunes minutia points but it edits the
#cat: binary input image as well.
Input:
minutiae - list of true and false minutiae
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 - list of pruned minutiae
bdata - edited binary image with loops filled and overlaps removed
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int remove_hooks_islands_lakes_overlaps(MINUTIAE *minutiae,
unsigned char *bdata, const int iw, const int ih,
const LFSPARMS *lfsparms)
{
int *to_remove;
int i, f, s, ret;
int delta_y, full_ndirs, qtr_ndirs, deltadir, min_deltadir;
int *loop_x, *loop_y, *loop_ex, *loop_ey, nloop;
MINUTIA *minutia1, *minutia2;
double dist;
/* Allocate list of minutia indices that upon completion of testing */
/* should be removed from the minutiae lists. Note: That using */
/* "calloc" initializes the list to FALSE. */
to_remove = (int *)calloc(minutiae->num, sizeof(int));
if(to_remove == (int *)NULL){
fprintf(stderr,
"ERROR : remove_hooks_islands_lakes_overlaps : calloc : to_remove\n");
return(-300);
}
/* Compute number directions in full circle. */
full_ndirs = lfsparms->num_directions<<1;
/* Compute number of directions in 45=(180/4) degrees. */
qtr_ndirs = lfsparms->num_directions>>2;
/* Minimum allowable deltadir to consider joining minutia. */
/* (The closer the deltadir is to 180 degrees, the more likely the join. */
/* When ndirs==16, then this value is 11=(3*4)-1 == 123.75 degrees. */
/* I chose to parameterize this threshold based on a fixed fraction of */
/* 'ndirs' rather than on passing in a parameter in degrees and doing */
/* the conversion. I doubt the difference matters. */
min_deltadir = (3 * qtr_ndirs) - 1;
f = 0;
/* Foreach primary (first) minutia (except for last one in list) ... */
while(f < minutiae->num-1){
/* If current first minutia not previously set to be removed. */
if(!to_remove[f]){
/* Set first minutia to temporary pointer. */
minutia1 = minutiae->list[f];
/* Foreach secondary (second) minutia to right of first minutia ... */
s = f+1;
while(s < minutiae->num){
/* Set second minutia to temporary pointer. */
minutia2 = minutiae->list[s];
/* The binary image is potentially being edited during each */
/* iteration of the secondary minutia loop, therefore */
/* minutia pixel values may be changed. We need to catch */
/* these events by using the next 2 tests. */
/* If the first minutia's pixel has been previously changed... */
if(*(bdata+(minutia1->y*iw)+minutia1->x) != minutia1->type){
/* Then break out of secondary loop and skip to next first. */
break;
}
/* If the second minutia's pixel has been previously changed... */
if(*(bdata+(minutia2->y*iw)+minutia2->x) != minutia2->type)
/* Set to remove second minutia. */
to_remove[s] = TRUE;
/* If the second minutia not previously set to be removed. */
if(!to_remove[s]){
/* Compute delta y between 1st & 2nd minutiae and test. */
delta_y = minutia2->y - minutia1->y;
/* If delta y small enough (ex. < 8 pixels) ... */
if(delta_y <= lfsparms->max_rmtest_dist){
/* Compute Euclidean distance between 1st & 2nd mintuae. */
dist = distance(minutia1->x, minutia1->y,
minutia2->x, minutia2->y);
/* If distance is NOT too large (ex. < 8 pixels) ... */
if(dist <= lfsparms->max_rmtest_dist){
/* Compute "inner" difference between directions on */
/* a full circle and test. */
if((deltadir = closest_dir_dist(minutia1->direction,
minutia2->direction, full_ndirs)) ==
INVALID_DIR){
free(to_remove);
fprintf(stderr,
"ERROR : remove_hooks_islands_lakes_overlaps : INVALID direction\n");
return(-301);
}
/* If the difference between dirs is large enough ... */
/* (the more 1st & 2nd point away from each other the */
/* more likely they should be joined) */
if(deltadir > min_deltadir){
/* If 1st & 2nd minutiae are NOT same type ... */
if(minutia1->type != minutia2->type){
/* Check to see if pair on a hook with contour */
/* of specified length (ex. 15 pixels) ... */
ret = on_hook(minutia1, minutia2,
lfsparms->max_hook_len,
bdata, iw, ih);
/* If hook detected between pair ... */
if(ret == HOOK_FOUND){
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Set to remove second minutia. */
to_remove[s] = TRUE;
}
/* If hook test IGNORED ... */
else if (ret == IGNORE){
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Skip to next 1st minutia by breaking out of */
/* inner secondary loop. */
break;
}
/* If system error occurred during hook test ... */
else if (ret < 0){
free(to_remove);
return(ret);
}
/* Otherwise, no hook found, so skip to next */
/* second minutia. */
}
/* Otherwise, pair is the same type, so test to see */
/* if both are on an island or lake. */
else{
/* Check to see if pair on a loop of specified */
/* half length (ex. 15 pixels) ... */
ret = on_island_lake(&loop_x, &loop_y,
&loop_ex, &loop_ey, &nloop,
minutia1, minutia2,
lfsparms->max_half_loop,
bdata, iw, ih);
/* If pair is on island/lake ... */
if(ret == LOOP_FOUND){
/* Fill the loop. */
if((ret = fill_loop(loop_x, loop_y, nloop,
bdata, iw, ih))){
free_contour(loop_x, loop_y,
loop_ex, loop_ey);
free(to_remove);
return(ret);
}
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Set to remove second minutia. */
to_remove[s] = TRUE;
/* Deallocate loop contour. */
free_contour(loop_x, loop_y, loop_ex, loop_ey);
}
/* If island/lake test IGNORED ... */
else if (ret == IGNORE){
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Skip to next 1st minutia by breaking out of */
/* inner secondary loop. */
break;
}
/* If ERROR while looking for island/lake ... */
else if (ret < 0){
free(to_remove);
return(ret);
}
/* Otherwise, minutia pair not on island/lake, */
/* but might be on an overlap. */
else {
/* If free path exists between pair ... */
if(free_path(minutia1->x, minutia1->y,
minutia2->x, minutia2->y,
bdata, iw, ih, lfsparms)){
/* Then assume overlap, so ... */
/* Join first and second minutiae in image. */
if((ret = join_minutia(minutia1, minutia2,
bdata, iw, ih, NO_BOUNDARY,
JOIN_LINE_RADIUS))){
free(to_remove);
return(ret);
}
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Set to remove second minutia. */
to_remove[s] = TRUE;
}
/* Otherwise, pair not on an overlap, so skip */
/* to next second minutia. */
}/* End overlap test. */
}/* End same type tests (island/lake & overlap). */
}/* End deltadir test. */
}/* End distance test. */
}
/* Otherwise, current 2nd too far below 1st, so skip to next */
/* 1st minutia. */
else{
/* Break out of inner secondary loop. */
break;
}/* End delta-y test. */
}/* End if !to_remove[s] */
/* Bump to next second minutia in minutiae list. */
s++;
}/* End secondary minutiae loop. */
}/* Otherwise, first minutia already flagged to be removed. */
/* Bump to next first minutia in minutiae list. */
f++;
}/* End primary minutiae loop. */
/* Now remove all minutiae in list that have been flagged for removal. */
/* NOTE: Need to remove the minutia from their lists in reverse */
/* order, otherwise, indices will be off. */
for(i = minutiae->num-1; i >= 0; i--){
/* If the current minutia index is flagged for removal ... */
if(to_remove[i]){
/* Remove the minutia from the minutiae list. */
if((ret = remove_minutia(i, minutiae))){
free(to_remove);
return(ret);
}
}
}
/* Deallocate flag list. */
free(to_remove);
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: remove_islands_and_lakes - Takes a list of true and false minutiae and
#cat: attempts to detect and remove those false minutiae that
#cat: are either on a common island (filled with black pixels)
#cat: or a lake (filled with white pixels).
#cat: Note that this routine edits the binary image by filling
#cat: detected lakes or islands.
Input:
minutiae - list of true and false minutiae
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 - list of pruned minutiae
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int remove_islands_and_lakes(MINUTIAE *minutiae,
unsigned char *bdata, const int iw, const int ih,
const LFSPARMS *lfsparms)
{
int *to_remove;
int i, f, s, ret;
int delta_y, full_ndirs, qtr_ndirs, deltadir, min_deltadir;
int *loop_x, *loop_y, *loop_ex, *loop_ey, nloop;
MINUTIA *minutia1, *minutia2;
double dist;
int dist_thresh, half_loop;
dist_thresh = lfsparms->max_rmtest_dist;
half_loop = lfsparms->max_half_loop;
/* Allocate list of minutia indices that upon completion of testing */
/* should be removed from the minutiae lists. Note: That using */
/* "calloc" initializes the list to FALSE. */
to_remove = (int *)calloc(minutiae->num, sizeof(int));
if(to_remove == (int *)NULL){
fprintf(stderr,
"ERROR : remove_islands_and_lakes : calloc : to_remove\n");
return(-610);
}
/* Compute number directions in full circle. */
full_ndirs = lfsparms->num_directions<<1;
/* Compute number of directions in 45=(180/4) degrees. */
qtr_ndirs = lfsparms->num_directions>>2;
/* Minimum allowable deltadir to consider joining minutia. */
/* (The closer the deltadir is to 180 degrees, the more likely the join. */
/* When ndirs==16, then this value is 11=(3*4)-1 == 123.75 degrees. */
/* I chose to parameterize this threshold based on a fixed fraction of */
/* 'ndirs' rather than on passing in a parameter in degrees and doing */
/* the conversion. I doubt the difference matters. */
min_deltadir = (3 * qtr_ndirs) - 1;
/* Foreach primary (first) minutia (except for last one in list) ... */
f = 0;
while(f < minutiae->num-1){
/* If current first minutia not previously set to be removed. */
if(!to_remove[f]){
/* Set first minutia to temporary pointer. */
minutia1 = minutiae->list[f];
/* Foreach secondary minutia to right of first minutia ... */
s = f+1;
while(s < minutiae->num){
/* Set second minutia to temporary pointer. */
minutia2 = minutiae->list[s];
/* If the secondary minutia is desired type ... */
if(minutia2->type == minutia1->type){
/* The binary image is potentially being edited during */
/* each iteration of the secondary minutia loop, */
/* therefore minutia pixel values may be changed. We */
/* need to catch these events by using the next 2 tests. */
/* If the first minutia's pixel has been previously */
/* changed... */
if(*(bdata+(minutia1->y*iw)+minutia1->x) != minutia1->type){
/* Then break out of secondary loop and skip to next */
/* first. */
break;
}
/* If the second minutia's pixel has been previously */
/* changed... */
if(*(bdata+(minutia2->y*iw)+minutia2->x) != minutia2->type)
/* Set to remove second minutia. */
to_remove[s] = TRUE;
/* If the second minutia not previously set to be removed. */
if(!to_remove[s]){
/* Compute delta y between 1st & 2nd minutiae and test. */
delta_y = minutia2->y - minutia1->y;
/* If delta y small enough (ex. <16 pixels)... */
if(delta_y <= dist_thresh){
/* Compute Euclidean distance between 1st & 2nd */
/* mintuae. */
dist = distance(minutia1->x, minutia1->y,
minutia2->x, minutia2->y);
/* If distance is NOT too large (ex. <16 pixels)... */
if(dist <= dist_thresh){
/* Compute "inner" difference between directions */
/* on a full circle and test. */
if((deltadir = closest_dir_dist(minutia1->direction,
minutia2->direction, full_ndirs)) ==
INVALID_DIR){
free(to_remove);
fprintf(stderr,
"ERROR : remove_islands_and_lakes : INVALID direction\n");
return(-611);
}
/* If the difference between dirs is large */
/* enough ... */
/* (the more 1st & 2nd point away from each */
/* other the more likely they should be joined) */
if(deltadir > min_deltadir){
/* Pair is the same type, so test to see */
/* if both are on an island or lake. */
/* Check to see if pair on a loop of specified */
/* half length (ex. 30 pixels) ... */
ret = on_island_lake(&loop_x, &loop_y,
&loop_ex, &loop_ey, &nloop,
minutia1, minutia2,
half_loop, bdata, iw, ih);
/* If pair is on island/lake ... */
if(ret == LOOP_FOUND){
/* Fill the loop. */
if((ret = fill_loop(loop_x, loop_y, nloop,
bdata, iw, ih))){
free_contour(loop_x, loop_y,
loop_ex, loop_ey);
free(to_remove);
return(ret);
}
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Set to remove second minutia. */
to_remove[s] = TRUE;
/* Deallocate loop contour. */
free_contour(loop_x,loop_y,loop_ex,loop_ey);
}
/* If island/lake test IGNORED ... */
else if (ret == IGNORE){
/* Set to remove first minutia. */
to_remove[f] = TRUE;
/* Skip to next 1st minutia by breaking out */
/* of inner secondary loop. */
break;
}
/* If ERROR while looking for island/lake ... */
else if (ret < 0){
free(to_remove);
return(ret);
}
}/* End deltadir test. */
}/* End distance test. */
}
/* Otherwise, current 2nd too far below 1st, so skip to */
/* next 1st minutia. */
else{
/* Break out of inner secondary loop. */
break;
}/* End delta-y test. */
}/* End if !to_remove[s] */
}/* End if 2nd not desired type */
/* Bump to next second minutia in minutiae list. */
s++;
}/* End secondary minutiae loop. */
}/* Otherwise, first minutia already flagged to be removed. */
/* Bump to next first minutia in minutiae list. */
f++;
}/* End primary minutiae loop. */
/* Now remove all minutiae in list that have been flagged for removal. */
/* NOTE: Need to remove the minutia from their lists in reverse */
/* order, otherwise, indices will be off. */
for(i = minutiae->num-1; i >= 0; i--){
/* If the current minutia index is flagged for removal ... */
if(to_remove[i]){
/* Remove the minutia from the minutiae list. */
if((ret = remove_minutia(i, minutiae))){
free(to_remove);
return(ret);
}
}
}
/* Deallocate flag list. */
free(to_remove);
/* Return normally. */
return(0);
}
/*************************************************************************
**************************************************************************
#cat: remove_malformations - Attempts to detect and remove minutia points
#cat: that are "irregularly" shaped. Irregularity is measured
#cat: by measuring across the interior of the feature at
#cat: two progressive points down the feature's contour. The
#cat: test is triggered if a pixel of opposite color from the
#cat: feture's type is found. The ratio of the distances across
#cat: the feature at the two points is computed and if the ratio
#cat: is too large then the minutia is determined to be malformed.
#cat: A cursory test is conducted prior to the general tests in
#cat: the event that the minutia lies in a block with LOW RIDGE
#cat: FLOW. In this case, the distance across the feature at
#cat: the second progressive contour point is measured and if
#cat: too large, the point is determined to be malformed.
Input:
minutiae - list of true and false minutiae
bdata - binary image data (0==while & 1==black)
iw - width (in pixels) of image
ih - height (in pixels) of image
low_flow_map - map of image blocks flagged as LOW RIDGE FLOW
mw - width in blocks of the map
mh - height in blocks of the map
lfsparms - parameters and thresholds for controlling LFS
Output:
minutiae - list of pruned minutiae
Return Code:
Zero - successful completion
Negative - system error
**************************************************************************/
int remove_malformations(MINUTIAE *minutiae,
unsigned char *bdata, const int iw, const int ih,
int *low_flow_map, const int mw, const int mh,
const LFSPARMS *lfsparms)
{
int i, j, ret;
MINUTIA *minutia;
int *contour_x, *contour_y, *contour_ex, *contour_ey, ncontour;
int ax1, ay1, bx1, by1;
int ax2, ay2, bx2, by2;
int *x_list, *y_list, num;