6
6
"""
7
7
8
8
import math
9
- import numpy as np
9
+ import os
10
+
10
11
import cv2
11
- from scipy import signal
12
- from scipy import ndimage
12
+ import numpy as np
13
13
import scipy
14
+ from scipy import ndimage , signal
14
15
15
16
16
- # pylint: disable=too-many-instance-attributes, too-many-function-args, too-many-locals
17
+ # pylint: disable=too-many-instance-attributes, too-many-function-args, too-many-locals, too-many-arguments
17
18
class FingerprintImageEnhancer :
18
19
"""Fingerprint Enhancer Object."""
19
20
20
- def __init__ (self ):
21
- """Initialize the object."""
22
- self .ridge_segment_blksze = 16
23
- self .ridge_segment_thresh = 0.1
24
- self .gradient_sigma = 1
25
- self .block_sigma = 7
26
- self .orient_smooth_sigma = 7
27
- self .ridge_freq_blksze = 38
28
- self .ridge_freq_windsze = 5
29
- self .min_wave_length = 5
30
- self .max_wave_length = 15
31
- self .relative_scale_factor_x = 0.65
32
- self .relative_scale_factor_y = 0.65
33
- self .angle_inc = 3
34
- self .ridge_filter_thresh = - 3
21
+ def __init__ (
22
+ self ,
23
+ ridge_segment_blksze = 16 ,
24
+ ridge_segment_thresh = 0.1 ,
25
+ gradient_sigma = 1 ,
26
+ block_sigma = 7 ,
27
+ orient_smooth_sigma = 7 ,
28
+ ridge_freq_blksze = 38 ,
29
+ ridge_freq_windsze = 5 ,
30
+ min_wave_length = 5 ,
31
+ max_wave_length = 15 ,
32
+ relative_scale_factor_x = 0.65 ,
33
+ relative_scale_factor_y = 0.65 ,
34
+ angle_inc = 3.0 ,
35
+ ridge_filter_thresh = - 3 ,
36
+ ):
37
+ """initialize the object
38
+
39
+ Args:
40
+ ridge_segment_blksze (int, optional): ridge_segment_blksze. Defaults to 16.
41
+ ridge_segment_thresh (float, optional): ridge_segment_thresh. Defaults to 0.1.
42
+ gradient_sigma (int, optional): gradient_sigma. Defaults to 1.
43
+ block_sigma (int, optional): block_sigma. Defaults to 7.
44
+ orient_smooth_sigma (int, optional): orient_smooth_sigma. Defaults to 7.
45
+ ridge_freq_blksze (int, optional): block size for ridge_freq calculation. Defaults to 38.
46
+ ridge_freq_windsze (int, optional): window size for ridge_freq calculation. Defaults to 5.
47
+ min_wave_length (int, optional): min_wave_length. Defaults to 5.
48
+ max_wave_length (int, optional): max_wave_length. Defaults to 15.
49
+ relative_scale_factor_x (float, optional): relative_scale_factor_x. Defaults to 0.65.
50
+ relative_scale_factor_y (float, optional): relative_scale_factor_x. Defaults to 0.65.
51
+ angle_inc (float, optional): angle increment for gabor filtering. Defaults to 3.0.
52
+ ridge_filter_thresh (int, optional): ridge filter threshold. Defaults to -3.
53
+ """
54
+ self .ridge_segment_blksze = ridge_segment_blksze
55
+ self .ridge_segment_thresh = ridge_segment_thresh
56
+ self .gradient_sigma = gradient_sigma
57
+ self .block_sigma = block_sigma
58
+ self .orient_smooth_sigma = orient_smooth_sigma
59
+ self .ridge_freq_blksze = ridge_freq_blksze
60
+ self .ridge_freq_windsze = ridge_freq_windsze
61
+ self .min_wave_length = min_wave_length
62
+ self .max_wave_length = max_wave_length
63
+ self .relative_scale_factor_x = relative_scale_factor_x
64
+ self .relative_scale_factor_y = relative_scale_factor_y
65
+ self .angle_inc = angle_inc
66
+ self .ridge_filter_thresh = ridge_filter_thresh
35
67
36
68
self ._mask = []
37
69
self ._normim = []
@@ -515,18 +547,20 @@ def save_enhanced_image(self, path: str) -> None:
515
547
Args:
516
548
path (str): image name.
517
549
"""
550
+ os .makedirs (os .path .dirname (path ), exist_ok = True )
518
551
# saves the enhanced image at the specified path
519
552
cv2 .imwrite (path , (255 * self ._binim ))
520
553
521
- def enhance (self , img : np .ndarray , resize : bool = True ) -> np .ndarray :
554
+ def enhance (self , img : np .ndarray , resize : bool = True , invert_output = False ) -> np .ndarray :
522
555
"""Enhance the input image.
523
556
524
557
Args:
525
558
img (np.ndarray): input image.
526
559
resize (bool, optional): resize the input image. Defaults to True.
560
+ invert_output (bool, optional): invert the output
527
561
528
562
Returns:
529
- _type_np .ndarray: return the enhanced image.
563
+ np .ndarray: return the enhanced image.
530
564
"""
531
565
if resize :
532
566
rows , cols = np .shape (img )
@@ -541,4 +575,67 @@ def enhance(self, img: np.ndarray, resize: bool = True) -> np.ndarray:
541
575
self .__ridge_orient () # compute orientation image
542
576
self .__ridge_freq () # compute major frequency of ridges
543
577
self .__ridge_filter () # filter the image using oriented gabor filter
578
+ if invert_output :
579
+ self ._binim ^= True
544
580
return self ._binim
581
+
582
+
583
+ # pylint: disable = too-many-arguments
584
+ def enhance_fingerprint (
585
+ img : np .ndarray ,
586
+ resize : bool = False ,
587
+ ridge_segment_blksze : int = 16 ,
588
+ ridge_segment_thresh : float = 0.1 ,
589
+ gradient_sigma : int = 1 ,
590
+ block_sigma : int = 7 ,
591
+ orient_smooth_sigma : int = 7 ,
592
+ ridge_freq_blksze : int = 38 ,
593
+ ridge_freq_windsze : int = 5 ,
594
+ min_wave_length : int = 5 ,
595
+ max_wave_length : int = 15 ,
596
+ relative_scale_factor_x : float = 0.65 ,
597
+ relative_scale_factor_y : float = 0.65 ,
598
+ angle_inc : float = 3.0 ,
599
+ ridge_filter_thresh : int = - 3 ,
600
+ invert_output : bool = False ,
601
+ ) -> np .ndarray :
602
+ """enhance the input image.
603
+
604
+ Args:
605
+ img (np.ndarray): input image
606
+ resize (bool, optional): resize the input image to a fixed size. Defaults to False.
607
+ ridge_segment_blksze (int, optional): ridge_segment_blksze. Defaults to 16.
608
+ ridge_segment_thresh (float, optional): ridge_segment_thresh. Defaults to 0.1.
609
+ gradient_sigma (int, optional): gradient_sigma. Defaults to 1.
610
+ block_sigma (int, optional): block_sigma. Defaults to 7.
611
+ orient_smooth_sigma (int, optional): orient_smooth_sigma. Defaults to 7.
612
+ ridge_freq_blksze (int, optional): block size for ridge_freq calculation. Defaults to 38.
613
+ ridge_freq_windsze (int, optional): window size for ridge_freq calculation. Defaults to 5.
614
+ min_wave_length (int, optional): min_wave_length. Defaults to 5.
615
+ max_wave_length (int, optional): max_wave_length. Defaults to 15.
616
+ relative_scale_factor_x (float, optional): relative_scale_factor_x. Defaults to 0.65.
617
+ relative_scale_factor_y (float, optional): relative_scale_factor_x. Defaults to 0.65.
618
+ angle_inc (float, optional): angle increment for gabor filtering. Defaults to 3.0.
619
+ ridge_filter_thresh (int, optional): ridge filter threshold. Defaults to -3.
620
+ invert_output (bool, optional): flag to invert the enhanced-output. Defaults to False.
621
+
622
+ Returns:
623
+ np.ndarray: _description_
624
+ """
625
+ image_enhancer = FingerprintImageEnhancer (
626
+ ridge_segment_blksze ,
627
+ ridge_segment_thresh ,
628
+ gradient_sigma ,
629
+ block_sigma ,
630
+ orient_smooth_sigma ,
631
+ ridge_freq_blksze ,
632
+ ridge_freq_windsze ,
633
+ min_wave_length ,
634
+ max_wave_length ,
635
+ relative_scale_factor_x ,
636
+ relative_scale_factor_y ,
637
+ angle_inc ,
638
+ ridge_filter_thresh ,
639
+ ) # Create object called image_enhancer
640
+ enhanced_output = image_enhancer .enhance (img , resize , invert_output = invert_output )
641
+ return enhanced_output
0 commit comments