20

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?

understanding

2 Answers2

28

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.

robjohn
  • 353,833
  • 1
    Can you give an example ? Laymen sort of.. I couldn't understand it fully – Premnath D Feb 26 '14 at 00:29
  • please see the update in my question – Premnath D Feb 26 '14 at 00:49
  • @PremnathD: I have added some description, but I am working on some illustrations. – robjohn Feb 26 '14 at 00:49
  • @PremnathD: I tried to describe the diffusions. I will have to work on the illustrations of gradients and divergences later. – robjohn Feb 26 '14 at 01:26
  • 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 – Premnath D Feb 26 '14 at 01:55
  • What do you mean by "unit volume of a vector valued flow"? What do you mean by 1. unit, 2, volume, 3. vector valued flow? What do you mean by source and sink in "divergence of a flow with no source or sink is 0"? You say "In one dimension, it is the second derivative". How can the sum of partial derivatives in this case be the second derivative? In one dimension of what? The domain of the function? –  Mar 06 '19 at 15:22
  • You may be reading that sentence wrong: 'the amount of output vs input for a unit volume of a vector valued "flow"' means take a vector valued field (usually representing a flow) take an infinitesimal cube, measure the net amount of the flow out of that cube (flow out minus the flow in) and divide by the volume of that cube (giving the equivalent flow out of a unit cube). – robjohn Mar 06 '19 at 16:06
12

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.

colormegone
  • 11,002
  • 1
    Thank you very much for your efforts . your answer helped me – Premnath D Feb 26 '14 at 01:58
  • 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$ – havakok Jun 13 '20 at 12:12