Lab 7 PDF

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

LAB # 07: Edge Detection

Lab Objective:

The objective of this lab is to apply differential spatial filters and Canny edge detector on images
to detect edges.

Lab Description:
Different spatial filters allow us to enhance the details in an image as per our requirement. In
order to find out the boundary or edges of objects in an image, Differential filters come in handy.
One of the differential filter is Sobel filter

Horizontal Sobel filter is used to find out the edges along x-axis as it calculates the derivative of
an image in x direction.
-1 0 1
-2 0 2
-1 0 1

While Vertical Sobel filter is used to find out the edges along y-axis.

-1 -2 -1
0 0 0
1 2 1

The edges obtained from applying both this filters can then be added to obtain all the edges in an
image.
The result of either sobel filter ranges from -1020 to +1020. Where 0 stands for no change while
-1020 and 1020 suggest maximum change from light to dark and dark to light respectively, but
we are interested in change not light to dark or dark to light change so in order to achieve that we
can take absolute values only.
Digital Image Processing Lab Manual

Canny Edge Detection: is a popular edge detection algorithm. Steps are as follows.

i) Noise Reduction: Using 5x5 Gaussian filter


ii) Sobel kernel in both horizontal and vertical direction.
iii) Non-Maximum suppression: Suppress all the gradient values to 0 except the local maxima.
iv) Hysteresis Thresholding: we need two threshold values, minVal and maxVal. Any edges with
intensity gradient more than maxVal are sure to be edges and those below minVal are sure to
be non-edges, so discarded. Those who lie between these two thresholds are classified edges
or non-edges based on their connectivity. If they are connected to “sure-edge” pixels, they are
considered to be part of edges

Lab Task:

1: Apply Horizontal Sobel and Vertical Sobel separately on the figure.


 Now find the magnitude of the two edges and save it. Show only those whose
magnitude are in top 30%

 Now find phase of the image and show the lines that are on 45 and 90 degrees.

 Now show the lines that are on 45 and 90 degrees and have top 30% magnitude.
2: Apply canny edge detector to find edges in the imag.
Home Task

1. Apply Hough transform on the edge detected image using cv2.HoughLines ().

You might also like