Skip to content

Commit 2bb9889

Browse files
author
vboxuser
committed
add scripts to generate pypi packe easily with the latest codes
1 parent 4122159 commit 2bb9889

File tree

8 files changed

+152
-24
lines changed

8 files changed

+152
-24
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Uses oriented gabor filter bank to enhance the fingerprint image. The orientatio
1515
import cv2
1616
1717
img = cv2.imread('image_path', 0) # read input image
18-
out = fingerprint_enhancer.enhance_Fingerprint(img) # enhance the fingerprint image
18+
out = fingerprint_enhancer.enhance_fingerprint(img) # enhance the fingerprint image
1919
cv2.imshow('enhanced_image', out); # display the result
2020
cv2.waitKey(0) # hold the display window
2121
```

devtool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Module to run pre commit checks for staged files."""
22
from subprocess import check_call
33
import os
4+
45
import fire
56
import git
67

enhanced/1.jpg

-170 KB
Binary file not shown.

enhanced/2.jpg

-70.7 KB
Binary file not shown.

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""generate the fingerprint_enhancer python package."""
2+
3+
from setuptools import setup
4+
5+
with open("README.md", "r", encoding="utf-8") as fh:
6+
long_description = fh.read()
7+
8+
setup(
9+
name="fingerprint_enhancer",
10+
version="0.0.14",
11+
author="utkarsh-deshmukh",
12+
author_email="utkarsh.deshmukh@gmail.com",
13+
description="enhance fingerprint images",
14+
long_description=long_description,
15+
long_description_content_type="text/markdown",
16+
url="https://github.com/Utkarsh-Deshmukh/Fingerprint-Enhancement-Python",
17+
download_url="https://github.com/Utkarsh-Deshmukh/Fingerprint-Enhancement-Python/archive/develop.zip",
18+
install_requires=["numpy", "opencv-python", "scipy"],
19+
license="MIT",
20+
keywords="Fingerprint Image Enhancement",
21+
package_dir={"": "src"},
22+
packages=["fingerprint_enhancer"],
23+
classifiers=[
24+
"Programming Language :: Python :: 3",
25+
"License :: OSI Approved :: MIT License",
26+
"Operating System :: OS Independent",
27+
],
28+
)

src/example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import sys
99
import cv2
10-
from fingerprint_image_enhancer import FingerprintImageEnhancer
10+
from fingerprint_enhancer.fingerprint_image_enhancer import FingerprintImageEnhancer
1111

1212
if __name__ == "__main__":
1313
image_enhancer = FingerprintImageEnhancer() # Create object called image_enhancer
@@ -22,5 +22,5 @@
2222
if len(img.shape) > 2: # convert image into gray if necessary
2323
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
2424

25-
out = image_enhancer.enhance(img) # run image enhancer
25+
image_enhancer.enhance(img, invert_output=True) # run image enhancer
2626
image_enhancer.save_enhanced_image("enhanced/" + IMG_NAME) # save output

src/fingerprint_enhancer/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"""fingerprint_enhancer module."""
2+
from .fingerprint_image_enhancer import enhance_fingerprint

src/fingerprint_image_enhancer.py renamed to src/fingerprint_enhancer/fingerprint_image_enhancer.py

Lines changed: 118 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,64 @@
66
"""
77

88
import math
9-
import numpy as np
9+
import os
10+
1011
import cv2
11-
from scipy import signal
12-
from scipy import ndimage
12+
import numpy as np
1313
import scipy
14+
from scipy import ndimage, signal
1415

1516

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
1718
class FingerprintImageEnhancer:
1819
"""Fingerprint Enhancer Object."""
1920

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
3567

3668
self._mask = []
3769
self._normim = []
@@ -515,18 +547,20 @@ def save_enhanced_image(self, path: str) -> None:
515547
Args:
516548
path (str): image name.
517549
"""
550+
os.makedirs(os.path.dirname(path), exist_ok=True)
518551
# saves the enhanced image at the specified path
519552
cv2.imwrite(path, (255 * self._binim))
520553

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:
522555
"""Enhance the input image.
523556
524557
Args:
525558
img (np.ndarray): input image.
526559
resize (bool, optional): resize the input image. Defaults to True.
560+
invert_output (bool, optional): invert the output
527561
528562
Returns:
529-
_type_np.ndarray: return the enhanced image.
563+
np.ndarray: return the enhanced image.
530564
"""
531565
if resize:
532566
rows, cols = np.shape(img)
@@ -541,4 +575,67 @@ def enhance(self, img: np.ndarray, resize: bool = True) -> np.ndarray:
541575
self.__ridge_orient() # compute orientation image
542576
self.__ridge_freq() # compute major frequency of ridges
543577
self.__ridge_filter() # filter the image using oriented gabor filter
578+
if invert_output:
579+
self._binim ^= True
544580
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

Comments
 (0)