KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf ·...

47
KECE471 Computer Vision Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth and Ponce Note: Many contents were extracted from the lecture notes of Prof. Kyoung Mu Lee.

Transcript of KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf ·...

Page 1: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

KECE471 Computer Vision

Edge Detection

Chang-Su Kim

Chapter 8, Computer Vision by Forsyth and PonceNote: Many contents were extracted from the lecture notes of Prof. Kyoung Mu Lee.

Page 2: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Edge Detection

Page 3: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Edges

• Where the image

values exhibit sharp

variations

• Edges can be measured by– 1st order derivatives

• Determine the gradients

• Perform non-maximal suppression

• Threshold

– 2nd order derivatives• Find zero crossings in

2nd derivatives using Laplacian

Page 4: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

First-order derivative filters (1D)

• Sharp changes correspond to peaks of the

first-derivative of the input signal

f(x)f ’(x)

xx

Page 5: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Image gradient

• 2D gradient of an image:

• The gradient magnitude (edge strength):

• The gradient direction:

,),(

==

y

I

x

IIII yx

22

yx III +=

= −

x

y

I

I1tan

Page 6: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Image gradient

• Horizontal change:

• Vertical change:

)0,(, ky

I

x

I=

Change

No Change

),0(, ky

I

x

I=

No Change

Change

Page 7: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Image gradient

• General directions:

• Gradient direction is perpendicular to edge– It represents the direction for the maximum change

• Gradient magnitude measures edge strength.

1 2, ( , )I I

k kx y

=

Page 8: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Discrete approximation of derivatives

• 1D derivative

• Discrete approximations

−−+

−−

−+

=

central : 2

)()(lim

backward : )()(

lim

forward : )()(

lim

)(

0

0

0

x

xxfxxfx

xxfxfx

xfxxf

dx

xdf

x

x

x

( 1) ( ) ( )

( ) ( 1)

( 1) ( 1)

2

f x f xdf x

f x f xdx

f x f x

+ −

− − + − −

symmetric

-1 1

-1 1

-1 0 1

Page 9: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Effects of noises

• Consider an 1-D signal

• Can you detect the edge?

)(xI

dx

xdI )(

Page 10: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Noise suppression: pre-smoothing

Noise Filter(Smoothing)

EdgeDetection(Derivative)

𝐼(𝑥, 𝑦) 𝐸(𝑥, 𝑦)

( , ) ( , )*( ( , )* ( , ))

( ( , )* ( , ))* ( , )

( , ) ( ( , )* ( , ))

E x y D x y S x y I x y

D x y S x y I x y

S x y D x y I x y

=

=

=

Page 11: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Noise smoothing and edge detection

• Prewitt edge detector:

– Vertical mask

-1 0 1

-1 0 1

-1 0 1

Vertical Edge Detection

Noise S

mooth

ing

x

Page 12: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Noise smoothing and edge detection

-1 -1 -1

0 0 0

1 1 1

Noise Smoothing Horizo

nta

l Edge D

ete

ctio

n

• Prewitt edge detector:

– Horizontal mask

y

Page 13: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Prewitt Edge Detector

Result of Prewitt operator (threshold = 100)

Original image|𝐸| > threshold

|𝐸|

𝐸𝑥

𝐸𝑦

22

yx EEE +=

Page 14: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Sobel Edge Detector

• Sobel Masks:

– Gives more weight to the 4-neighbors

-1 0 1

-2 0 2

-1 0 1

-1 -2 -1

0 0 0

1 2 1

Page 15: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Sobel Edge Detector

Result of Sobel operator (threshold = 100)

Original image|𝐸| > threshold

|𝐸|

𝐸𝑥

𝐸𝑦

Page 16: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Gaussian Smoothing

• Consider smoothing with Gaussian kernel

I

IG

( )IGdx

d

2

2

2)(

x

exG−

=

Page 17: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Derivative of Gaussian

• Note that and

• This saves us one step

( ) IGdx

dIG

dx

d

= 2

2

22

)('

x

ex

xG−

−=

I

IGdx

d

Gdx

d

Page 18: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

2D edge detection filters

Gaussian derivative of Gaussian (DOG)

2

22

222

1),(

yx

eyxG

+−

= ( )yx GGyxG ,),( =

Page 19: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Second-order derivative filters (1D)

• Peaks of the first-derivative of the input signal

correspond to “zero-crossings” of the second-

derivative.

𝑓(𝑥) 𝑓′(𝑥)

x

𝑓′′(𝑥)

Page 20: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Second-order derivative filters (1D)

• The condition: 𝑓′′(𝑥) = 0 is not enough for

edgeness

– 𝑓(𝑥) = 𝑐 has 𝑓′′(𝑥) = 0, but there is no edge

• We need check whether |𝑓′ 𝑥 | is big

enough

Page 21: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

2D Laplacian Operator

1 1 1

1 -8 1

1 1 1

0 1 0

1 -4 1

0 1 0

Page 22: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

2D Laplacian Operator

• 2𝐼(𝑥, 𝑦) is a scalar (isotropic)

– Pros: It can be found using a SINGLE

mask

– Cons: The orientation information is

lost

• 2𝐼(𝑥, 𝑦) is the sum of second-

order derivatives

– But taking derivatives increases noises

– Very sensitive to noises

• It is always combined with a

smoothing (Gaussian) operation

Page 23: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Laplacian of Gaussian (LOG)• In 1D, consider

• Edge is the zero-crossing of the bottom graph

( ) IGx

IGx

=

2

2

2

2

I

IGx

2

2

Gx2

2

Page 24: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Laplacian of Gaussian (LOG)

• 𝑂(𝑥, 𝑦) =

2(𝐼(𝑥, 𝑦) ∗ 𝐺(𝑥, 𝑦))

1. Smoothing with a Gaussian filter

2. Finding zero-crossings with a Laplacian filter

• Using linearity:– 𝑂 𝑥, 𝑦 =

2𝐺 𝑥, 𝑦 ∗ 𝐼(𝑥, 𝑦)

– The combined filter is called LOG

2 2

2

2 22

2 2

2 2 2 2

4 2 2

2 2

4 2 2

( , ) exp

2

( , )

2 exp

2

2 exp

2

( )

= ( )

x yG x y

G GG x y

x y

x y x y

r r

+= −

= +

+ += − −

− −

Page 25: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

LOG Filter• Mexican hat operator (inverted LoG)

1-D 2-D

= 2

= 3

Page 26: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth
Page 27: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

LOG Filter

Original image

= 2.0

= 4.0 = 6.0

Page 28: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Second-Order Edge Detectors

• The Marr-Hildreth Operator

1. Laplacian of Gaussian (LoG)

2. Finding zero-crossing points

Page 29: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Second-Order Edge Detectors

• Laplacian of Gaussian (LoG)

𝛻2(𝑔 𝑥, 𝑦 ∗ 𝐏)=𝛻2(𝑔 𝑥, 𝑦 ) ∗ 𝐏

• 𝛻2(𝑔 𝑥, 𝑦 )=1

𝜎2𝑥2+𝑦2

𝜎2− 2 𝑒

−𝑥2+𝑦2

2𝜎2

• Maxican hat operator

• It is similar to the difference of Gaussian

Page 30: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Second-Order Edge Detectors

• Finding zero-crossing points

• Find the averages of the four quadrants

• If the max average is positive and the min average is negative,

then the center point is detected

Page 31: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Canny Edge Detector

• Canny Edge Detector

– Uses a mathematical model of the edge and noises

– Sets a performance criterion

– Synthesizes the optimal filter

• Experiments consistently show that it performs very well

• Widely used by C.V. practitioners for 30 years

• J. Canny, “A Computational Approach to Edge Detection”, IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol 8, No. 6,

Nov 1986.

Page 32: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Edge & Noise Model (1D)

• An ideal edge can be modeled as an step

• Additive, white Gaussian noise

A

Page 33: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Performance Criteria

• Good detection

– The filter must have a strong response at the edge location (𝑥 = 0)

• Good localization

– The filter response must be maximum very close to 𝑥 = 0

• Low false positives

– There should be only one maximum in a reasonable neighborhood of 𝑥 = 0

Page 34: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Optimal Filter

• Canny found a linear, continuous filter that

maximized the three given criteria

• There is no close-form solution for the

optimal filter

• However, it looks very similar to the

derivative of Gaussian (DoG)

Page 35: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Canny Edge Detector

• Three procedures

– Gradient computation

– Nonmaximum suppression

– Thresholding

Page 36: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Procedure: Gradient Computation

• Given an input image 𝐼 and a zero mean

Gaussian filter 𝐺 (std = 𝜎)

1. 𝐽 = 𝐼 ∗ 𝐺 (smoothing)

2. For each pixel (𝑖, 𝑗) (Gradient computation)

• Compute the image gradient

𝐽(𝑖, 𝑗) = (𝐽𝑥(𝑖, 𝑗), 𝐽𝑦(𝑖, 𝑗))

• Estimate edge strength

𝐸𝑠(𝑖, 𝑗) = 𝐽𝑥2 𝑖, 𝑗 + 𝐽𝑦

2 𝑖, 𝑗1/2

• Estimate edge orientation

𝐸𝑜 𝑖, 𝑗 = arctan𝐽𝑦 𝑖, 𝑗

𝐽𝑥 𝑖, 𝑗

• The output are images 𝐸𝑠 and 𝐸𝑜

Page 37: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Nonmaximum Suppression

• 𝐸𝑠 has the magnitudes of the smoothed

gradient.

– 𝜎 determines the amount of smoothing

• 𝐸𝑠 has large values at edges

• However, 𝐸𝑠 is large along thick trail.

how do we identify the significant

points?

Page 38: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

NONMAXIMUM SUPRESSION

• We wish to mark points along the curve where the magnitude is biggest.

• We can do this by looking for the maximum along a slice normal to the curve (nonmaximum suppression).

Page 39: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

• Non-maximum suppression:

✓ At q, we have a maximum if the value is larger than those at both p and at r.

✓ Interpolate to get these value

NONMAXIMUM SUPRESSION

Page 40: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Procedure: Nonmaximum Suppression

• The inputs are 𝐸𝑠 & 𝐸𝑜

• Consider 4 directions 𝐷 = {0°, 45°, 90°, 135°}

• For each pixel (𝑖, 𝑗) do:

1. Find the direction 𝑑𝐷 s.t. 𝑑 𝐸𝑜(𝑖, 𝑗) (normal to the edge)

2. If 𝐸𝑠(𝑖, 𝑗) is smaller than at least one of its neighbor along 𝑑

𝐼𝑁(𝑖, 𝑗) = 0

Otherwise,

𝐼𝑁(𝑖, 𝑗) = 𝐸𝑠(𝑖, 𝑗)

• The output is the thinned edge image 𝐼𝑁

Page 41: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Procedure: Thresholding

• Edges are found by thresholding the output

of NONMAX_SUPRESSION

• If the threshold is too high:

– Very few (none) edges

• Many false negatives, many gaps

• If the threshold is too low:

– Too many (all pixels) edges

• Many false positives, many extra edges

Page 42: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Results

original image Gradients

Nonmaximumsuppression and

thresholding

Page 43: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Canny with Canny with original

• controls the scale of the features

✓ large detects large scale edges only

✓ small detects fine features as well

Results

Page 44: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

fine scale, high threshold

coarse scale, high threshold coarse scale, low threshold

Page 45: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Canny Edge Detector

• Hysteresis thresholding

– Recursive search of 8 neighbors

Page 46: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Hysteresis Thresholding

Page 47: KECE471 Computer Vision Edge Detectionmcl.korea.ac.kr/.../uploads/2020/05/05_Edge_Detection.pdf · 2020-05-12 · Edge Detection Chang-Su Kim Chapter 8, Computer Vision by Forsyth

Challenges or Opportunities?

Edges are really at the lower level?Can we find better edges or silhouettes?