我想为我的图像实现高斯滤波器的拉普拉斯算子。我测试了这两种方法,它给了我完全不同的答案。请告诉我我犯了哪个错误。在第一种方法中,我从它的函数中实现了 LOG 过滤器,而在第二种方法中,我使用了 opencv 函数。这是我的第一种方法的代码:
img = np.array(Image.open('Bi00069.bmp').convert('I;16'))
ddepth = cv2.CV_16U
kernel_size = 3
def gkern(l,sig):
ax = np.linspace(-(l - 1) / 2., (l - 1) / 2., l)
xx, yy = np.meshgrid(ax, ax)
kernel = (-1)/(np.pi*sig**4)*(1-(xx**2+yy**2)/(2*sig**2))*
np.exp(-0.5 * (np.square(xx) + np.square(yy)) / np.square(sig))
return kernel / np.sum(kernel)
img1 = signal.convolve2d(img,gkern(5,5),mode='same',
boundary='fill', fillvalue=0)
plt.imshow(G_img2,cmap='gray')
第二个实现是:
src = cv2.GaussianBlur(img, (3, 3), 5,cv2.BORDER_DEFAULT)
img2 = cv2.Laplacian(src, ddepth, ksize=kernel_size)
plt.imshow(img2,cmap='gray')
我认为根据结果,第二张图片应该是正确的。但我不知道我的第一次实施有什么问题。请帮助我。