Edge Detection Techniques
Edge Detection Techniques
1. Sobel Operator:
The operator consists of a pair of 3×3 convolution kernels as shown in Figure 1. One kernel is
simply the other rotated by 90°.
These kernels are designed to respond maximally to edges running vertically and horizontally
relative to the pixel grid, one kernel for each of the two perpendicular orientations. The kernels
can be applied separately to the input image, to produce separate measurements of the gradient
component in each orientation (call these Gx and Gy). These can then be combined together to
find the absolute magnitude of the gradient at each point and the orientation of that gradient. The
gradient magnitude is given by:
The angle of orientation of the edge (relative to the pixel grid) giving rise to the spatial gradient is
given by: θ = arctan(Gy / Gx).
2. Prewitt’s Operator:
Prewitt operator is similar to the Sobel operator and is used for detecting vertical and horizontal
edges in images.
These kernels are designed to respond maximally to edges running at 45° to the pixel grid, one
kernel for each of the two perpendicular orientations. The kernels can be applied separately to the
input image, to produce separate measurements of the gradient component in each orientation (call
these Gx and Gy). These can then be combined together to find the absolute magnitude of the
gradient at each point and the orientation of that gradient. The gradient magnitude is given by:
The angle of orientation of the edge giving rise to the spatial gradient (relative to the pixel grid
orientation) is given by: θ = arctan(Gy /Gx) − 3π 4.
Step 1: In order to implement the canny edge detector algorithm, a series of steps must be followed. The
first step is to filter out any noise in the original image before trying to locate and detect any edges. And
because the Gaussian filter can be computed using a simple mask, it is used exclusively in the Canny
algorithm. Once a suitable mask has been calculated, the Gaussian smoothing can be performed using
standard convolution methods. A convolution mask is usually much smaller than the actual image. As a
result, the mask is slid over the image, manipulating a square of pixels at a time. The larger the width of
the Gaussian mask, the lower is the detector's sensitivity to noise. The localization error in the detected
edges also increases slightly as the Gaussian width is increased.
Step 2: After smoothing the image and eliminating the noise, the next step is to find the edge strength by
taking the gradient of the image. The Sobel operator performs a 2-D spatial gradient measurement on an
image. Then, the approximate absolute gradient magnitude (edge strength) at each point can be found.
The Sobel operator uses a pair of 3x3 convolution masks, one estimating the gradient in the x-direction
(columns) and the other estimating the gradient in the y-direction (rows). They are shown below:
The magnitude, or edge strength, of the gradient is then approximated using the formula:
|G| = |Gx| + |Gy|
Step 3: The direction of the edge is computed using the gradient in the x and y directions. However,
an error will be generated when sum X is equal to zero. So, in the code there has to be a restriction
set whenever this takes place. Whenever the gradient in the x direction is equal to zero, the edge
direction has to be equal to 90 degrees or 0 degrees, depending on what the value of the gradient
in the y-direction is equal to. If GY has a value of zero, the edge direction will equal 0 degrees.
Otherwise the edge direction will equal 90 degrees. The formula for finding the edge direction is
just:
Theta = invtan (Gy / Gx).
Step 4: Once the edge direction is known, the next step is to relate the edge direction to a direction
that can be traced in an image. So, if the pixels of a 5x5 image are aligned as follows:
Then, it can be seen by looking at pixel "a", there are only four possible directions when describing
the surrounding pixels - 0 degrees (in the horizontal direction), 45 degrees (along the positive
diagonal), 90 degrees (in the vertical direction), or 135 degrees (along the negative diagonal). So
now the edge orientation has to be resolved into one of these four directions depending on which
direction it is closest to (e.g. if the orientation angle is found to be 3 degrees, make it zero degrees).
Think of this as taking a semicircle and dividing it into 5 regions.
Therefore, any edge direction falling within the yellow range (0 to 22.5 & 157.5 to 180 degrees)
is set to 0 degrees. Any edge direction falling in the green range (22.5 to 67.5 degrees) is set to 45
degrees. Any edge direction falling in the blue range (67.5 to 112.5 degrees) is set to 90 degrees.
And finally, any edge direction falling within the red range (112.5 to 157.5 degrees) is set to 135
degrees.
Step 5: After the edge directions are known, non-maximum suppression now has to be applied.
Non-maximum suppression is used to trace along the edge in the edge direction and suppress any
pixel value (sets it equal to 0) that is not considered to be an edge. This will give a thin line in the
output image.
Step 6: Finally, hysteresis is used as a means of eliminating streaking. Streaking is the breaking
up of an edge contour caused by the operator output fluctuating above and below the threshold. If
a single threshold, T1 is applied to an image, and an edge has an average strength equal to T1, then
due to noise, there will be instances where the edge dips below the threshold. Equally it will also
extend above the threshold making an edge look like a dashed line. To avoid this, hysteresis uses
2 thresholds, a high and a low. Any pixel in the image that has a value greater than T1 is presumed
to be an edge pixel and is marked as such immediately. Then, any pixels that are connected to this
edge pixel and that have a value greater than T2 are also selected as edge pixels. If you think of
following an edge, you need a gradient of T2 to start but you don't stop till you hit a gradient below
T1.
Edge detection of all four types was performed on a Figure. Canny yielded the best results. This
was expected as Canny edge detection accounts for regions in an image. Canny yields thin lines
for its edges by using non-maximal suppression. Canny also utilizes hysteresis with thresholding.
The parameters you can supply differ depending on the method you specify. If you do not specify
a method, edge uses the Sobel method.