【发布时间】:2021-07-07 00:15:50
【问题描述】:
我在图像处理和 gabor 过滤器方面比较厉害,我想用这个过滤器来增强指纹图像
我阅读了很多关于指纹图像增强的文章,我知道这样做的步骤是
读取图像 -> 标准化 -> 获取方向图 -> gabor 过滤器 -> 二值化 -> 骨架
现在我在第 4 步,我的问题是如何为 gabor 获得正确的值(lambds 和 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, 1, 9) 重塑为 (8, 16, 9),,, 8 ->rows , 16 -> cols , 9 个方向
fd=np.array(fd)
fd=np.reshape(fd,(fd.shape[0],fd.shape[1],ori))
# from (8, 16, 9) to (8, 16, 1)
# Choose the angle that has the most potential ( biggest magntude )
angels=np.zeros((fd.shape[0],fd.shape[1],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)
3- 卷积函数
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),np.pi/4,0.5,0 )
filt = cv2.filter2D(imgc,cv2.CV_64F,ker)
plt.imshow(filt,'gray')
结果:
你看到左边有 45 的边缘质量很好
谁能帮帮我,告诉我在这个问题中我应该做什么?
谢谢大家:)
编辑:
我搜索了另一种方法,我发现我可以使用多个方向的 gabor fiter bank 并在过滤图像中获得最佳分数,那么我如何从过滤图像中找到像素的最佳分数
这是当我使用具有 45,60,65,90,135 个角度的 gabor fiter bank 并将过滤后的图像划分为 16*16 并找到最高标准差时的输出(最佳分数 -> 我使用标准差作为分数)对于每个块并获得最佳过滤图像
所以你可以看到图像中有好的部分和坏的部分,我认为单独使用标准偏差在图像的某些部分是无效的,所以我的新问题是什么是最好的分数函数,它可以给我很好的输出部分图片
【问题讨论】:
-
能否请您按原样上传您的原始图像,而不是您在 Python 上显示的图像?
-
@Prefect 是的,当然
-
澄清一下,您是要解决输出的问题,还是要在过滤后的图像中找到最好的分数?
-
@Prefect 现在我想要过滤图像中最好的得分函数(我在上面编辑我的问题)
-
@Prefect 但是如果您有解决我的输出问题的解决方案(第一个问题),好的,请告诉我兄弟并建议我应该使用什么算法(过滤器组或方向图)
标签: opencv image-processing fingerprint image-enhancement gabor-filter