scipy.ndimage.filter.laplace()中使用的拉普拉斯掩码/内核是什么?

icy*_*ypy 4 python numpy image-processing filter scipy

一个简单的水平/垂直拉普拉斯掩模在内核的中心有4个(图的左侧).类似地,对角线特征敏感的拉普拉斯掩模在内核的中心有8个(图中的右侧).什么面具scipy使用,我可以选择使用哪个?

在此输入图像描述

ray*_*ica 10

一个简单的检查是声明一个零的二维数组,除了中心的一个系数设置为1,然后将laplace函数应用于它.具有过滤功能的属性是,如果您提交带有单个1的图像,则输出将是实际过滤器本身位于1所在位置 - 查找脉冲响应 ...或更具体地说,点扩展函数.

如果你这样做,那么你将看到在运行该laplace方法后它的样子:

In [13]: import numpy as np

In [14]: import scipy.ndimage.filters

In [15]: A = np.zeros((5,5))

In [16]: A[2,2] = 1

In [17]: B = scipy.ndimage.filters.laplace(A)

In [18]: A
Out[18]:
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

In [19]: B
Out[19]:
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  1., -4.,  1.,  0.],
       [ 0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])
Run Code Online (Sandbox Code Playgroud)

因此,它是第一个正在使用的内核,但请注意符号的变化.中心系数为正,而其他系数为负.


但是,如果你真的想知道底层发生了什么,请查看该函数的文档:http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.filters.laplace.html - 指向函数定义源的链接:

https://github.com/scipy/scipy/blob/v0.16.0/scipy/ndimage/filters.py#L396

您需要查看的相关代码如下:

def derivative2(input, axis, output, mode, cval):
    return correlate1d(input, [1, -2, 1], axis, output, mode, cval, 0)
return generic_laplace(input, derivative2, output, mode, cval)
Run Code Online (Sandbox Code Playgroud)

基本上,[1, -2, 1]正如correlate1d函数所做的那样,1D内核被独立地应用于每个维度......所以首先是行,然后是列.这实际上会计算您在问题中看到的第一个蒙版.