gpt4 book ai didi

python - cv2.Sobel 中的比例是什么意思?

转载 作者:太空宇宙 更新时间:2023-11-03 23:08:08 26 4
gpt4 key购买 nike

我试图理解 cv2.Sobel 中的 scale 参数.将 scale 设置为 1/8,我沿 x 轴得到如下输出:

enter image description here

但是对于 scale = 10 或 scale = 100,输出非常相似。

enter image description here

上面两幅图都是沿x轴的一阶梯度,比例分别为1/8和100。

import cv2

filename = "./images/cube.jpg"

img = cv2.imread(filename,0)

sx = cv2.Sobel(img, cv2.CV_64F, 1,0, ksize=3, scale= 1/8)


cv2.imshow("sx", sx)

if cv2.waitKey(0) & 0xff == 27:
cv2.destroyAllWindows()

参数 scale 有什么作用?它有什么用?

最佳答案

在 OpenCV 中的 cv::Sobel 的 C++ 源代码上见:

Mat kx, ky;
getDerivKernels( kx, ky, dx, dy, ksize, false, ktype );
if( scale != 1 )
{
// usually the smoothing part is the slowest to compute,
// so try to scale it instead of the faster differentiating part
if( dx == 0 )
kx *= scale;
else
ky *= scale;
}

因此,尺度是 Sobel 核的一个因素。如果 scale != 1 则 kerell 将不是 ((-1 0 +1) (-2 0 +2) (-1 0 +1))。它将是 ((-scale 0 +scale) (-2*scale 0 +2*scale) (-scale 0 +scale)).

关于python - cv2.Sobel 中的比例是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54849260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com