我在这里阅读了该函数的 scipy 文档:scipy.ndimage.uniform_filter1d。然而,当我尝试使用它时,我无法理解它的工作原理。我阅读了文档,在 Python Shell 中运行了该示例,使用了我自己的示例,但仍然没有进展。例如:
>>> from scipy.ndimage import uniform_filter1d
>>> uniform_filter1d([2, 8, 0, 4, 1, 9, 9, 0], size=3)
array([4, 3, 4, 1, 4, 6, 6, 3])
>>> uniform_filter1d([1, 2, 3, 4, 5, 6, 7, 8], size=3)
array([1, 2, 3, 4, 5, 6, 7, 7])
Run Code Online (Sandbox Code Playgroud)
当我看到第二个数组的输出时,感觉这个函数保留了数组的大部分元素。然而,在第二个示例中,感觉就像除了 4 和 1 之外,输出数组中的所有其他元素都是全新的。
因此,我希望您能帮助我了解此功能的工作和使用。
Ozg*_*gci 10
这个过滤器的作用是,根据大小,取每个像素与其相邻像素的算术平均值。大小是计算算术平均值的子数组的大小。没有足够邻居的像素的标准是反射。让我们来看看它的过程:
uniform_filter1d([1,2,3,4,5,6], size=3)
[1,2,3,4,5,6] # index 0, Reflect 1 : [1,1,2] -> average: 4/3 = 1
[1,2,3,4,5,6] # index 1, [1,2,3] -> average: 6/3 = 2
[1,2,3,4,5,6] # index 2, [2,3,4] -> average: 9/3 = 3
[1,2,3,4,5,6] # index 3, [3,4,5] -> average: 12/3 = 4
[1,2,3,4,5,6] # index 4, [4,5,6] -> average: 15/3 = 5
[1,2,3,4,5,6] # index 5, Reflect 6 : [5,6,6] -> average: 17/3 = 5
Result: [1,2,3,4,5,5]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1333 次 |
| 最近记录: |