-
Notifications
You must be signed in to change notification settings - Fork 0
/
segmentize.py
64 lines (42 loc) · 1.78 KB
/
segmentize.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
import sys
from django.conf import settings
import os
image_full_path = sys.argv[1]
image_name = sys.argv[2]
import cv2
import numpy as np
import fingerprint_enhancer
import imutils
import matplotlib.pyplot as plt
def normalise(img,mean,std):
normed = (img - np.mean(img))/(np.std(img));
return(normed)
def ridge_segment(im,blksze,thresh):
rows,cols = im.shape;
im = normalise(im,0,1); # normalise to get zero mean and unit standard deviation
new_rows = int(blksze * np.ceil((float(rows))/(float(blksze))))
new_cols = int(blksze * np.ceil((float(cols))/(float(blksze))))
padded_img = np.zeros((new_rows,new_cols));
stddevim = np.zeros((new_rows,new_cols));
padded_img[0:rows][:,0:cols] = im;
for i in range(0,new_rows,blksze):
for j in range(0,new_cols,blksze):
block = padded_img[i:i+blksze][:,j:j+blksze];
stddevim[i:i+blksze][:,j:j+blksze] = np.std(block)*np.ones(block.shape)
stddevim = stddevim[0:rows][:,0:cols]
mask = stddevim > thresh;
mean_val = np.mean(im[mask]);
std_val = np.std(im[mask]);
normim = (im - mean_val)/(std_val);
return(normim,mask)
image = cv2.imread(str(image_full_path))
img = cv2.resize(image,(300,300))
im= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#result = ridge_segment(im,blksze,thresh)
result = ridge_segment(im,16,0.1)
#result = np.hstack((imgray, img)) #stacking images side-by-side
image_save_path = image_full_path.replace(image_name,"md_output/Segmentize_temp.jpg")
output_enhance_enhanced = fingerprint_enhancer.enhance_Fingerprint(result[0])
cv2.imwrite(os.path.join(settings.MEDIA_ROOT,image_save_path), output_enhance_enhanced)
cv2.waitKey(0)
cv2.destroyAllWindows()