You are on page 1of 34

Department of Mechatronics

Edge Detection

MACHINE VISION AND IMAGE


PROCESSING
(MTE 4075)
Manipal Institute of Technology, Manipal, India
−1−
Content:
▪Edge Detection
–Introduction
–Detection of Isolated Points
–Line Detection
–Edge Models
–Basic Edge Detection
–Advanced Edge detection technique
•Marr-Hildreth edge detector
•The Canny edge detector
Manipal Institute of Technology, Manipal, India
−2−
Introduction: Definition of Edges

• Edges are significant local changes of


intensity in an image.

Manipal Institute of Technology, Manipal, India


−3−
Introduction: What Causes Intensity Changes?

• Geometric events
– surface orientation (boundary) discontinuities
– depth discontinuities
– color and texture discontinuities

• Non-geometric events surface normal discontinuity

– illumination changes depth discontinuity

– shadows color discontinuity


– inter-reflections
illumination discontinuity

Manipal Institute of Technology, Manipal, India


−4−
Introduction: Goal of Edge Detection

• Produce a line “drawing” of a scene from an image of that


scene.

Manipal Institute of Technology, Manipal, India


−5−
Introduction: Why is Edge Detection Useful?

• Important features can be extracted from the edges of


an image (e.g., corners, lines, curves).
• These features are used by higher-level computer
vision algorithms (e.g., recognition).

Manipal Institute of Technology, Manipal, India


−6−
Introduction

Manipal Institute of Technology, Manipal, India


−9−
Introduction
▪ The basic definition of the first-order derivative
of a one dimensional function f(x) is the
difference

▪ The second-order derivative of a one-


dimensional function f ( x ) is the difference

▪ When we consider an image function of two


variables, f(x, y), at which time we will dealing
with partial derivatives along the two spatial
axes.
Manipal Institute of Technology, Manipal, India
− 10 −
Introduction: Zero Crossings
• Zero crossings in the convolved Example function – a
result indicate presence of an smoothed step edge
edge
• Peaks in the first derivative are
equivalent to zero crossings in the
second derivative First derivative peak
• Magnitude of the edge is
proportional to the slope at the
zero crossing

Second derivative
Zero crossing

Manipal Institute of Technology, Manipal, India


− 11 −
Detection of Isolated Points:

• Apply Laplacian mask to image f(x,y)


• R(x,y) denotes filtered image
• Extract pixels that exceed the threshold T
• The image g(x,y) contains only edge/point

1 if R( x, y )  T
g(x, y) = 
0 otherwise

Point

Example 10.1
Manipal Institute of Technology, Manipal, India
− 13 −
Line Detection

• Horizontal mask to obtain horizontal lines


• +45 and -45 mask to obtain diagonal lines
• Vertical mask to obtain vertical lines

Example 10.2
Manipal Institute of Technology, Manipal, India
− 14 −
Line Detection

Detection of +45
line in an image

Example 10.3
Manipal Institute of Technology, Manipal, India
− 15 −
Edge Models

Step Edge Ramp Edge Roof Edge

Transition between 2 Edges blurred Base is 1 pixel, roof edge


Intensity levels with and/or noisy Is 1 pixel
1 pixel gap Slope depends Example:
on the blurring • Image of a wall with pipe,
• objects at different distances
• Roads in satellite images

Manipal Institute of Technology, Manipal, India


− 16 −
First derivative: to detect the
presence of edges

Second derivative: to check edge pixel


moving from light to dark

Or dark to light

Manipal Institute of Technology, Manipal, India


− 17 −
Original image First Second
Behaviour of the first and second and cross derivative derivative
derivatives of a noisy image sectional profile

• Edge operators also enhance


noise

• Example – first and second


derivatives of a noisy ramp edge

Increasing noise
– Even with very low noise, 1st
derivative is useless at this noise
level
– Second derivative is useless for even
less noise

Example 10.4
Manipal Institute of Technology, Manipal, India
− 20 −
Edge Detection: Fundamental Steps
(1) Smoothing: suppress as much noise as possible, without destroying true
edges.

(2) Enhancement: apply differentiation to enhance the quality of edges (i.e.,


sharpening).

(3)Thresholding: determine which edge pixels should be discarded as noise


and which should be retained (i.e., threshold edge magnitude).

(4) Localization: determine the exact edge location.

sub-pixel resolution might be required for some applications to estimate the location of an edge to
better than the spacing between pixels.

Manipal Institute of Technology, Manipal, India


− 21 −
Edge Detection:
• Practical edge detectors - first do image smoothing for noise reduction

• Example – Sobel filter • Effectively does a smoothing followed


-1 0 1
by a differencing
1
-2 0 2 -1 0 +1
2
differencing
-1 0 1 1
smoothing

• All edge detectors do


– Smoothing for noise reduction
– Detection of candidate edge points
– Edge localization – keeping only the points that are closest to the true edge

Manipal Institute of Technology, Manipal, India


− 22 −
Edge Detection: Gradient operators

Manipal Institute of Technology, Manipal, India


− 23 −
Edge Detector: Example
Original image “pout.tif” Gradient magnitude, using Sobel masks

𝟏
𝟐 𝟐 𝟐
𝛛𝒇 𝛛𝒇
𝜵𝒇 = +
𝛛𝒙 𝛛𝒚
Manipal Institute of Technology, Manipal, India
− 24 −
Edge Detector: Example

original image horizontal edge vertical edge

Manipal Institute of Technology, Manipal, India


− 25 −
Edge Detector: Sobel Edge Detection Example

Source: J Hays
Manipal Institute of Technology, Manipal, India
− 32 −
Edge Detector: Sobel Edge Detection Example

Source: J Hays
Manipal Institute of Technology, Manipal, India
− 33 −
Edge Detector: Properties of an Edge Detector

Criteria for a good edge detector?


Good detection: find all real edges,
ignoring noise or other artifacts

Good localization: detect edges as


close as possible to true edges

Single response: return one point only for


each true edge point

Source: K Grauman
Manipal Institute of Technology, Manipal, India
− 34 −
Advanced Edge Detection Technique:
• Marr-Hildreth edge detector (self learning)
• The Canny edge detector

Reference of Self Learning Topic:


Gonzalez, Rafael C., and Richard E. Woods. "Digital Image Processing, New Jersey.", 2007. 3rd edition. (Chapter-10, Page-714)

Manipal Institute of Technology, Manipal, India


− 46 −
The Canny edge detector
• Canny has shown that the first derivative of the Gaussian closely approximates
the operator that optimizes the product of signal-to-noise ratio and localization.
(i.e., analysis based on "step-edges" corrupted by "Gaussian noise“)

J. Canny, A Computational Approach To Edge Detection, IEEE Trans. Pattern


Analysis and Machine Intelligence, 8:679-714, 1986.
Manipal Institute of Technology, Manipal, India
− 47 −
The Canny edge detector: Algorithm

Manipal Institute of Technology, Manipal, India


− 48 −
The Canny edge detector: Algorithm

(and direction)
(and direction)

Manipal Institute of Technology, Manipal, India


− 49 −
The Canny edge detector:

Original image

Smoothing by Gaussian convolution

Differential operators along x and y axis

Non-maximum suppression
finds peaks in the image gradient

Hysteresis thresholding locates edge strings

Edge map

Manipal Institute of Technology, Manipal, India


− 50 −
The Canny edge detector:

• Low error rate of detection


– Well match human perception results
• Good localization of edges
– The distance between actual edges in an image
and the edges found by a computational algorithm
should be minimized
• Single response
– The algorithm should not return multiple edges
pixels when only a single one exists

Manipal Institute of Technology, Manipal, India


− 51 −
The Canny edge detector: Example

original image vertical edges horizontal edges

norm of the gradient after thresholding after thinning

Manipal Institute of Technology, Manipal, India


− 52 −
The Canny edge detector: Example

Canny Edges
Source: Prem Kalra, R Urtasun, S Fidler

Manipal Institute of Technology, Manipal, India


− 53 −
Edge Detection in OpenCV/ MATLAB
• MATLAB
– edge()

• OpenCV Python
• cv2.canny()
• https://www.geeksforgeeks.org/image-processing-in-
python-scaling-rotating-shifting-and-edge-detection/

Manipal Institute of Technology, Manipal, India


− 75 −
Practice Problem
Gonzalez, Rafael C., and Richard E. Woods. "Digital Image Processing,
New Jersey.", 2007. 3rd edition.

Example 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.8, 10.9

Manipal Institute of Technology, Manipal, India


− 76 −
Summary
We have looked at:
❑Edge Detection
❑Introduction
❑Detection of Isolated Points
❑Line Detection
❑Edge Models
❑Basic Edge Detection
❑Advanced Edge detection technique
• Marr-Hildreth edge detector
• The Canny edge detector

Manipal Institute of Technology, Manipal, India


− 77 −

You might also like