Edge Detection

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

What are edges

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.

Why detect edges


Most of the shape information of an image is enclosed in edges. So first we detect these edges in an
image and by using the filters and then by enhancing those areas of image which contains edges,
sharpness of the image will increase and image will become clearer.

Goal of edge detection


Produce a line drawing of a scene from an image of that scene. Important features can be extracted
from the edges of an image (e.g., corners, lines, curves)
And these features are used by higher-level computer vision algorithms (e.g., for object recognition).
What causes intensity changes?
 Various physical events cause intensity changes.
- Geometric events
- object boundary (discontinuity in depth and/or surface color and texture)
- surface boundary (discontinuity in surface orientation and/or surface color and texture)
 Non-geometric events
- specularity (direct reflection of light, such as a mirror)
- shadows (from other objects or from the same object)
- inter-reflections

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.

Why detect edges


Most of the shape information of an image is enclosed in edges. So first we detect these edges in an
image and by using these filters and then by enhancing those areas of image which contains edges,
sharpness of the image will increase and image will become clearer.
Here are some of the masks for edge detection:
 Prewitt Operator
 Sobel Operator
 Robinson Compass Masks
 Krisch Compass Masks
 Laplacian Operator.
Above mentioned all the filters are Linear filters or smoothing filters.
Prewitt Operator
Prewitt operator is used for detecting edges horizontally and vertically.
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.
Robinson Compass Masks
This operator is also known as direction mask. In this operator we take one mask and rotate it in all the 8
compass major directions to calculate edges of each direction.
Kirsch Compass Masks
Kirsch Compass Mask is also a derivative mask which is used for finding edges. Kirsch mask is also used
for calculating edges in all the directions.
Laplacian Operator
Laplacian Operator is also a derivative operator which is used to find edges in an image. Laplacian is a
second order derivative mask. It can be further divided into positive laplacian and negative laplacian.
All these masks find edges. Some find horizontally and vertically, some find in one direction only and
some find in all the directions. The next concept that comes after this is sharpening which can be done
once the edges are extracted from the image

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.

Original Image Sharpen Image

***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.

After applying Vertical Mask


After applying vertical mask on the above sample image, following image will be obtained. This image
contains vertical edges. You can judge it more correctly by comparing with horizontal edges picture.
After applying Horizontal Mask
After applying horizontal mask on the above sample image, following image will be obtained.

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.

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.
After applying Vertical Mask
After applying vertical mask on the above sample image, following image will be obtained.

After applying Horizontal Mask


After applying horizontal mask on the above sample image, following image will be obtained
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. 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.

Applying more weight to mask


Now we can also see that if we apply more weight to the mask, the more edges it will get for us. Also as
mentioned in the start of the tutorial that there is no fixed coefficients in sobel operator, so here is
another weighted operator
-1 0 1

-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.

Robinson compass masks


Robinson compass masks are another type of derrivate mask which is used for edge detection. This
operator is also known as direction mask. In this operator we take one mask and rotate it in all the 8
compass major directions that are following:
 North
 North West
 West
 South West
 South
 South East
 East
 North East
There is no fixed mask. You can take any mask and you have to rotate it to find edges in all the above
mentioned directions. All the masks are rotated on the bases of direction of zero columns.
For example let’s see the following mask which is in North Direction and then rotate it to make all the
direction masks.
North Direction Mask

-1 0 1

-2 0 2

-1 0 1

North West Direction Mask

0 1 2

-1 0 1

-2 -1 0

West Direction Mask

1 2 1

0 0 0

-1 -2 -1

South West Direction Mask

2 1 0

1 0 -1

0 -1 -2

South Direction Mask

1 0 -1

2 0 -2

1 0 -1

South East Direction Mask

0 -1 -2

1 0 -1

2 1 0
East Direction Mask

-1 -2 -1

0 0 0

1 2 1

North East Direction Mask

-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.

North Direction Edges


North West Direction Edges

West Direction Edges

South West Direction Edges

South Direction Edges


South East Direction Edges

East Direction Edges

North East Direction Edges

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.

Kirsch Compass Mask


Kirsch Compass Mask is also a derivative mask which is used for finding edges. This is also like Robinson
compass find edges in all the eight directions of a compass. The only difference between Robinson and
kirsch compass masks is that in robinson we have a standard mask but in Kirsch we change the mask
according to our own requirements.
With the help of Kirsch Compass Masks we can find edges in the following eight directions.
 North
 North West
 West
 South West
 South
 South East
 East
 North East
We take a standard mask which follows all the properties of a derivative mask and then rotate it to find
the edges.
For example let’s see the following mask which is in North Direction and then rotate it to make all the
direction masks.

North Direction Mask


-3 -3 5

-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

South West Direction Mask


5 5 -3

5 0 -3

-3 -3 -3
South Direction Mask
5 -3 -3

5 0 -3

5 -3 -3

South East Direction Mask


-3 -3 -3

5 0 -3

5 5 -3
East Direction Mask
-3 -3 -3

-3 0 -3

5 5 5

North East Direction Mask


-3 -3 -3

-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

North West Direction Edges

West Direction Edges

South West Direction Edges


South Direction Edges

South East Direction Edges

East Direction Edges

North East Direction Edges


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.

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.

Positive Laplacian Operator


In Positive Laplacian we have standard mask in which center element of the mask should be negative
and corner elements of mask should be zero.
0 1 0

1 -4 1

0 1 0

Positive Laplacian Operator is use to take out outward edges in an image.

Negative Laplacian Operator


In negative Laplacian operator we also have a standard mask, in which center element should be
positive. All the elements in the corner should be zero and rest of all the elements in the mask should be
-1.
0 -1 0

-1 4 -1

0 -1 0

Negative Laplacian operator is use to take out inward edges in an image

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

After applying Positive Laplacian Operator


After applying positive Laplacian operator we will get the following image.

After applying Negative Laplacian Operator


After applying negative Laplacian operator we will get the following image.

You might also like