我需要 Python / Numpy 等价的 Matlab(八度)离散拉普拉斯算子(函数)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]]
所以没有一个输出似乎相互匹配。Octave 代码 del2.m 表明它是一个拉普拉斯算子。我错过了什么吗?