一个简单的水平/垂直拉普拉斯掩模在内核的中心(图的左侧)有 4 个。类似地,对对角线特征敏感的拉普拉斯掩码在内核的中心(下图中的右侧)有 8 个。 scipy
使用的是什么掩码,我可以选择使用哪个掩码吗?
最佳答案
一个简单的检查是声明一个二维零数组,除了中心的一个系数设置为 1,然后对其应用 laplace
函数。具有过滤功能的属性是,如果您提交带有单个 1 的图像,则输出将是实际过滤器本身,以 1 所在的位置为中心 - 查找 impulse response ...或者更具体地说,Point Spread Function .
如果你这样做,那么在运行 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.]])
因此,它是第一个正在使用的内核,但请注意符号的变化。中心系数为正,其余系数为负。
但是,如果您真的想知道引擎盖下发生了什么,请查看有关函数的文档: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)
基本上,[1, -2, 1]
的一维内核被独立应用于每个维度,正如 correlate1d
函数所做的那样...所以行首先,然后是列。这实际上计算了您在问题中看到的第一个掩码。
关于python - scipy.ndimage.filter.laplace() 中使用的拉普拉斯掩码/内核是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32768407/