52
DD2423 Image Processing and Computer Vision EDGE DETECTION arten Bj¨ orkman Computater Vision and Active Perception School of Computer Science and Communication November 8, 2012 1

EDGE DETECTION - KTH

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EDGE DETECTION - KTH

DD2423 Image Processing and Computer Vision

EDGE DETECTIONMarten Bjorkman

Computater Vision and Active Perception

School of Computer Science and Communication

November 8, 2012

1

Page 2: EDGE DETECTION - KTH

General

Under rather general assumptions about the image formation the world consistsof smooth regular surfaces with different reflectance properties.

One can assume that a discontinuity in image brightness corresponds to somediscontinuity in (and their combinations):

• depth,

• surface orientation,

• reflectance, or

• illumination.

Thus, find discontinuities in image brightness (edges) and characterize these withrespect to the physical phenomena that gave rise to them.

2

Page 3: EDGE DETECTION - KTH

Example: Line drawing

Luminance and second order derivative.

3

Page 4: EDGE DETECTION - KTH

Example: Line drawing

Noisy luminance and second order derivative.

4

Page 5: EDGE DETECTION - KTH

Why edges?

• Edge features are perhaps the most important features to humans.

• Independent of illumination.

• Easy to detect computationally.

• Used to form higher level features (lines, curves, corners, etc).

5

Page 6: EDGE DETECTION - KTH

How do edges look in practice?

Ideal models:

RidgeLineRamp edgeStep edge

In practice, edges are blurred and noisy.

Problem: Concept of discontinuity doesn’t exist for discrete data!

6

Page 7: EDGE DETECTION - KTH

Fundamental problem

Differentiation is ill posed - an arbitrary small perturbation in the input can leadto arbitrarily large perturbation in the output.

Ex: f (x) = arctan(x) f ′(x) = 11+x2

f (x) = arctan(x)+ εsinωx f ′(x) = 11+x2 + εωcosωx .

• The difference εωcosωx can be arbitrarily large if ω >> 1/ε.7

Page 8: EDGE DETECTION - KTH

Noise reduction: Smoothing

• Basic idea: Precede differentiation by smoothing.

• Trade-off problem:

- increasing amount of smoothing: stronger suppression of noise, higherdistortion of “true” structures.

- decreasing amount of smoothing: more accurate feature detection, highernumber of “false positives”.

8

Page 9: EDGE DETECTION - KTH

Basic methods for edge detection

• Linear:

- Differentiation (derivatives)

- High-pass filtering

- Matching with model patterns

• Non-linear:

- Fitting of parameterized edge models

- Non-linear diffusion

• Common approach:

1. Detect edge points

2. Link these to polygons

3. Abstraction: Fit to model (straight lines, splines, ellipses )

9

Page 10: EDGE DETECTION - KTH

Edge attributes and problems

• Attributes:

- Position

- Orientation

- Strength

- Diffuseness (width)

• Problems:

- Image noise

- Interference (nearby structures at different scales)

- Physical interpretation

10

Page 11: EDGE DETECTION - KTH

Method: gradients and derivatives

• Most methods are gradient based.

• Detection of maxima of gradient.

• Detection of zero crossings of second derivative.

• Edge pixels need to be connected together to get to a sequenceof edge points (edge linking).

11

Page 12: EDGE DETECTION - KTH

Image gradient

12

Page 13: EDGE DETECTION - KTH

Image gradient

13

Page 14: EDGE DETECTION - KTH

Image gradient

14

Page 15: EDGE DETECTION - KTH

Image gradient

• So the gradient is a vector with magnitude in the x and y directionsequal to the respective partial derivatives.

• Q: How do we compute partial derivatives of a discrete function?

• A: Taylor series approximation!

15

Page 16: EDGE DETECTION - KTH

Image gradient

16

Page 17: EDGE DETECTION - KTH

Image gradient

17

Page 18: EDGE DETECTION - KTH

Image gradient

18

Page 19: EDGE DETECTION - KTH

Basic edge detection

19

Page 20: EDGE DETECTION - KTH

Magnitude

20

Page 21: EDGE DETECTION - KTH

Edge detection in practice

21

Page 22: EDGE DETECTION - KTH

Edge detection in practice

22

Page 23: EDGE DETECTION - KTH

Sobel operator

Common in many edge detection schemes.

Sv =

1 0 −12 0 −21 0 −1

=

121

∗ (1 0 −1)

Sh =

1 2 10 0 0−1 −2 −1

=

10−1

∗ (1 2 1)

• Smoothing in one direction, derivative in the other.

• Usually, even more smoothing is needed.

23

Page 24: EDGE DETECTION - KTH

Sobel operator (cont)

24

Page 25: EDGE DETECTION - KTH

Different filter types

25

Page 26: EDGE DETECTION - KTH

Example: Roberts vs. Prewitt filter

The major edges are better with Prewitt than Roberts, but Sobel is best.

26

Page 27: EDGE DETECTION - KTH

Zero crossings - Laplacian operator

Instead of searching the maxima of the gradient, we may search zero crossingsof the second order derivative.

27

Page 28: EDGE DETECTION - KTH

LoG and DoG

LoG (Laplacian of Gaussian): Gaussian smoothing with variance σ2 followed by aLaplacian operator:

DoG (Difference of Gaussian): An efficient approximation of a LoG based on thedifference between two Gaussian smoothing operator with different variances:

28

Page 29: EDGE DETECTION - KTH

Difference of Gaussians

29

Page 30: EDGE DETECTION - KTH

The Laplacian operator - Properties

• Advantages:

- Closer to mechanisms of visual perception.

- One parameter only (size of the filter).

- No threshold is required.

- Produces closed contours.

• Disadvantages:

- Is more sensitive to noise (usage of second derivative).

- No information on the orientation of the contour.

• Combination of gradient and contour:

- Search for zero-crossings of the Laplacian in the neighborhood oflocal maxima of the gradient.

30

Page 31: EDGE DETECTION - KTH

Laplacian operator

31

Page 32: EDGE DETECTION - KTH

Zero crossings

32

Page 33: EDGE DETECTION - KTH

Canny Edge Detector

1. Convolve image with derivatives of a Gaussian.

2. Compute gradient magnitude.

3. Perform non-maximum suppression.

4. Perform Hysteresis Thresholding.

Based on a Master thesis. Most popular edge detection method since 1986.

33

Page 34: EDGE DETECTION - KTH

Canny Edge Detector

• Typical problem: If you detect edges by gradient thresholding, the resultingedges can be severel pixels wide.

• The Canny Edge Detector adds an additional refinement to address this:

- Estimate edge direction Ed.

- Estimate edge strength Es (usually gradient magnitude).

- Remove non-maximum edge pixels in the Ed direction.

34

Page 35: EDGE DETECTION - KTH

1. Gaussian smoothing

35

Page 36: EDGE DETECTION - KTH

2. Gradient magnitude

36

Page 37: EDGE DETECTION - KTH

Gradient orientation

37

Page 38: EDGE DETECTION - KTH

3. Non-maximum suppression

Implementation by discrete local search

1. Interpolate

- gradient magnitude Es =| ∇I |=√

δIδx

2+ δI

δy2, using the

- gradient direction Ed = tan−1(δIδy/

δIδx)

2. Perform local search at each point

⇒ gives edge points that can be linked into polygons.

38

Page 39: EDGE DETECTION - KTH

Gradient orientation

39

Page 40: EDGE DETECTION - KTH

Non-maximum suppression (faster)

40

Page 41: EDGE DETECTION - KTH

Non-maximum suppression (example)

41

Page 42: EDGE DETECTION - KTH

And after thresholding...

Raw thresholding on gradient magnitude may result in highly fragmented edges.

42

Page 43: EDGE DETECTION - KTH

4. Hysteresis thresholding

• Problem: Thresholding on gradient magnitude may lead to fragmented edges.

43

Page 44: EDGE DETECTION - KTH

Hysteresis thresholding

44

Page 45: EDGE DETECTION - KTH

Edge linking

Link neighboring edge pixels to connected contours.Each point has strength | ∇L | and orientation Θ.

Algorithm: ∀ pixels

if (| ∇L |> threshold) [ and is locally maximum ]

∀ neighbor’s

if (| ∇L | of neighbor > threshold) [ and is locally maximum ]

and ( |Θthis−Θneighbor |< threshold)

link these pixels to be connected

Combine with efficient traversal procedure and mechanism for closing gaps.

45

Page 46: EDGE DETECTION - KTH

Differential geometric edge definition

Non-maximum suppression:

Edge point = point where the gradient magnitude assumes a maximumin the gradient direction.

This can be expressed in terms of

Gradient: ∇L = (Lx,Ly)T , and

Gradient magnitude:√

L2x +L2

y.

Normalized gradient direction:

n =∇L| ∇L |

=(Lx,Ly)

T√L2

x +L2y

46

Page 47: EDGE DETECTION - KTH

Differential geometric edge definition

Directional derivative in direction v = (cosα,sinα):

∂v = cosα∂x + sinα∂y

Directional derivative in gradient direction:

∂n =Lx√

L2x +L2

y

∂x +Ly√

L2x +L2

y

∂y

Denote:∂nL = Ln =

Lx√L2

x +L2y

Lx +Ly√

L2x +L2

y

Ly

47

Page 48: EDGE DETECTION - KTH

Gradient magnitude

Requirements for gradient magnitude to be maximal in gradient direction:

Lnn = 0 Lnnn ≤ 0

• In terms of coordinates:

Lnn = (cos∂x + sin∂y)2L = cos2

αLxx +2cosαsinαLxy + sin2αLyy

=L2

x√L2

x +L2y

Lxx +2LxLy√L2

x +L2y

Lxy +L2

y√L2

x +L2y

Lyy

=(L2

xLxx +2LxLyLxy +L2yLyy)√

L2x +L2

y

= 0

• Since denominator is irrelevant, edges are given by

L2xLxx +2LxLyLxy +L2

yLyy = 0

L3xLxxx +3L2

xLyLxxy +3LxL2yLxyy +L3

yLyyy ≤ 0

48

Page 49: EDGE DETECTION - KTH

Summary: gradient based edge detection

• Edges correspond to abrupt changes in image intensity.

• Edges can be detected by

– Smooth out image noise.– Estimate the gradient of the image at every point in the image.– Threshold the gradient image.

AND / OR– Find points where the gradient is maximum in the gradient direction.– Connect edge pixels into edge segments.

49

Page 50: EDGE DETECTION - KTH

Detecting Edges by Matching

Idea: Match local image patches to a set of edge models withdifferent orientation.

Direction = orientation of best match (strongest response)

Edge strength = strongest response

Example: (−1 1−1 1

),(

0√

2−√

2 0

),(

1 1−1 −1

),(√

2 00 −

√2

)Natural measure: Normalized cross correlation

C f g =C f g√

C f f√

Cgg

50

Page 51: EDGE DETECTION - KTH

Summary of good questions

• Why is edge detection important for image understanding?

• Why is edge detection difficult in practice?

• What families of methods exist for edge detection?

• What information do image gradients provide?

• Why can Laplacians be useful for edge detection?

• Why are differences of Gaussians interesting?

• How does the Canny edge detector work?

• What is hysteresis thresholding?

• What should the image derivatives be equal to on edge points?

51

Page 52: EDGE DETECTION - KTH

Readings

• Related sections of Chapter 4, 5 and 10

52