Python Scipy ndimage中值滤波器原点

Python Scipy ndimage中值滤波器原点,python,numpy,scipy,median,ndimage,Python,Numpy,Scipy,Median,Ndimage,我有一个二进制数组,比如说,a=np.random.binomian(n=1,p=1/2,size=(9,9))。我使用3x3内核对它执行中值滤波,比如说,b=nd.median\u filter(a,3)。我希望这将基于像素及其八个相邻像素执行中值滤波。但是,我不确定内核的位置。他说, 原点:标量,可选 The origin parameter controls the placement of the filter. Default 0.0. 如果默认值为零,则应将当前像素和3 x 3网格

我有一个二进制数组,比如说,
a=np.random.binomian(n=1,p=1/2,size=(9,9))
。我使用
3x3
内核对它执行中值滤波,比如说,
b=nd.median\u filter(a,3)
。我希望这将基于像素及其八个相邻像素执行中值滤波。但是,我不确定内核的位置。他说,

原点:标量,可选

The origin parameter controls the placement of the filter. Default 0.0.
如果默认值为零,则应将当前像素和
3 x 3
网格移到右侧和底部,是否?默认值不应该是
示意图的中心吗?在我们的
3x3
示例中,哪个对应于
(1,1)
,而不是
(0,0)


谢谢。

origin说它只接受标量,但对我来说,它也接受类似数组的输入,这也是函数的情况。传递0确实是示意图的中心。原点的值相对于中心。对于3x3封装外形,可以指定值-1.0到1.0。这里有一些例子。请注意,在未指定原点的示例中,过滤器按预期居中

import numpy as np
import scipy.ndimage

a= np.zeros((5, 5))
a[1:4, 1:4] = np.arange(3*3).reshape((3, 3))

default_out = scipy.ndimage.median_filter(a, size=(3, 3))
shift_pos_x = scipy.ndimage.median_filter(a, size=(3, 3), origin=(0, 1))
shift_neg_x = scipy.ndimage.median_filter(a, size=(3, 3), origin=(0, -1))

print(a)
print(default_out)
print(shift_pos_x)
print(shift_neg_x)
输出:

输入阵列:

[[ 0.  0.  0.  0.  0.]
 [ 0.  0.  1.  2.  0.]
 [ 0.  3.  4.  5.  0.]
 [ 0.  6.  7.  8.  0.]
 [ 0.  0.  0.  0.  0.]]
集中输出:

[[ 0.  0.  0.  0.  0.]
 [ 0.  0.  1.  0.  0.]
 [ 0.  1.  4.  2.  0.]
 [ 0.  0.  4.  0.  0.]
 [ 0.  0.  0.  0.  0.]]
右移输出:

[[ 0.  0.  0.  0.  0.]
 [ 0.  0.  0.  1.  0.]
 [ 0.  0.  1.  4.  2.]
 [ 0.  0.  0.  4.  0.]
 [ 0.  0.  0.  0.  0.]]
左移输出:

[[ 0.  0.  0.  0.  0.]
 [ 0.  1.  0.  0.  0.]
 [ 1.  4.  2.  0.  0.]
 [ 0.  4.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.]]