最近在学convolution
使用numpy 跟 scipy来练习一下
但是遇到一个问题
程式码如下:
import numpy as np
from scipy import signal as sig
data = np.array([[0, 88, 0],
[105, 255, 55],
[0, 40, 0]])
G_x = sig.convolve2d(data, np.array([[-1], [0], [1]]), mode='valid')
G_y = sig.convolve2d(data, np.array([[1, 0, -2]]), mode='valid')
执行出来的结果是
G_x is [[ 0 48 0]]
G_y is
[[ 0]
[-155]
[ 0]]
但是,我自己预期是
Gx应该是
[0, 88, 0] [-1]
[105, 255, 55] 跟 [0]
[0, 40, 0] [1]
= [-1x0+0x105+1x0, -1x88+0x255+1x40, -1x0+0x55+1x0]
= [0, -48, 0]
而Gy则是
[0, 88, 0]
[105, 255, 55] 跟 [1, 0, -2]
[0, 40, 0]
[ 1x0 + 0x88 + -2x0 ] [0]
= [ 1x105 + 0x255 + -2x55 ] = [-5]
[ 1x0 + 0x40 + -2x0 ] [0]
不知道是我哪里理解错误了
麻烦各位高手指点一下了
感谢