我需要 Matlab (Octave) 离散拉普拉斯算子 (函数) 的 Python / Numpy 等效项del2()
。我尝试了几个Python解决方案,其中没有一个与输出匹配del2
。在八度上我有
image = [3 4 6 7; 8 9 10 11; 12 13 14 15;16 17 18 19]
del2(image)
这给出了结果
0.25000 -0.25000 -0.25000 -0.75000
-0.25000 -0.25000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000
0.25000 0.25000 0.00000 0.00000
在Python上我尝试过
import numpy as np
from scipy import ndimage
import scipy.ndimage.filters
image = np.array([[ 3, 4, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19]])
stencil = np.array([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])
print ndimage.convolve(image, stencil, mode='wrap')
这给出了结果
[[ 23 19 15 11]
[ 3 -1 0 -4]
[ 4 0 0 -4]
[-13 -17 -16 -20]]
我也尝试过
scipy.ndimage.filters.laplace(image)
这给出了结果
[[ 6 6 3 3]
[ 0 -1 0 -1]
[ 1 0 0 -1]
[-3 -4 -4 -5]]
因此,所有输出似乎都不匹配。倍频代码del2.m
表明它是拉普拉斯算子。我错过了什么吗?