-gradient

The gradient of an image displays the rate of change of the operand's intensity along the horizontal (left to right), vertical (top to bottom) or depth (front to back) axes. The graph on the left charts the intensity of a one dimensional bell curve image (red), the green curve charts the bell curve's rate of change (or slope). The gradient is closely related to the first derivative, which it approximates, and is computed by taking successive differences of neighboring pixels along a given directional axis. 

The format of the command is:

-gradient: axis,scheme

  1. axis: one of 'x', 'y', or 'z' and chooses a directional axis. With 'x', the command computes the gradient by taking successive differences of pixels, from left to right, along the horizontal direction. 'y' chooses successive differences along the vertical direction from top to bottom, and 'z' chooses successive differences along the depth direction from front (top) slices to rear (bottom) slices.
  2. scheme:can be:
    1. -1=backward
    2. 0=centered
    3. 1=forward
    4. 2=sobel
    5. 3=rotation-invariant (default)
    6. 4=deriche
    7. 5=vanvliet

and chooses among several different methods to estimate the gradient.

Both the axis and scheme parameters are optional. Without parameters, the command computes all significant 2d/3d components using a scheme of 3 (rotation invariant).

Vector (a.k.a. direction) fields

It is quite common to follow the -gradient command with -append c which folds the output images into one 2 or 3 channel image of a special character called a 2 or 3D direction field. Each pixel may be regarded as a vector and the overall image a vector field.

In the case of -gradient's output, the vector field encodes the pointwise direction and magnitude of intensity gradients observed in the original image.

Such vector fields may be visualized with -quiver, rendering the field with arrow markers, or -direction2rgb, rendering the field with color.  We may extract the vector lengths with -norm and their directions, or orientations with -orientation. The -divergence command estimates pointwise outflow and inflow of vector fields.

The -warp command employs 2D direction fields as the object controlling image distortion. The command -eigen2tensor takes pairs of vector fields and transforms them into tensor fields. In this operation, the first vector field contain pairs of eigenvalues and the second is a field of unit vectors (an orientation field), representing one of two eigenvectors per tensor. The other one  may be inferred as it points in a 90° direction from the first. Tensor fields are used in encoding image structure and making smoothing geometries

Examples:

A bell curve from above (cubic.png). The red curve in the graph at the beginning of this article is a horizontal section of this grayscale image, taken through the midpoint line.

Running: $ gmic cubic.png -gradient produces two gradient images, depicted on the right.

Horizontal gradient of the bell curve on the left (cubic.png). The green curve in the graph at the beginning of this article is a horizontal section of this image, taken along the midpoint line.

Gray maps to zero in this image and represents unchanging regions in cubic.png. Light gray and white represent positive values and regions of increasing intensity in cubic.png. Similarly dark gray and black represent negative values and regions of decreasing intensity.

Vertical gradient of the bell curve on the far left  (cubic.png). But for orientation, the particulars of this image are the same as the horizontal gradient on the immediate left.

A Isophysis tasmanica Tasmania, Australia. (isophysistasmanica.png)

$ gmic isophysistasmanica.png --luminance...

... -gradient[-1] xy,1 -a[-2,-1] c ...

We generate gradients in both the x and y directions and append these two images into the horizontal and vertical channels of a vector field.

... --norm[-1] -negative[-1] --unsharp[-1] 20% -cut[-1] 0,255...

We take the norm of this vector field, obtaining an image where dark lines trace the rapidly changing gradients of the original image.

Garry Osgood