extract ridges and valleys from finger Image

Viewed 198

for my class project I am trying to extract ridges and Valleys from the finger image. An example is given below.

#The code I am using

import cv2
import numpy as np
import fingerprint_enhancer 
clip_hist_percent=25
image = cv2.imread("")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Calculate grayscale histogram
hist = cv2.calcHist([gray],[0],None,[256],[0,256])
hist_size = len(hist)

# Calculate cumulative distribution from the histogram
accumulator = []
accumulator.append(float(hist[0]))
for index in range(1, hist_size):
   accumulator.append(accumulator[index -1] + float(hist[index]))

# Locate points to clip
maximum = accumulator[-1]
clip_hist_percent *= (maximum/100.0)
clip_hist_percent /= 2.0

# Locate left cut
minimum_gray = 0
while accumulator[minimum_gray] < clip_hist_percent:
   minimum_gray += 1

# Locate right cut
maximum_gray = hist_size -1
while accumulator[maximum_gray] >= (maximum - clip_hist_percent):
    maximum_gray -= 1

# Calculate alpha and beta values
alpha = 255 / (maximum_gray - minimum_gray)
beta = -minimum_gray * alpha



auto_result = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)

gray = cv2.cvtColor(auto_result, cv2.COLOR_BGR2GRAY)

# compute gamma = log(mid*255)/log(mean)
mid = 0.5
mean = np.mean(gray)
gamma = math.log(mid*255)/math.log(mean)
# do gamma correction
img_gamma1 = np.power(auto_result,gamma).clip(0,255).astype(np.uint8)
g1 = cv2.cvtColor(img_gamma2, cv2.COLOR_BGR2GRAY)
# blur = cv2.GaussianBlur(g1,(2,1),0)

thresh2 = cv2.adaptiveThreshold(g1, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                          cv2.THRESH_BINARY, 199, 3)
# blur = cv2.GaussianBlur(thresh2,(2,1),0)
blur=((3,3),1)
erode_=(5,5)
dilate_=(3, 3)
dilate = cv2.dilate(cv2.erode(cv2.GaussianBlur(thresh2/255, blur[0], 
blur[1]), np.ones(erode_)), np.ones(dilate_))*255

out = fingerprint_enhancer.enhance_Fingerprint(dilate)

enter image description here

I am having difficulty extracting the lines on the finger. I tried to adjust the brightness and contrast, applied calcHist, adaptive thresholding, applied blur, then applied the Gabor filters (as per UTKARSH code). The result look like above.

We could clearly see that the lower part of the image has many spurious lines. My project requirement is to get clear lines from the RGB image. Could anyone help me with the steps and the code?

Thank you in advance

reference: https://github.com/Utkarsh-Deshmukh/Fingerprint-Enhancement-Python https://ieeexplore.ieee.org/abstract/document/7358782

1 Answers

There are several strange things (IMO) about your code.

First you do a contrast stretch that sets the 12.5% darkest pixels to black and the 12.5% brightest pixels to white. You probably already have this number of white pixels, so not much happens there, but you do remove all the information in the darkest region of the finger print.

Next you threshold. Here you remove most of the remaining information. Thresholding is something you should leave until the very last step of any processing. In particular, the algorithm implemented in fingerprint_enhancer.enhance_Fingerprint() takes a gray-scale image as input. You should not binarize its input at all!

I would start with a local contrast stretch, then you can directly apply the enhancement algorithm:

import cv2
import fingerprint_enhancer 

image = cv2.imread("zMxbO.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Apply local contrast stretch
se = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (25, 25))  # larger than the width of the widest ridges
low = cv2.morphologyEx(gray, cv2.MORPH_OPEN, se)    # locally lowest grayvalue
high = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, se)  # locally highest grayvalue
gray = (gray - o) / (c - o + 1e-6)

# Apply fingerprint enhancement
out = fingerprint_enhancer.enhance_Fingerprint(gray, resize=True)

The local contrast stretch yields this:

result of local contrast stretch

The finger print enhancement algorithm now yields this:

result of finger print enhancement

Note things go wrong around the edges, where the background was cut out and replaced with white, as well as in the dark region, where the noise dominates and the enhancement algorithm hallucinates a bit. I don't think you can extract meaningful information from that area, a better illumination would be necessary.

Related