指纹增强

时间:2017-01-05 10:08:49

标签: python-2.7 image-processing computer-vision opencv3.0 scikit-image

指纹传感器(Persona)用于获取指纹图像。我正在尝试增强此图像。我正在使用OpenCV来达到这个目的。这是我的原始图片:

我已经应用了otsu变换并得到了这张图片:

现在我已经在0, 45, 90, 135的方向上应用了OpenCV的Gabor过滤器。我得到了这个结果:

这是我在Python OpenCV中用于应用gabor过滤器的代码:

import numpy as np
import cv2

from matplotlib import pyplot as plt

//cv2.getGaborKernel(ksize, sigma, theta, lambda, gamma, psi, ktype)
// ksize - size of gabor filter (n, n)
// sigma - standard deviation of the gaussian function
// theta - orientation of the normal to the parallel stripes
// lambda - wavelength of the sunusoidal factor
// gamma - spatial aspect ratio
// psi - phase offset
// ktype - type and range of values that each pixel in the gabor kernel 
//canhold

g_kernel = cv2.getGaborKernel((25, 25), 6.0, np.pi/4, 8.0, 0.5, 0, ktype=cv2.CV_32F)
g_kernel1 = cv2.getGaborKernel((30, 30), 6.0, (3*np.pi)/4, 8.0, 0.5, 0, ktype=cv2.CV_32F)
g_kernel2 = cv2.getGaborKernel((30, 30),4 , 0, 8, 0.5, 0, ktype=cv2.CV_32F)
g_kernel3 = cv2.getGaborKernel((30, 30),4 , np.pi, 8, 0.5, 0, ktype=cv2.CV_32F)

print np.pi/4
img = cv2.imread('C:/Users/admin123/Desktop/p.png')
img1 = cv2.imread('C:/Users/admin123/Desktop/p.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

// Otsu thresholding
ret2,img1 = cv2.threshold(img1,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.imshow('otsu', img1)

filtered_img = cv2.filter2D(img, cv2.CV_8UC3, g_kernel)
filtered_img1 = cv2.filter2D(img, cv2.CV_8UC3, g_kernel1)
filtered_img2 = cv2.filter2D(img, cv2.CV_8UC3, g_kernel2)
filtered_img3 = cv2.filter2D(img, cv2.CV_8UC3, g_kernel3)

cv2.imshow('0', filtered_img)
cv2.imshow('1', filtered_img1)
cv2.imshow('2', filtered_img2)
cv2.imshow('image', img)

cv2.addWeighted(filtered_img2,0.4,filtered_img1,0.8,0,img) #0 degree and 90
cv2.addWeighted(img,0.4,filtered_img,0.6,0,img) #0 degree and 90
cv2.addWeighted(img,0.4,filtered_img3,0.6,0,img)
cv2.addWeighted(img,0.4,img1,0.6,0.3,img)

cv2.imshow('per',img)

//threshold will convert it plain zero and white image
ret,thresh1 = cv2.threshold(img,150,255,cv2.THRESH_BINARY)#127 instead of 200

cv2.imshow('per1',thresh1)

h, w = g_kernel.shape[:2]
g_kernel = cv2.resize(g_kernel, (3*w, 3*h), interpolation=cv2.INTER_CUBIC)
g_kernel1 = cv2.resize(g_kernel1, (3*w, 3*h), interpolation=cv2.INTER_CUBIC)

cv2.imshow('gabor kernel (resized)', g_kernel)
cv2.imshow('gabor kernel1 (resized)', g_kernel1)

cv2.waitKey(0)
cv2.destroyAllWindows()

我想要强大的指纹识别功能。为此我想要这个级别的图像来获得准确的细节点:

enter image description here

如何从增强中获得这么多结果?代码需要进行哪些更改才能获得增强的结果?

3 个答案:

答案 0 :(得分:3)

好吧,我没有python / opencv的答案,但我可以指出你可以用Matlab代码摆弄的资源。你可以在这里找到代码Simple Fingerprint Matcher 代码基本上包含了enhacement / minutiae提取/匹配的所有代码。虽然在匹配方面不是很强大但增强功能非常好。

我在你上传的样本上运行了代码,如下所示。 Binary enter image description here

请注意,代码使用两种不同的方法组合进行指纹增强。一个基于Gabor滤波器,另一个称为STFT(短时傅里叶变换),但很可能您只需要Gabor滤波器部分。实际上取决于图像质量。 如果您需要Matlab中的Gabor过滤器代码,可以在此处找到它http://www.peterkovesi.com/matlabfns/#fingerprints 但我确实修改了代码以显示图像并只处理一根手指。 以下是主要文件调用步骤提取增强指纹。执行该操作的matlab函数是f_enhance.m

function [ binim, mask, cimg1, cimg2, oimg1, oimg2 ] = f_enhance( img )
enhimg =  fft_enhance_cubs(img,6);             % Enhance with Blocks 6x6
enhimg =  fft_enhance_cubs(enhimg,12);         % Enhance with Blocks 12x12
[enhimg,cimg2] =  fft_enhance_cubs(enhimg,24); % Enhance with Blocks 24x24
blksze = 5;   thresh = 0.085;                  
normim = ridgesegment(enhimg, blksze, thresh);
oimg1 = ridgeorient(normim, 1, 3, 3);                 
[enhimg,cimg1] =  fft_enhance_cubs(img, -1);
[normim, mask] = ridgesegment(enhimg, blksze, thresh);
oimg2 = ridgeorient(normim, 1, 3, 3); 
[freq, medfreq] = ridgefreq(normim, mask, oimg2, 32, 5, 5, 15);
binim = ridgefilter(normim, oimg2, medfreq.*mask, 0.5, 0.5, 1);
figure,imshow(binim,[]); % Normalize to grayscale
binim = ridgefilter(normim, oimg2, medfreq.*mask, 0.5, 0.5, 1) > 0;
figure;
figure,imshow(binim);
figure;
end

你要么恢复到Matlab,要么你总是可以翻译代码:) 祝你好运

答案 1 :(得分:1)

安装

pip install fingerprint_enhancer

用法

import fingerprint_enhancer # Load the library

img = cv2.imread('image_path', 0) # read input image

out = fingerprint_enhancer.enhance_Fingerprint(img) # enhance the fingerprint image

cv2.imshow('enhanced_image', out); # display the result

cv2.waitKey(0)

答案 2 :(得分:0)

我可能迟到了。但这对以后的其他人可能有用。

看看这个资料: https://github.com/Utkarsh-Deshmukh/Fingerprint-Enhancement-Python

它使用python中的定向Gabor过滤器执行指纹增强功能。