下面是测试代码
import numpy as np
import cv2
from scipy.ndimage import generic_filter
def sobel_x_filter(P):
return (P[2] + 2 * P[6] + P[7]) - (P[0] + 2 * P[3] + P[6])
matrix = np.ones((100, 100))
matrix[1, 2] = 2
cv2_result = cv2.Sobel(np.float32(matrix), cv2.CV_32F, 1, 0)
generic_filter_result = generic_filter(matrix, sobel_x_filter, (3, 3))cv2_result[1, :]是[ 0., 2., 0., -2., 0., ..., 0.],
但是generic_filter_result[1, :]是[0., 0., 0., -2., 0., 0., 0., ..., 0.]。
我很困惑为什么结果会不一样,我尝试将函数generic_filter中的mode参数更改为mirror或wrap,但它仍然产生与以前相同的结果,并且与cv2.Sobel的结果不一致
发布于 2019-01-12 00:41:03
我认为你的函数应该是:
def sobel_x_filter(P):
return (P[2] + 2 * P[5] + P[8]) - (P[0] + 2 * P[3] + P[6])https://stackoverflow.com/questions/54133727
复制相似问题