这是预期的结果吗高斯滤波器?

2024-04-26 06:32:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用gaussian_filterscipy.ndimage计算离散导数,因此输出在边界条件下呈现出一些奇怪的行为。代码如下:

from scipy import ndimage
import numpy as np
import matplotlib.pyplot as plt

y = np.linspace(0.2*np.pi,0.7*np.pi,100)
U = np.sin(y)


sg = 1
Uy  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='constant',cval=0)
Uy2  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='nearest')
Uy3  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='reflect')
Uy4  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='mirror')
Uy5  = ndimage.gaussian_filter1d(U, sigma=sg,order=1,mode='wrap')


fig,(a1,a2) = plt.subplots(1,2)
a1.plot(U , y,label='data')
a2.plot(Uy, y,label='constant')
a2.plot(Uy2,y,label='nearest')
a2.plot(Uy3,y,label='reflect')
a2.plot(Uy4,y,label='mirror')
a2.plot(Uy5,y,label='wrap')
a1.legend(loc='best')
a2.legend(loc='best')

enter image description here

怎么了?恒定模式应导致boudary上的cval?这是预期的结果吗?在


Tags: importa2plotmodea1asnporder