从手指图像中提取脊和谷

extract ridges and valleys from finger Image

对于我的 class 项目,我试图从手指图像中提取脊和谷。下面给出一个例子。

#我使用的代码

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)

我很难提取手指上的线条。我尝试调整亮度和对比度、应用 calcHist、自适应阈值、应用模糊,然后应用 Gabor 过滤器(根据 UTKARSH code)。结果如上所示。

我们可以清楚地看到图像的下部有很多杂散线。我的项目要求是从 RGB 图像中获得清晰的线条。谁能帮我解决步骤和代码?

提前致谢

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

您的代码有几处奇怪的地方 (IMO)。

首先,您进行对比度拉伸,将 12.5% 的最暗像素设置为黑色,将 12.5% 的最亮像素设置为白色。你可能已经有了这个数量的白色像素,所以那里不会发生太多事情,但你确实删除了指纹最暗区域的所有信息。

下一个门槛。在这里,您删除了大部分剩余信息。阈值是您应该保留到任何处理的最后一步。特别是,fingerprint_enhancer.enhance_Fingerprint() 中实现的算法将 gray-scale 图像作为输入。你根本不应该将它的输入二值化!

我会从局部对比度拉伸开始,然后你可以直接应用增强算法:

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)

局部对比度拉伸产生这样的结果:

指纹增强算法现在产生这个:

请注意,边缘周围出现问题,背景被切掉并替换为白色,以及黑暗区域,噪声占主导地位,增强算法有点幻觉。我不认为你可以从该区域提取有意义的信息,需要更好的照明。