【问题标题】:What does scale mean in cv2.Sobel?cv2.Sobel 中的比例是什么意思?
【发布时间】:2019-07-17 20:33:54
【问题描述】:

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

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

以上两幅图都是沿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 有什么作用?有什么用?

【问题讨论】:

    标签: python opencv image-processing computer-vision sobel


    【解决方案1】:

    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 则 kernell 将不是 ((-1 0 +1) (-2 0 +2) (-1 0 +1))。它将是 ((-scale 0 +scale) (-2*scale 0 +2*scale) (-scale 0 +scale))。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-21
      • 2019-09-11
      • 2021-09-15
      • 2022-06-16
      • 2018-12-10
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多