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.
The gradient of an image is a vector of its partials:2: 165
where:
The derivative of an image can be approximated by finite differences. If central difference is used, to calculate ∂ f ∂ y {\displaystyle \textstyle {\frac {\partial f}{\partial y}}} we can apply a 1-dimensional filter to the image A {\displaystyle \mathbf {A} } by convolution:
where ∗ {\displaystyle *} 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
can be used. The gradient direction can be calculated by the formula:3: 706
and the magnitude is given by:4
Jacobs, David. "Image gradients." Class Notes for CMSC 426 (2005) http://www.cs.umd.edu/~djacobs/CMSC426/ImageGradients.pdf ↩
Gonzalez, Rafael; Richard Woods (2008). Digital Image Processing (3rd ed.). Upper Saddle River, New Jersey: Pearson Education, Inc. ISBN 978-0-13-168728-8. 978-0-13-168728-8 ↩
"Edges: Gradient Edge Detection". homepages.inf.ed.ac.uk. Retrieved 2023-04-09. https://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MARBLE/low/edges/gradient.htm ↩