【发布时间】:2017-12-28 13:04:19
【问题描述】:
假设我加载了一个图像f(x,y),例如,
我想计算图像f 的高斯导数∂/∂x ∂/∂y G*f,其中G 是高斯滤波器,* 表示卷积。使用 Scipy 很容易做到这一点:
from scipy.ndimage.filters import gaussian_filter
imshow(gaussian_filter(g, sigma, order=1))
使用sigma=50 会产生以下结果:
现在,出于应用原因,我需要使用 mode='constant' 进行计算:
imshow(gaussian_filter(g, sigma, order=1, mode='constant', cval=0))
不过,结果看起来还是合理的:
但是,请注意我图像的背景强度是1,而不是0。因此,使用cval=1应该是合理的:
imshow(gaussian_filter(g, sigma, order=1, mode='constant', cval=1))
现在这是出乎意料的!这个结果没有意义吧?
为了记录,我还检查了偏微分 ∂/∂x G*f 和 ∂/∂y G*f。而
imshow(gaussian_filter(g, sigma, order=[0, 1], mode='constant', cval=1)
看起来很合理
另一个
imshow(gaussian_filter(g, sigma, order=[1, 0], mode='constant', cval=1)
没有:
这是为什么呢?
【问题讨论】:
-
真的看起来像一个错误。尝试使用通用卷积运算符并给它你想要的内核。你在 SciPy 中有类似的东西吗?
标签: python image-processing scipy