Image gradient

From HandWiki
Short description: Directional change in the intensity or color in an image
Two types of gradients, with blue arrows to indicate the direction of the gradient. Dark areas indicate higher values
A blue and green color gradient.

An image gradient is a directional change in the intensity or color in an image. The gradient of the image is one of the fundamental building blocks in image processing. For example, the Canny edge detector uses image gradient for edge detection. In graphics software for digital image editing, the term gradient or color gradient is also used for a gradual blend of color which can be considered as an even gradation from low to high values, as used from white to black in the images to the right. Another name for this is color progression.

Mathematically, the gradient of a two-variable function (here the image intensity function) at each image point is a 2D vector with the components given by the derivatives in the horizontal and vertical directions. At each image point, the gradient vector points in the direction of largest possible intensity increase, and the length of the gradient vector corresponds to the rate of change in that direction.[1]

Since the intensity function of a digital image is only known at discrete points, derivatives of this function cannot be defined unless we assume that there is an underlying continuous intensity function which has been sampled at the image points. With some additional assumptions, the derivative of the continuous intensity function can be computed as a function on the sampled intensity function, i.e., the digital image. Approximations of these derivative functions can be defined at varying degrees of accuracy. The most common way to approximate the image gradient is to convolve an image with a kernel, such as the Sobel operator or Prewitt operator.

Image gradients are often utilized in maps and other visual representations of data in order to convey additional information. GIS tools use color progressions to indicate elevation and population density, among others.

Computer vision

Left: Black and white picture of a cat. Center: The same cat, displayed in a gradient image in the x direction. Appears similar to an embossed image. Right: The same cat, displayed in a gradient image in the y direction. Appears similar to an embossed image.
On the left, an intensity image of a cat. In the center, a gradient image in the x direction measuring horizontal change in intensity. On the right, a gradient image in the y direction measuring vertical change in intensity. Gray pixels have a small gradient; black or white pixels have a large gradient.

In computer vision, image gradients can be used to extract information from images. Gradient images are created from the original image (generally by convolving with a filter, one of the simplest being the Sobel filter) for this purpose. Each pixel of a gradient image measures the change in intensity of that same point in the original image, in a given direction. To get the full range of direction, gradient images in the x and y directions are computed.

One of the most common uses is in edge detection. After gradient images have been computed, pixels with large gradient values become possible edge pixels. The pixels with the largest gradient values in the direction of the gradient become edge pixels, and edges may be traced in the direction perpendicular to the gradient direction. One example of an edge detection algorithm that uses gradients is the Canny edge detector.

Image gradients can also be used for robust feature and texture matching. Different lighting or camera properties can cause two images of the same scene to have drastically different pixel values. This can cause matching algorithms to fail to match very similar or identical features. One way to solve this is to compute texture or feature signatures based on gradient images computed from the original images. These gradients are less susceptible to lighting and camera changes, so matching errors are reduced.

Mathematics

The gradient of an image is a vector of its partials:[2]:165

[math]\displaystyle{ \nabla f=\begin{bmatrix} g_{x} \\ g_{y} \end{bmatrix} = \begin{bmatrix} \frac{\partial f}{\partial x} \\ \frac{\partial f}{\partial y} \end{bmatrix} }[/math],

where:

[math]\displaystyle{ \textstyle\frac{\partial f}{\partial x} }[/math] is the derivative with respect to x (gradient in the x direction)
[math]\displaystyle{ \textstyle\frac{\partial f}{\partial y} }[/math] is the derivative with respect to y (gradient in the y direction).

The derivative of an image can be approximated by finite differences. If central difference is used, to calculate [math]\displaystyle{ \textstyle\frac{\partial f}{\partial y} }[/math] we can apply a 1-dimensional filter to the image [math]\displaystyle{ \mathbf{A} }[/math] by convolution:

[math]\displaystyle{ \frac{\partial f}{\partial y} = \begin{bmatrix} -1 \\ +1 \end{bmatrix} * \mathbf{A} }[/math]

where [math]\displaystyle{ * }[/math] denotes the 1-dimensional convolution operation. This 2×1 filter will shift the image by half a pixel. To avoid this, the following 3×1 filter

[math]\displaystyle{ \begin{bmatrix} -1 \\ 0 \\ +1 \end{bmatrix} }[/math]

can be used. The gradient direction can be calculated by the formula:[2]:706

[math]\displaystyle{ \theta = \operatorname{tan{^-}{^1}} \left [ \frac{g_{y}}{g_{x}} \right ] }[/math],

and the magnitude is given by:[3]

[math]\displaystyle{ \sqrt{g_{y}^{2} + g_{x}^{2}} }[/math]

See also

References

  1. Jacobs, David. "Image gradients." Class Notes for CMSC 426 (2005)
  2. 2.0 2.1 Gonzalez, Rafael; Richard Woods (2008). Digital Image Processing (3rd ed.). Upper Saddle River, New Jersey: Pearson Education, Inc.. ISBN 978-0-13-168728-8. http://www.imageprocessingplace.com/DIP-3E/dip3e_main_page.htm. 
  3. "Edges: Gradient Edge Detection". https://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MARBLE/low/edges/gradient.htm. 

Further reading

External links