||Download this example as a Mathematica notebook.
Edge detection is a problem of fundamental importance in image analysis. In typical images,
edges characterize object boundaries and are therefore useful for segmentation, registration,
and identification of objects in a scene. In this section, the construction, characteristics,
and performance of a number of gradient and zero-crossing edge operators will be presented.
An edge is a jump in intensity. The cross section of an edge has the shape of a ramp.
An ideal edge is a discontinuity (i.e., a ramp with an infinite slope). The first derivative
assumes a local maximum at an edge. For a continuous image , where x and y are the row and column coordinates
respectively, we typically consider the two directional derivatives
and . Of particular interest in edge detection are two functions
that can be expressed in terms of these directional derivatives: the gradient magnitude
and the gradient orientation. The gradient magnitude is defined as
and the gradient orientation is given by
Local maxima of the gradient magnitude identify edges in . When the first derivative achieves a maximum, the second derivative
is zero. For this reason, an alternative edge-detection strategy is to locate zeros of the
second derivatives of .
The differential operator used in these so-called zero-crossing edge detectors is the Laplacian
This loads the package.
The following demonstration illustrates the principles of edge detection. We model a
one-dimensional edge with a simple smooth function, for example,
. As the parameter alpha increases,
the slope of the edge gets steeper. Here we use .
This evaluates and plots the first and second derivatives of our "edge" function.
As expected, the result shows that maxima of the first derivative (green) and zero crossings of
the second derivative (blue) locate the center of our model edge. It can also be shown
that the zero crossings are independent of the steepness of the transition, while the
gradient magnitude is directly related to the edge slope.
In practice, finite difference approximations of first-order
directional derivatives are used. These are represented by a pair of
masks, say and . Formally these are linear-phase FIR filters. A
convolution of the image with
and gives two directional derivative
and respectively. The gradient image is
traditionally calculated as ,
or alternatively using
. A pixel location is declared an edge location if the value of nabla (at point x, y)
exceeds some threshold. The locations of all edge points constitutes an edge map.
The selection of a threshold value is an important design decision that depends on
a number of factors, such as image brightness, contrast, level of noise, and even
edge direction. Typically, the threshold is selected following an analysis of the gradient
image histogram. It is sometimes useful to calculate edge-direction information.
This is given by .
Option of EdgeMagnitude
The method of computing the gradient magnitude is user selectable with option
Gradient Edge Operators
A number of commonly used gradient operators are available.
Here are two common gradient edge operators.
Note that each of the Sobel edge masks is a combination of a digital differentiator
in one of the spatial directions and a smoothing operator in the other.
Here we read one of the example images and consider a subregion of the image.
We compute the gradient magnitude and edge direction using the Sobel mask.
To recover the edges, the gradient image must be segmented using a global or
local (i.e., adaptive) threshold operator. The choice of a threshold value
determines the resulting segmentation and, therefore, the perceived quality of the edge
detector. It is useful to consider the cumulative histogram of the gradient image in
selecting an appropriate threshold value. Here we calculate the histogram and cumulative
histogram of the gradient magnitude image. In a typical approach, the top 10 to 20
percent of the largest gradient values are selected as edge points. This is easily done
based on an investigation of the cumulative histogram.
The threshold can now be estimated visually or even calculated from the cumulative
histogram by setting a threshold at the 80 percent level.
We display the edge maps for three selected threshold values.
Based on visual inspection of the edge maps, it seems reasonable to accept the
threshold value of t.
A zero-crossing edge operator was originally proposed by Marr and Hildreth .
They suggested that in order to effectively detect intensity changes (edges),
the operator needs to have two characteristics. First, it must be a differential operator,
taking either a first or second spatial derivative of the image. Second, it should be
capable of being tuned to act at any desired scale so that large filters can be used to
detect blurry shadow edges, and small ones can be used to detect sharply focused fine
detail in the image. This led to the so-called Laplacian-of-Gaussian edge operator.
This is a compound operator that combines a smoothing operation, using a
Gaussian-shaped, linear-phase FIR filter, with a differentation operation, using a discrete
Laplacian. The edges are identified by the location of zero crossings (recall that
the second derivative changes sign in the vicinity of maxima of the first derivative).
Smoothing and Differentiating Filters
LaplacianFilter returns a number of common FIR filter approximations
to the Laplacian operator. The default argument value
() returns the minimum-variance discrete
Laplacian subject to the conditions that pixel noise is uncorrelated and has uniform variance .
The Laplacian is the lowest-order isotropic (i.e., orientation-independent) operator.
This computes the Laplacian of the example image.
This shows the original and filtered images.
The zero crossings are clearly visible as they occur at the border between bright and
dark areas of the Laplacian image. The midtones cover areas of small responses to the
Laplacian operator, which corresponds to uniform (flat) brightness areas of the original image.
In order to mitigate the increase in pixel noise due to differentiation,
the image is filtered with a lowpass filter. This is accomplished by a Gaussian-shaped,
linear-phase FIR filter. Since convolution is associative and commutative, the two-step
sequence can be reduced to one step by constructing a compound operator.
is a compound operator whose values are samples of the Laplacian of the
bivariate Gaussian function with variance .
Here we set
and plot both the resulting function as a surface and the functions profile for
Here we filter the example image using LoGFilter.
Shown below are the results of convolving the example image with a Laplacian-of-Gaussian
filter followed by zero-crossing detection. The latter is implemented with the function
 Gonzalez, R. C., and Woods, R. E. Digital Image Processing (Reading, MA:
 Marr, D., and Hildreth, E. "Theory of Edge Detection," Proceedings of the Royal Society
London 207 (1980) 187-217.
 Haralick, R. M., and Shapiro, L. G. Computer and Robot Vision, vol.1
(Reading, MA: Addison-Wesley, 1992).