Documente Academic
Documente Profesional
Documente Cultură
TITLE:
Compute the edges of the given image using the following edge detectors and comment
on their performance:
1. Robert
2. Prewitt
3. Sobel
4. Canny
OBJECTIVE:
To understand the edge detection using different operators and comment on their
performance.
THEORY:
Type of edges:
Generally edges are of three types:
1. Horizontal Edges
2. Vertical Edges
3. Diagonal Edges
1. Robert Operator
2. Prewitt Operator
3. Sobel Operator
4. Canny Operator
Above mentioned all the filters are linear filters or smoothening filters.
Robert Operator
The Roberts operator performs a simple, quick to compute, 2-D spatial gradient
measurement on an image. It thus highlights regions of high spatial gradient which often
correspond to edges. In its most common usage, the input to the operator is a grey scale
image, as is the output. Pixel values at each point in the output represent the estimated
absolute magnitude of the spatial gradient of the input image at that point.
How It Works
In theory, the operator consists of a pair of 2×2 convolution masks as shown in Figure 1.
One mask is simply the other rotated by 90°. This is very similar to the Sobel operator.
+1 0 0 +1
0 -1 -1 0
Gx Gy
These masks are designed to respond maximally to edges running at 45° to the pixel grid,
one mask for each of the two perpendicular orientations. The masks 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:
|G|=√Gx^2+Gy^2
although typically, an approximate magnitude is computed which is much faster to
compute.
|G|=|Gx|+|Gy|
The angle of orientation of the edge (relative to the pixel grid) giving rise to the spatial
gradient is given by:
=arctan(Gy/Gx)-3∏/4
In this case, orientation 0 is taken to mean that the direction of maximum contrast from
black to white runs from left to right on the image, and other angles are measured
anticlockwise from this.
Often, this absolute magnitude is the only output the user sees --- the two components of
the gradient are conveniently computed and added in a single pass over the input image
using the pseudo-convolution operator shown in Figure
P1 P2
P3 P4
|G|=|P1-P4|+|P2-P3|
Prewitt Operator
Prewitt operator is used for edge detection in an image. It detects two types of edges
1. Horizontal edges
2. Vertical Edges
Prewitt operator provides us two masks one for detecting edges in horizontal direction
and another for detecting edges in an vertical direction.
The prewitt operator is based on convolving the image with a small ,separable,and integer
valued filter in horizontal and vertical direction and is therefore relatively inexpensive
in terms of computation.
Mathematically,the operator uses two 3x3 kernels .
Mx=(z3+cz6+z9)-(z1+cz4+z7)
My=(z7+cz8+z9)-(z1+cz2+z3)
(the constant c implies the emphasis given to pixels closer to the center of the mask)
Vertical direction
-1 0 1
-1 0 1
-1 0 1
Above mask will find the edges in vertical direction and it is because the zeros column in
the vertical direction. When you will convolve this mask on an image, it will give you the
vertical edges in an image.
Horizontal Direction
Above mask will find edges in horizontal direction and it is because that zeros column is
in horizontal direction. When you will convolve this mask onto an image it would
prominent horizontal edges in the image.
Vertical
Gradient Detector Output
CODE FOR PREWITT OPERATOR:
Sobel Operator
The sobel operator is very similar to Prewitt operator. It is also a derivate mask and is used
for edge detection. It also calculates edges in both horizontal and vertical direction.
It is used to compute an approximation of the gradient of image intensity function for edge
detection.
-1 0 1
-2 0 2
-1 0 1
This mask works exactly same as the Prewitt operator vertical mask. There is only one
difference that is it has “2” and “-2” values in center of first and third column. When applied
on an image this mask will highlight the vertical edges.
-1 -2 -1
0 0 0
1 2 1
Above mask will find edges in horizontal direction and it is because that zeros column is
in horizontal direction. When you will convolve this mask onto an image it would
prominent horizontal edges in the image. The only difference between it is that it have 2
and -2 as a center element of first and third row.
CODE FOR SOBEL EDGE DETECTOR
Canny Operator
The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to
detect a wide range of edges in images. It was developed by John F. Canny in 1986. Canny
also produced a computational theory of edge detection explaining why the technique
works.
Gradient direction is always perpendicular to edges. It is rounded to one of four angles
representing vertical, horizontal and two diagonal directions
Canny Algorithm:
• Apply Gaussian filter to smooth the image in order to remove the noise
• Find the intensity gradients of the image
• Apply non-maximum suppression to get rid of spurious response to edge detection
• Apply double threshold to determine potential edges
• Track edge by hysteresis: Finalize the detection of edges by suppressing all the
other edges that are weak and not connected to strong edges.
3. Roberts Works with binary Threshold It is simple and fast. Localization is not
images only. Does Detects thicker good.Weak re-
not detect edges edges. sponse to genuine
when a minimal edge.
change in gray scale
value.
Conclusion
From this experiment we have learnt how to detect edges in the digital image using
different edge detecting operators.
Hence we can comment on their performance as :
Robert<Prewitt<Sobel<Canny.
OUTPUTS