Python中的离散拉普拉斯算子(del2等价物) [英] Discrete Laplacian (del2 equivalent) in Python

查看:70
本文介绍了Python中的离散拉普拉斯算子(del2等价物)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 Python/Numpy 等效的 Matlab (Octave) 离散拉普拉斯算子(函数)del2().我尝试了几个 Python 解决方案,但似乎没有一个与 del2 的输出匹配.在八度音阶上我有

I need the Python / Numpy equivalent of Matlab (Octave) discrete Laplacian operator (function) del2(). I tried couple Python solutions, none of which seem to match the output of del2. On Octave I have

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 上我尝试过

On Python I tried

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 表明它是一个拉普拉斯算子.我错过了什么吗?

So none of the outputs seem to match eachother. Octave code del2.m suggests that it is a Laplacian operator. Am I missing something?

推荐答案

也许您正在寻找 scipy.ndimage.filters.laplace().

Maybe you are looking for scipy.ndimage.filters.laplace().

这篇关于Python中的离散拉普拉斯算子(del2等价物)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆