问题描述
我在图像处理和 gabor 过滤器方面比较厉害,我想用这个过滤器来增强指纹图像
我阅读了很多关于指纹图像增强的文章,我知道这样做的步骤是
读取图像 -> 归一化 -> 获取方向图 -> gabor 过滤器 -> 二值化 -> 骨架
现在我在第 4 步,我的问题是如何为 gabor 获得( lamds 和 gamma )的正确值
过滤器
我的形象:
我的代码:
1- 读取图像并使用 HOG 特征获取方向图
imgc = imread(r'C:\Users\iP\Desktop\printe.jpg',as_gray=True)
imgc = resize(imgc,(64*3,128*3))
rows,cols=imgc.shape
offset=24
ori=9 # to get angels (0,45,90,135) only
fd,hog_image = hog(imgc,orientations=ori,pixels_per_cell=(offset,offset),cells_per_block=(1,1),visualize=True,multichannel=None,feature_vector=False
)
方向图:
2- 将方向图从 (8,16,1,9) 重塑为 (8,9),8 ->rows,16 -> cols,9 方向
fd=np.array(fd)
fd=np.reshape(fd,(fd.shape[0],fd.shape[1],ori))
# from (8,9) to (8,1)
# Choose the angle that has the most potential ( biggest magntude )
angels=np.zeros((fd.shape[0],1))
for r in range(fd.shape[0]):
for c in range(fd.shape[1]):
bloc_prop = fd[r,c]
angelss=bloc_prop.reshape((1,ori))
angel=np.argmax(angelss)
angels[r,c]=angel
angels=angels.astype(np.int32)
def conv_gabor(img,orient_map,gabor_kernel_shape):
#
# loop on all pixels in the image and convolve it with it's angel in the orientation map
#
roo,coo=img.shape
#to get the padding value for immage before convolving it with kernels
pad=(gabor_kernel_shape-1)
padded=np.zeros((img.shape[0]+pad,img.shape[1]+pad)) # adding the cols and rows
padded[int(pad/2):-int(pad/2),int(pad/2):-int(pad/2)]=img # copy image to inside the padded
image
#result image
dst=padded.copy()
# start from the image that inside the padded
for r in range(int(pad/2),int(pad/2)+roo):
for c in range(int(pad/2),int(pad/2)+coo):
# get the angel from the orientation map
ro=(r-int(pad/2))//offset
co=(c-int(pad/2))//offset
ang=angels[ro,co]
real_angel=(((180/ori)*ang))
# bloack around the pixe to convolve it
block=padded[r-int(pad/2):r+int(pad/2)+1,c-int(pad/2):c+int(pad/2)+1]
# get Gabor kernel
# here is my question ->> what to get the parametres values for ( lambda and gamma
and phi)
ker= cv2.getGaborKernel( (gabor_kernel_shape,gabor_kernel_shape),3,np.deg2rad(real_angel),np.pi/4,0.001,0 )
dst[r,c]=np.sum((ker*block))
return dst
dst=conv_gabor(imgc,angels,11)
dst :
你看到图像太糟糕了,我不知道为什么会这样,我想是因为 lambda 和 gamma 还是什么?
但是当我只用一个天使过滤 45 时:
ker= cv2.getGaborKernel( (11,11),2,np.deg2rad(45),0.5,0 )
filt = cv2.filter2D(imgc,cv2.CV_64F,ker)
plt.imshow(filt,'gray')
结果:
你看到左边有 45 的边质量很好
谁能帮助我,告诉我在这个问题中我该怎么做?
谢谢大家:)
编辑:
我搜索了另一种方法,我发现我可以使用具有多种方向的 gabor fiter bank 并在过滤图像中获得最佳分数,那么如何从过滤图像中找到像素的最佳分数
这是当我使用具有 45,60,65,135 个角度的 gabor fiter bank 并将过滤后的图像划分为 16*16 并找到最高标准偏差时的输出(最佳分数 -> 我使用标准偏差作为分数)对于每个块并获得最佳过滤图像
所以你可以看到图像中有好的和坏的部分,我认为单独使用标准偏差在图像的某些部分是无效的,所以我的新问题是什么是最好的得分函数,它可以给我提供好的输出部分图片
解决方法
在我看来,对过滤后的图像进行加权可能足以满足您的任务。考虑到您的过滤器方向,角度为 45 和 135 的过滤器在图像的不同区域响应非常好。因此,您可以计算加权总和以获得最佳过滤结果。
img = cv2.imread('fingerprint.jpg',0)
w_45 = 0.5
w_135 = 0.5
img_45 = cv2.filter2D(img,cv2.CV_64F,cv2.getGaborKernel( (11,11),2,np.deg2rad(45),np.pi/4,0.5,0 ))
img_135 = cv2.filter2D(img,np.deg2rad(135),0 ))
result = img_45*w_45+img_135*w_135
result = result/np.amax(result)*255
plt.imshow(result,cmap='gray')
plt.show()
随意使用重量。结果完全取决于您的下一步是什么。