3

I am trying to understand the scale argument in cv2.Sobel. With scale set to 1/8, I get the output as follows along x-axis:

enter image description here

But with scale = 10 or scale = 100, the output is very similar.

enter image description here

Both of the above images are the first order gradients along x-axis with the scale of 1/8 and 100 respectively.

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()

What does the argument scale do? How is it useful?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

1 Answers1

2

See you on C++ source from cv::Sobel in OpenCV:

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;
}

So, scale is a factor for Sobel kernel. If scale != 1 than kernell will be not ((-1 0 +1) (-2 0 +2) (-1 0 +1)). It will be ((-scale 0 +scale) (-2*scale 0 +2*scale) (-scale 0 +scale)).

Nuzhny
  • 1,869
  • 1
  • 7
  • 13