How to invoke OpenCV Sobel function to compute actual derivative of image given some kernel size? I.e. considering that image is a function of f(x, y) and x, y spans from [0, 0] to [width, height] in pixels?
dimg_x = cv2.Sobel(img, ddepth=-1, dx=1, dy=0, ksize=ksize)
Probably some scaling needs to be applied to gradient image, but I can't figure out how to compute it given kernel size.
You can use the scale argument of Sobel:
cv2.Sobel(img, dx=dx, dy=dy, ksize=ksize, scale=2**(2+dx+dy-ksize*2), ddepth=CV_32F)
When you scale the output that way, you typically do not want to have ddepth=-1 but rather get the result as floats or doubles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With