我目前正在尝试使用我自己构建的拉普拉斯内核过滤图像。然而,当使用这个内核过滤输入图像时,与 SciPy 中的实现相比,它给出了意想不到的结果。
我构建的拉普拉斯核应该通过下图来验证
过滤图像的代码:
im = cv2.imread("test.png",0)
im = im.astype(np.float32)
def lkern(t=1.):
ax = np.arange(np.round(-5*np.sqrt(t),0),np.round(5*np.sqrt(t),0)+1)
xx, yy = np.meshgrid(ax, ax)
kernel = -1/(np.sqrt(2*np.pi*t)*t)*np.exp(-(xx**2+yy**2)/(2*t))+
(xx**2+yy**2)/(np.sqrt(2*np.pi*t)*t**2)*np.exp(-(xx**2+yy**2)/(2*t))
return kernel.astype(np.float)
t = 25**2/2
l = lkern(t)
L = cv2.filter2D(im/255,-1,l)
plt.figure()
plt.imshow(L,cmap="gray")
plt.show()
这导致
与 SciPy's 相比ndimage.gaussian_laplace
,结果应该是
这是非常不同的,我无法弄清楚如何正确地做到这一点。