Edge Detection
Edge Detection
Edge Detection
We can also say that sudden changes of discontinuities in an image are called as edges. Significant
transitions in an image are called as edges. Edges typically occur on the boundary between two different
regions in an image.
Types of edges
Generally edges are of three types:
Horizontal edges
Vertical Edges
Diagonal Edges
Edge descriptors
Edge normal: unit vector in the direction of maximum intensity change.
Edge direction: unit vector to perpendicular to the edge normal.
Edge position or center: the image position at which the edge is located.
Edge strength: related to the local image contrast along the normal.
Modeling intensity changes
Edges can be modeled according to their intensity profiles.
Type of Edges (a) Step Edge (b) Ramp Edge (c) Line Edge (d) Roof Edge
Step edge: the image intensity abruptly changes from one value to one side of the discontinuity to a
different value on the opposite side.
Ramp edge: a step edge where the intensity change is not instantaneous but occur
over a finite distance.
Ridge edge: the image intensity abruptly changes value but then returns to the
starting value within some short distance.
Roof edge: a ridge edge where the intensity change is not instantaneous but occur over a finite distance.
Sharpening
Sharpening is opposite to the blurring. In blurring, we reduce the edge content and in Sharpening, we
increase the edge content. So in order to increase the edge content in an image, we have to find edges
first.
Edges can be find by one of the any method described above by using any operator. After finding edges,
we will add those edges on an image and thus the image would have more edges, and it would look
sharpen. This is one way of sharpening an image. The sharpen image is shown below.
***Roberts Operator
It is one of the first edge detection operator. Cross diagonal differences can be detected from an
image.
Prewitt operator
Prewitt operator is used for edge detection in an image. It detects two types of edges
Horizontal edges
Vertical Edges
Edges are calculated by using difference between corresponding pixel intensities of an image. All the
masks that are used for edge detection are also known as derivative masks. Because image is a signal so
changes in a signal can only be calculated using differentiation. So that’s why these operators are also
called as derivative operators or derivative masks.
All the derivative masks should have the following properties:
Opposite sign should be present in the mask.
Sum of mask should be equal to zero.
More weight means more edge detection.
Prewitt operator provides us two masks one for detecting edges in horizontal direction and another for
detecting edges in an vertical direction.
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.
How it works
When we apply this mask on the image it prominent vertical edges. It simply works like as first order
derivate and calculates the difference of pixel intensities in a edge region. As the center column is of
zero so it does not include the original values of an image but rather it calculates the difference of right
and left pixel values around that edge. This increase the edge intensity and it become enhanced
comparatively to the original image.
Horizontal Direction
-1 -1 -1
0 0 0
1 1 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.
How it works
This mask will prominent the horizontal edges in an image. It also works on the principle of above mask
and calculates difference among the pixel intensities of a particular edge. As the center row of mask is
consist of zeros so it does not include the original values of edge in the image but rather it calculate the
difference of above and below pixel intensities of the particular edge. Thus increasing the sudden
change of intensities and making the edge more visible. Both the above masks follow the principle of
derivate mask. Both masks have opposite sign in them and both masks sum equals to zero. The third
condition will not be applicable in this operator as both the above masks are standardize and we can’t
change the value in them.
Now it’s time to see these masks in action:
Sample Image
Following is a sample picture on which we will apply above two masks one at time.
Comparison
As you can see that in the first picture on which we apply vertical mask, all the vertical edges are more
visible than the original image. Similarly in the second picture we have applied the horizontal mask and
in result all the horizontal edges are visible. So in this way you can see that we can detect both
horizontal and vertical edges from an image.
Sobel operator
The sobel operator is very similar to Prewitt operator. It is also a derivate mask and is used for edge
detection. Like Prewitt operator sobel operator is also used to detect two kinds of edges in an image:
Vertical direction
Horizontal direction
Difference with Prewitt Operator
The major difference is that in sobel operator the coefficients of masks are not fixed and they can be
adjusted according to our requirement unless they do not violate any property of derivative masks.
Following is the vertical Mask of Sobel Operator:
-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.
How it works
When we apply this mask on the image it prominent vertical edges. It simply works like as first order
derivate and calculates the difference of pixel intensities in a edge region.
As the center column is of zero so it does not include the original values of an image but rather it
calculates the difference of right and left pixel values around that edge. Also the center values of both
the first and third column is 2 and -2 respectively.
This give more weight age to the pixel values around the edge region. This increase the edge intensity
and it become enhanced comparatively to the original image.
Following is the horizontal Mask of Sobel Operator
-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.
This mask will prominent the horizontal edges in an image. It also works on the principle of above mask
and calculates difference among the pixel intensities of a particular edge. As the center row of mask is
consist of zeros so it does not include the original values of edge in the image but rather it calculate the
difference of above and below pixel intensities of the particular edge. Thus increasing the sudden
change of intensities and making the edge more visible.
Sample Image
Following is a sample picture on which we will apply above two masks one at time.
After applying Vertical Mask
After applying vertical mask on the above sample image, following image will be obtained.
So in this way you can see that we can detect both horizontal and vertical edges from an image. Also if
you compare the result of sobel operator with Prewitt operator, you will find that sobel operator finds
more edges or make edges more visible as compared to Prewitt Operator.
This is because in sobel operator we have allotted more weight to the pixel intensities around the edges.
-5 0 5
-1 0 1
If you can compare the result of this mask with of the Prewitt vertical mask, it is clear that this mask will
give out more edges as compared to Prewitt one just because we have allotted more weight in the
mask.
-1 0 1
-2 0 2
-1 0 1
0 1 2
-1 0 1
-2 -1 0
1 2 1
0 0 0
-1 -2 -1
2 1 0
1 0 -1
0 -1 -2
1 0 -1
2 0 -2
1 0 -1
0 -1 -2
1 0 -1
2 1 0
East Direction Mask
-1 -2 -1
0 0 0
1 2 1
-2 -1 0
-1 0 1
0 1 2
As you can see that all the directions are covered on the basis of zeros direction. Each mask will give you
the edges on its direction. Now let’s see the result of the entire above masks. Suppose we have a sample
picture from which we have to find all the edges. Here is our sample picture:
Sample Picture
Now we will apply all the above filters on this image and we get the following result.
As you can see that by applying all the above masks you will get edges in all the direction. Result is also
depends on the image. Suppose there is an image, which do not have any North East direction edges so
then that mask will be ineffective.
-3 0 5
-3 -3 5
North West Direction Mask
-3 5 5
-3 0 5
-3 -3 -3
West Direction Mask
5 5 5
-3 0 -3
-3 -3 -3
5 0 -3
-3 -3 -3
South Direction Mask
5 -3 -3
5 0 -3
5 -3 -3
5 0 -3
5 5 -3
East Direction Mask
-3 -3 -3
-3 0 -3
5 5 5
-3 0 5
-3 5 5
As you can see that all the directions are covered and each mask will give you the edges of its own
direction. Now to help you better understand the concept of these masks we will apply it on a real
image. Suppose we have a sample picture from which we have to find all the edges. Here is our sample
picture:
Sample Picture
Now we will apply all the above filters on this image and we get the following result.
North Direction Edges
Laplacian Operator
Laplacian Operator is also a derivative operator which is used to find edges in an image. The major
difference between Laplacian and other operators like Prewitt, Sobel, Robinson and Kirsch is that these
all are first order derivative masks but Laplacian is a second order derivative mask. In this mask we have
two further classifications one is Positive Laplacian Operator and other is Negative Laplacian Operator.
Another difference between Laplacian and other operators is that unlike other operators Laplacian
didn’t take out edges in any particular direction but it take out edges in following classification.
Inward Edges
Outward Edges
Let’s see that how Laplacian operator works.
1 -4 1
0 1 0
-1 4 -1
0 -1 0
How it works
Laplacian is a derivative operator; its uses highlight gray level discontinuities in an image and try to
deemphasize regions with slowly varying gray levels. This operation in result produces such images
which have grayish edge lines and other discontinuities on a dark background. This produces inward and
outward edges in an image
The important thing is how to apply these filters onto image. Remember we can’t apply both the
positive and negative Laplacian operator on the same image. we have to apply just one but the thing to
remember is that if we apply positive Laplacian operator on the image then we subtract the resultant
image from the original image to get the sharpened image. Similarly if we apply negative Laplacian
operator then we have to add the resultant image onto original image to get the sharpened image.
Let’s apply these filters onto an image and see how it will get us inward and outward edges from an
image. Suppose we have a following sample image.
Sample Image