-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathfinegerprint_pipline.py
77 lines (59 loc) · 2.86 KB
/
finegerprint_pipline.py
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
import cv2 as cv
from glob import glob
import os
import numpy as np
from utils.poincare import calculate_singularities
from utils.segmentation import create_segmented_and_variance_images
from utils.normalization import normalize
from utils.gabor_filter import gabor_filter
from utils.frequency import ridge_freq
from utils import orientation
from utils.crossing_number import calculate_minutiaes
from tqdm import tqdm
from utils.skeletonize import skeletonize
def fingerprint_pipline(input_img):
block_size = 16
# pipe line picture re https://www.cse.iitk.ac.in/users/biometrics/pages/111.JPG
# normalization -> orientation -> frequency -> mask -> filtering
# normalization - removes the effects of sensor noise and finger pressure differences.
normalized_img = normalize(input_img.copy(), float(100), float(100))
# color threshold
# threshold_img = normalized_img
# _, threshold_im = cv.threshold(normalized_img,127,255,cv.THRESH_OTSU)
# cv.imshow('color_threshold', normalized_img); cv.waitKeyEx()
# ROI and normalisation
(segmented_img, normim, mask) = create_segmented_and_variance_images(normalized_img, block_size, 0.2)
# orientations
angles = orientation.calculate_angles(normalized_img, W=block_size, smoth=False)
orientation_img = orientation.visualize_angles(segmented_img, mask, angles, W=block_size)
# find the overall frequency of ridges in Wavelet Domain
freq = ridge_freq(normim, mask, angles, block_size, kernel_size=5, minWaveLength=5, maxWaveLength=15)
# create gabor filter and do the actual filtering
gabor_img = gabor_filter(normim, angles, freq)
# thinning oor skeletonize
thin_image = skeletonize(gabor_img)
# minutias
minutias = calculate_minutiaes(thin_image)
# singularities
singularities_img = calculate_singularities(thin_image, angles, 1, block_size, mask)
# visualize pipeline stage by stage
output_imgs = [input_img, normalized_img, segmented_img, orientation_img, gabor_img, thin_image, minutias, singularities_img]
for i in range(len(output_imgs)):
if len(output_imgs[i].shape) == 2:
output_imgs[i] = cv.cvtColor(output_imgs[i], cv.COLOR_GRAY2RGB)
results = np.concatenate([np.concatenate(output_imgs[:4], 1), np.concatenate(output_imgs[4:], 1)]).astype(np.uint8)
return results
if __name__ == '__main__':
# open images
img_dir = './sample_inputs/*'
output_dir = './output/'
def open_images(directory):
images_paths = glob(directory)
return np.array([cv.imread(img_path,0) for img_path in images_paths])
images = open_images(img_dir)
# image pipeline
os.makedirs(output_dir, exist_ok=True)
for i, img in enumerate(tqdm(images)):
results = fingerprint_pipline(img)
cv.imwrite(output_dir+str(i)+'.png', results)
# cv.imshow('image pipeline', results); cv.waitKeyEx()