Numpy max pooling convolution

use*_*145 8 python numpy

编辑:

我真正想要做的是找到局部最大值,这在下面解释得很好,同样的解决方案也在这里解释:

http://scikit-image.org/docs/dev/auto_examples/plot_peak_local_max.html




看来你可以在Numpy 做线性卷积.

是否可以进行非线性最大池化卷积?使用NxM补丁并跨越输入图像,如果当前像素不是附近的最大像素,则归零?

所以非线性最大卷积就像这样,这是我的形象

  3 4 5 2 3
  3 5 1 2 7
  2 2 5 1 7
Run Code Online (Sandbox Code Playgroud)

给定2x2最大池值给出此输出

  0 0 5 0 0
  0 5 0 0 7
  0 0 5 0 7
Run Code Online (Sandbox Code Playgroud)

你有一个2x2补丁跨越图像,并将所有内容归零,只保留最大值.

Div*_*kar 8

你可以使用Scipy的maximum_filer -

from scipy.ndimage.filters import maximum_filter

arr*(arr == maximum_filter(arr,footprint=np.ones((3,3))))
Run Code Online (Sandbox Code Playgroud)

样品运行 -

In [19]: arr
Out[19]: 
array([[3, 4, 5, 2, 3],
       [3, 5, 1, 2, 7],
       [2, 2, 5, 6, 7]])

In [20]: arr*(arr == maximum_filter(arr,footprint=np.ones((3,3))))
Out[20]: 
array([[0, 0, 5, 0, 0],
       [0, 5, 0, 0, 7],
       [0, 0, 0, 0, 7]])
Run Code Online (Sandbox Code Playgroud)