Search code examples
opencvmathimage-processinggradient

The length of the gradient vector


It's just a simple thing that I need to clarify. I need a little refresh in mathematics: In a circle the length of the gradient should be the radius? Or do we use the gradient only to get the orientation?

I got to this question after I read about gradient in image processing: I've read this answer and this about how to get the image gradient and of course here.

I don't understand if the magnitude should stand for the number of pixels? or it just stand for the strength of the intensity changes in a specific point.

The following image is the magnitude of the gradient: the magnitude of the gradient:

I run the code and watched the magnitude in numbers, and the numbers clearly are not in the range of the image width\height.

Me, waiting to a simple clarify. Thanks!


Solution

  • Mathematically speaking, the gradient magnitude, or in other words the norm of the gradient vector, represents the derivative (i.e. the slope) of a 2D signal. This is quite clear in the definition given by Wikipedia:

    Gradient definition

    Here, f is the 2D signal and , ŷ are respectively unit vectors in the horizontal and vertical direction (i.e. orthonormal vectors).

    In the context of images, the 2D signal (i.e. the image) is discrete instead of being continuous, hence the derivative is approximated by the difference between the intensity of the current pixel and the intensity of the previous pixel, in the considered direction (actually, there are several ways to approximate the derivative, but let's keep it simple). Hence, we can approximate the gradient by the following quantity:

    discrete gradient's equation

    In this case, the gradient magnitude is the following:

    discrete gradient's magnitude

    To summarize, the gradient magnitude is a measure of the local intensity change at a given point and has not much to do with a radius, nor the width/height of the image.