我的代码说“过滤器权重数组的形状不正确”,我不知道如何解决?我知道图片和过滤器必须采用相同的格式,但是我无法弄清楚我做错了什么。
用Python的Im编程,Numpy
pic = scipy.ndimage.imread('Somepicture')
rgb_array = np.mean(pic, -1)
plt.imshow(rgb_array, cmap="gray")
#plt.show()
Gx = np.array([[-1,0,1], [-2,0,3], [-1,0,1]])
Gy = np.array([[-1,-2,-1], [0,0,0], [1,2,1]])
# Sobel X filter
dx = ndimage.convolve(pic, Gx, mode='constant')
# Sobel Y filter
dy = ndimage.convolve(pic, Gy, mode='constant')
s = math.sqrt((dx) ** 2 + (dy) ** 2)
def falta_pixels():
for row in pic:
for pixel in row:
s[row][pixel] = math.sqrt((dx[row][pixel]) ** 2 + (dy[row][pixel]) ** 2)
return s
plt.plot(s)
plt.show()