This forum is disabled, please visit https://forum.opencv.org

1 | initial version |

Warping the image is a very expensive operation, but if accuracy is important you will have to use it. If can accept approximation of gradient than you can use formula you mentioned. This formula gives you a good approximation but don't think that the result is exact. Lets see an example to understand why this is happening:

Image 1: White and black regions separated by vertical line. Gradient in X direction is 1, Gradient in Y direction is 0. According to formula gradient in 45 degree direction is 1/sqrt(2), which is also correct. So far so good.

Image 2: White and black region separated by diagonal line. Gradient in X and Y directions is 1/sqrt(2). According to formula the gradient in 45 degree direction is 1/sqrt(sqrt(2)). Oops, it should be 1.

This approximation good for almost any practical purpose, so don't hesitate to use it.

2 | No.2 Revision |

Warping the image is a very expensive operation, but if accuracy is important you will have to use it. If you can accept approximation of gradient than you can use formula you mentioned. This formula gives you a good approximation but don't think that the result is exact. Lets see an example to understand why this is happening:

Image 1: White and black regions separated by vertical line. Gradient in X direction is 1, Gradient in Y direction is 0. According to formula gradient in 45 degree direction is 1/sqrt(2), which is also correct. So far so good.

Image 2: White and black region separated by diagonal line. Gradient in X and Y directions is 1/sqrt(2). According to formula the gradient in 45 degree direction is 1/sqrt(sqrt(2)). Oops, it should be 1.

This approximation good for almost any practical purpose, so don't hesitate to use it.

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.