You are on page 1of 75

MATERI 07.

EDGE DETECTION
2020/2021 - 1 Pengolahan Citra
Definition of Edges
1

 Edges are significant local changes of intensity in


an image.
What Causes Intensity Changes?
2

 Geometric events
 surface orientation (boundary) discontinuities
 depth discontinuities
 color and texture discontinuities

 Non-geometric events surface normal discontinuity


 illumination changes
depth discontinuity
 specularities
 shadows color discontinuity

 inter-reflections
illumination discontinuity
Goal of Edge Detection
3

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


scene.
Why is Edge Detection Useful?
4

 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).
Effect of Illumination
5
Edge Descriptors
6

 Edge direction:
perpendicular to the direction
of maximum intensity change
(i.e., edge normal)
 Edge strength: related to the
local image contrast along
the normal.
 Edge position: the image
position at which the edge is
located.
Modeling Intensity Changes
7

 Step edge: the image intensity abruptly changes


from one value on one side of the discontinuity to a
different value on the opposite side.
Modeling Intensity Changes (cont’d)
8

 Ramp edge: a step edge where the intensity


change is not instantaneous but occur over a finite
distance.
Modeling Intensity Changes (cont’d)
9

 Ridge edge: the image intensity abruptly changes


value but then returns to the starting value within
some short distance (i.e., usually generated by
lines).
Modeling Intensity Changes (cont’d)
10

 Roof edge: a ridge edge where the intensity


change is not instantaneous but occur over a finite
distance (i.e., usually generated by the intersection
of two surfaces).
Main Steps in Edge Detection
11

 (1) Smoothing: suppress as much noise as possible,


without destroying true edges.
 (2) Enhancement: apply differentiation to enhance the
quality of the edges in the image.
i.e., sharpening
 (3) Thresholding: determine which edge pixels should be
discarded as noise and which should be retained.
i.e., threshold edge strength.
 (4) Localization: determine the exact location of an
edge.
i.e., sub-pixel resolution is required for some applications
to estimate the location of an edge to better than the
spacing between pixels.
Edge Detection Using Derivatives
12

 Often, points that lie on an edge


are detected by:

(1) Detecting the local maxima or


minima of the first derivative.
1st derivative
(2) Detecting the zero-crossings
of the second derivative.
2nd derivative
Edge Detection Using First Derivative
13

Assume 1D functions:
(not centered at x)

(centered at x)

(upward) step edge ramp edge

(downward) step edge roof edge


Edge Detection Using Second
14
Derivative
 Classic maximum/minimum test from Calculus:

 Extend this idea to find maximum/minimum of first


derivative:
Edge Detection Using Second
15
Derivative (cont’d)
 Approximate finding maxima/minima of gradient
magnitude by finding places where:

 can’t always find discrete pixels where the second


derivative is zero – look for zero-crossing instead.
Edge Detection Using Second
16
Derivative (cont’d)
Assume 1D functions:

(centered at x+1)

Replace x+1 with x (i.e., centered at x):


Edge Detection Using Second
17
Derivative (cont’d)
Edge Detection Using Second
18
Derivative (cont’d)
(upward) step edge

(downward) step edge

ramp edge

roof edge
Edge Detection Using Second
19
Derivative (cont’d)
 Four cases of zero-crossings:
 {+,-}, {+,0,-},{-,+}, {-,0,+}
 Slope of zero-crossing {a, -b} is: |a+b|.
 To detect zero-crossing threshold the slope.
 i.e.,if the slope is above some threshold, then that point
is an edge point.
Effect Smoothing on Derivates
20

Where is the edge??


Effect of Smoothing on Derivatives (cont’d)
21
Combine Smoothing with
22
Differentiation
(i.e., saves one operation)
Combine Smoothing with Differentiation:
Mathematical Interpretation
23

 Numerical differentiation is an ill-posed problem.


- i.e., solution does not exist or it is not unique or it does not
depend continuously on initial data)
 Ill-posed problems can be solved using
“regularization”
- i.e., impose additional constraints
 Interpolation must be performed prior to numerical
differentiation.
 In essence, smoothing performs image interpolation.
Edge Detection Using First Derivative:
24
Gradient
 Assume 2D functions:

 The first derivate of an image can be computed


using the gradient:
Gradient Representation
25

 The gradient is a vector which has magnitude and


direction:
(approximation)
∂f ∂f
or | |+| |
∂x ∂y

 Magnitude: indicates edge strength.


 Direction: indicates edge direction (i.e.,
perpendicular to edge direction).
Approximating Gradient
26

 Approximate gradient using finite differences:


Approximating Gradient (cont’d)
27

 Cartesian vs pixel-coordinates:
- j corresponds to the x direction
- i to the negative y direction
Approximating Gradient (cont’d)
28

sensitive to horizontal edges

∂f
sensitive to vertical edges
∂x
Approximating Gradient (cont’d)
29

 We can implement and using the


following masks:

(x+1/2,y)

good approximation
(x,y+1/2)
at (x+1/2,y) *
*

good approximation
at (x,y+1/2)
30
Approximating Gradient (cont’d)

 A different approximation of the gradient:


good approximation
(x+1/2,y+1/2)

• We can implement and using the following masks:


Another Approximation
31

 Consider the arrangement of pixels about the pixel (i, j):

3 x 3 neighborhood:

 The partial derivatives can be computed by:

 The constant c implies the emphasis given to pixels closer to the center of
the mask.
Prewitt Operator
32

 Setting c = 1, we get the Prewitt operator:


Sobel Operator
33

 Setting c = 2, we get the Sobel operator:


Edge Detection Steps Using Gradient
34

(i.e., sqrt is expensive)


Example (using Prewitt operator)
35

Note: in this example,


the divisions by 2 and 3
In the computation of fx
and fy are done for
normalization purposes
only.
Another Example
36

d
I
dx

d
I
dy
Another Example (cont’d)
37

2
d  d 
2

∆ =  I  +  I 
 dx   dy 

∆ ≥ Threshold = 100
Isotropic property of gradient
38
magnitude
 The magnitude of the gradient detects edges in all
directions.

2
d  d 
2
d d
I I ∆ =  I  +  I 
dx dy  dx   dy 
Criteria for Optimal Edge Detection
39

 (1) Good detection


 Minimize the probability of false positives (detecting spurious edges).
 Minimize the probability of false negatives (missing real edges).

 (2) Good localization


 Detected edges must be as close as possible to the true edges.

 (3) Single response


 Minimize the number of local maxima around the true edge.
Canny edge detector
40

 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.
Steps of Canny edge detector
41
Steps of Canny edge detector (cont’d)
42

(and direction)
Canny edge detector - example
43

original image
Canny edge detector – example
44
(cont’d)
Gradient magnitude
Canny edge detector – example
45
(cont’d)
Thresholded gradient magnitude
Canny edge detector – example
46
(cont’d)
Thinning (non-maxima suppression)
Non-maxima suppression
47

• Check if gradient magnitude at pixel location (i,j)


is local maximum along gradient direction
Non-maxima suppression (cont’d)
48

Warning: requires checking


interpolated pixels p and r

(i,j)
Hysteresis thresholding
49

• Standard thresholding:

- Can only select “strong” edges.


- Does not guarantee “continuity”.

gradient magnitude low threshold high threshold


Hysteresis thresholding (cont’d)
50

• Hysteresis thresholding uses two thresholds:


- low threshold tl
- high threshold th (usually, th = 2tl)

th
tl th
tl

• For “maybe” edges, decide on the edge if neighboring


pixel is a strong edge.
Hysteresis thresholding/Edge Linking
51

 Idea: use a high threshold to start edge curves and


a low threshold to continue them.

Use edge
“direction” for
linking edges
Hysteresis Thresholding/Edge Linking
52
(cont’d)

(using tl and th)

Note: large gaps are still difficult to bridge.


(i.e., more sophisticated algorithms are required)
Laplacian
53
Laplacian (cont’d)
54
Variations of the Laplacian
55
Laplacian - Example
56

detect zero-crossings
Properties of Laplacian
57

 It is an isotropic operator.
 It is cheaper to implement than the gradient (i.e.,
one mask only).
 It does not provide information about edge
direction.
 It is more sensitive to noise (i.e., differentiates
twice).
Laplacian of Gaussian (LoG)
(Marr-Hildreth operator)
58

 To reduce the noise effect, the image is first smoothed.


 When the filter chosen is a Gaussian, we call it the LoG edge
detector.
σ controls smoothing

 It can be shown that: (inverted


LoG)

2σ2
Laplacian of Gaussian (LoG) -
59
Example
(inverted LoG)
(inverted LoG)

filtering zero-crossings
Decomposition of LoG
60

 It can be shown than LoG can be written as


follows:2
∇ g ( x, y )

 2D LoG convolution can be implemented using 4


1D convolutions.
O(n2) versus O(4n) operations!
Decomposition of LoG (cont’d)
61

Algorithm
Difference of Gaussians (DoG)
62

 The Laplacian of Gaussian can be approximated by the


difference between two Gaussian functions:

approximation
actual LoG
Difference of Gaussians (DoG) (cont’d)
63

(a) σ =1 (b) σ =2 (b)-(a)


Gradient vs LoG
64

 Gradient works well when the image contains sharp


intensity transitions and low noise.
 Zero-crossings of LOG offer better localization, especially
when the edges are not very sharp.
step edge

ramp edge
Second Directional Derivative
65

 Directional derivative of f at point (r, c) in


direction α:

 Using polar coordinates:

ρ: radius in polar coordinate


α: angle in polar coordinate (clockwise from column axis)
Second Directional Derivative (cont’d)
66

 Second and third directional derivatives of f at


point (r, c) in direction α:
Second and Third Directional
67
Derivatives (cont’d)
 Edge detection using second directional derivative:
(1) Compute second and third directional derivatives

in the direction of gradient.


(2) If the second derivative is equal to zero, and the

third derivative is negative, then that point is an


edge point.
Second Directional Derivative in
the gradient direction
68
Laplacian vs Second Directional
69
Derivative
Edge Detection Using Facet Mode
70

 Steps
1. Fit a bi-quadratic polynomial to a small
neighborhood of a pixel.
2. Compute analytically the second and third directional
derivatives in the direction of gradient.
3. If the second derivative is equal to zero, and the third
derivative is negative, then that point is an edge
point.
Edge detection is just the beginning…
71

image human segmentation gradient magnitude

Berkeley segmentation database:


http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/
Practical Issues
72

 Noise suppression-localization tradeoff.


 Smoothing depends on mask size (e.g., depends on σ
for Gaussian filters).
 Larger mask sizes reduce noise, but worsen localization
(i.e., add uncertainty to the location of the edge) and
vice versa.
smaller mask larger mask
Practical Issues (cont’d)
73

 Choice of threshold.
gradient magnitude

low threshold high threshold


Practical Issues (cont’d)
74

 Edge thinning and linking.

You might also like