Image Gradient - Math

Math

The gradient of an image is given by the formula :

,

where :

is the gradient in the x direction
is the gradient in the y direction.

The gradient direction can be calculated by the formula :

.

An example of a gradient patch to use is

-1
1

However this will shift the image by half a pixel. The filter

-1
0
1

provides a good median

Read more about this topic:  Image Gradient