What is the difference between gradient and divergence?

I understood that gradient points in the direction of steepest ascent and divergence measures source strength. I couldn't relate this to the concept of divergence in image processing.

What is divergence in image processing, and how is it related to the gradient?

I have also asked a related question: https://dsp.stackexchange.com/questions/14606/anisotropic-diffusion. I couldn't understand the mathematics in it, but I roughly understood the theory. I need to understand the mathematics for the implementation.

I am trying to understand the equations in the above link: can you explain what can be concluded from these equations? How do they differ from each other?



2 Answers 2


The gradient is the directional rate of change of a scalar function in $\mathbb{R}^n$ whereas the divergence measures the amount of output vs input for a unit volume of a vector valued "flow" in $\mathbb{R}^n$.

The gradient has the magnitude of the rate of change in the direction of that change: $$ \nabla f(\vec{x})=\left\langle\frac{\partial}{\partial x_1}f,\frac{\partial}{\partial x_2}f,\dots,\frac{\partial}{\partial x_n}f\right\rangle $$ For example, the gradient of the distance from a given point is a vector field of unit length vectors pointing away from the given point.

Whereas the divergence is the measure of the amount of flow out of a given volume minus the amount of flow into a given volume: $$ \nabla\cdot\vec{f}(\vec{x})=\frac{\partial}{\partial x_1}f_1+\frac{\partial}{\partial x_2}f_2+\dots+\frac{\partial}{\partial x_n}f_n $$ For example, the divergence of a flow with no source or sink is $0$. If there is a net source, the divergence is positive and if there is a net sink the divergence is negative.

The Divergence of the Gradient

The $\color{#C00000}{\text{divergence}}$ of the $\color{#00A000}{\text{gradient}}$ is also called the $\color{#0000FF}{\text{Laplacian}}$: $$ \color{#C00000}{\nabla\cdot}\color{#00A000}{\nabla}=\color{#0000FF}{\Delta} $$ which is given by $$ \Delta f(\vec{x})=\frac{\partial^2}{\partial x_1^2}f+\frac{\partial^2}{\partial x_2^2}f+\dots+\frac{\partial^2}{\partial x_n^2}f $$ In one dimension, it is the second derivative. In higher dimensions it behaves in a similar manner: at a minimum point of $f$, $\Delta f\gt0$ and at a maximum point of $f$, $\Delta f\lt0$.

What your first equation says is that $$ \frac{\partial}{\partial t}I=c\Delta I $$ If $c\gt0$ then the diffusion is working to fill in depressions and tear down accumulations. If $c\lt0$, the diffusion has the opposite effect.

The isotropic diffusion acts the same (constant $c$) everywhere, whereas the anisotropic diffusion acts differently depending on the size of the gradient of the field.

Edge Stopping Function

The idea of an edge stopping function is to impede diffusion at an edge in an image (in a region where the magnitude of the gradient is large). That is, the function $g$ has a shape like

$\hspace{3.5cm}$diffusion coefficient

When the gradient is small, diffusion flows similarly to the isotropic case, but when the gradient is large (near an edge), diffusion stops. This allows detection of the edge.

  • 1
    $\begingroup$ Can you give an example ? Laymen sort of.. I couldn't understand it fully $\endgroup$
    – Premnath D
    Commented Feb 26, 2014 at 0:29
  • $\begingroup$ please see the update in my question $\endgroup$
    – Premnath D
    Commented Feb 26, 2014 at 0:49
  • $\begingroup$ @PremnathD: I have added some description, but I am working on some illustrations. $\endgroup$
    – robjohn
    Commented Feb 26, 2014 at 0:49
  • $\begingroup$ @PremnathD: I tried to describe the diffusions. I will have to work on the illustrations of gradients and divergences later. $\endgroup$
    – robjohn
    Commented Feb 26, 2014 at 1:26
  • $\begingroup$ Thank for your explanation. It helped me. My problem is how to relate divergence with the edges in the image .. Waiting for the illustrations.. Do it when you have time... Thank you again $\endgroup$
    – Premnath D
    Commented Feb 26, 2014 at 1:55

A glib answer is that "gradient" is a vector and "divergence" is a scalar. More specifically (and perhaps helpfully), the gradient vector points in the direction of the fastest (local) increase in the value of the (scalar) function. The divergence (of a vector field) provides a measure of how much "flux" (or flow) is passing through a surface surrounding a point in the field (positive for flow away from that point, negative for flow toward, zero for no net flow).

An example for gradient: the "distance from the origin" function, $ \ f(x) = \sqrt{x^2+y^2+z^2} \ $ has the gradient

$$ \nabla f \ = \ \frac{\langle \ x, y, z \ \rangle}{\sqrt{x^2+y^2+z^2}} \ , $$

which gives vectors pointing radially away from the origin, the "fastest" way to get farther from the origin.

An example for divergence: the vector function, $\overrightarrow{g} (x,y,z) = \langle x^2 , y^2 , z^2 \rangle \ , $ which has the divergence

$$ \nabla \centerdot \overrightarrow{g} \ = \ 2x + 2y + 2z \ , $$

which indicates that, for a quantity which is getting larger with increasing distance from the origin, the amount of "flow" outward through an (imaginary) surface at some radius from the origin is also getting "stronger".

These are formal definitions, but I'm afraid I'm not familiar with the context in which they appear in image processing.

  • 1
    $\begingroup$ Thank you very much for your efforts . your answer helped me $\endgroup$
    – Premnath D
    Commented Feb 26, 2014 at 1:58
  • $\begingroup$ I gave you a vote up since you simplified thing with your intuitive explanation. However, your formulation is problematic since the distance from the origin is clearly a function of $(x,y,z)$ and not $f(x)=\ldots$ $\endgroup$
    – havakok
    Commented Jun 13, 2020 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .