我在 Python 中尝试了 5 种不同的 Sobel 运算符实现,其中一种是我自己实现的,结果完全不同。
我的问题与this one类似,但我仍然不明白与其他实现的差异。
Sobel 算子的定义是否有任何一致意见,它是否总是与“图像梯度”同义?
甚至 Sobel 内核的定义因来源而异,根据维基百科,它是[[1, 0, -1],[2, 0, -2],[1, 0, -1]],但根据其他来源,它是[[-1, 0, 1],[-2, 0, 2],[-1, 0, 1]]。
这是我尝试不同技术的代码:
from scipy import ndimage
import numpy as np
import cv2 as cv
from scipy import ndimage
from PIL import Image, ImageFilter
img = np.random.randint(0, 255, [10, 10]).astype(np.uint8)
def sobel_x(img) :
return ndimage.convolve(img, np.array([[-1, 0, 1],[-2, 0, 2],[-1, 0, 1]]))
my_sobel = sobel_x(img)
_, numpy_sobel = …Run Code Online (Sandbox Code Playgroud)