edge detection - stanford university

35
Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 1 Edge detection n Gradient-based edge operators l Prewitt l Sobel l Roberts n Laplacian zero-crossings n Canny edge detector n Hough transform for detection of straight lines n Circle Hough Transform

Upload: khangminh22

Post on 08-Feb-2023

1 views

Category:

Documents


0 download

TRANSCRIPT

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 1

Edge detection

n Gradient-based edge operatorsl Prewittl Sobell Roberts

n Laplacian zero-crossingsn Canny edge detectorn Hough transform for detection of straight linesn Circle Hough Transform

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 2

Gradient-based edge detection

n Idea (continous-space): local gradient magnitude indicates edge strength

n Digital image: use finite differencesto approximatederivatives

n Edge templates

difference -1 1( )

central difference -1 0[ ] 1( )

Prewitt−1 0 1−1 0[ ] 1−1 0 1

⎜⎜⎜

⎟⎟⎟

Sobel−1 0 1−2 0[ ] 2−1 0 1

⎜⎜⎜

⎟⎟⎟

grad f x, y( )( ) = ∂ f x, y( )

∂x

⎝⎜

⎠⎟

2

+∂ f x, y( )

∂y

⎝⎜

⎠⎟

2

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 3

Practical edge detectors

n Edges can have any orientationn Typical edge detection scheme uses K=2 edge templatesn Some use K>2

s x,y[ ]

e1 x, yéë ùû

e2 x, yéë ùû

eK x, yéë ùû

Combination,e.g.,

ek x, yéë ùû2

orMaxk ek x, yéë ùû

edgemagnitude

(edge orientation)

M x, yéë ùû

a x, yéë ùû

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 4

Gradient filters (K=2)

Prewitt−1 0 1−1 0[ ] 1−1 0 1

⎜⎜⎜

⎟⎟⎟

−1 −1 −10 0[ ] 01 1 1

⎜⎜⎜

⎟⎟⎟

Sobel−1 0 1−2 0[ ] 2

−1 0 1

⎜⎜⎜

⎟⎟⎟

−1 −2 −10 0[ ] 0

1 2 1

⎜⎜⎜

⎟⎟⎟

Roberts 0[ ] 1-1 0

æ

èç

ö

ø÷

1[ ] 00 -1

æ

èç

ö

ø÷Central

Difference

0 0 0−1 0[ ] 10 0 0

⎜⎜⎜

⎟⎟⎟

0 −1 00 0[ ] 00 1 0

⎜⎜⎜

⎟⎟⎟

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 5

Kirsch operator (K=8)

Kirsch +5 +5 +5−3 0[ ] −3−3 −3 −3

⎜⎜⎜

⎟⎟⎟

−3 +5 +5−3 0[ ] +5−3 −3 −3

⎜⎜⎜

⎟⎟⎟

−3 −3 +5−3 0[ ] +5−3 −3 +5

⎜⎜⎜

⎟⎟⎟

−3 −3 −3−3 0[ ] +5−3 +5 +5

⎜⎜⎜

⎟⎟⎟

−3 −3 −3−3 0[ ] −3+5 +5 +5

⎜⎜⎜

⎟⎟⎟

−3 −3 −3+5 0[ ] −3+5 +5 −3

⎜⎜⎜

⎟⎟⎟

+5 −3 −3+5 0[ ] −3+5 −3 −3

⎜⎜⎜

⎟⎟⎟

+5 +5 −3+5 0[ ] −3−3 −3 −3

⎜⎜⎜

⎟⎟⎟

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 6

Magnitude of image filtered with

(log display)

Magnitude of image filtered with

(log display)

Prewitt operator example

−1 0 1−1 0[ ] 1−1 0 1

⎜⎜⎜

⎟⎟⎟

−1 −1 −10 0[ ] 01 1 1

⎜⎜⎜

⎟⎟⎟

Original1024x710

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 7

Prewitt operator example (cont.)

Sum of squared horizontal and

vertical gradients(log display)

threshold = 900 threshold = 4500 threshold = 7200

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 8

Sobel operator example

Sum of squared horizontal and

vertical gradients(log display)

threshold = 1600 threshold = 8000 threshold = 12800

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 9

Roberts operator example

Original1024x710

Magnitude of image filtered with

(log display)

Magnitude of image filtered with

(log display)

1[ ] 00 −1

⎝⎜⎜

⎠⎟⎟

0[ ] 1−1 0

⎝⎜⎜

⎠⎟⎟

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 10

Roberts operator example (cont.)

Sum of squared diagonal gradients

(log display)

threshold = 100 threshold = 500 threshold = 800

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 11

Edge orientationCentralDifference

0 0 0−1 0[ ] 10 0 0

⎜⎜⎜

⎟⎟⎟

0 −1 00 0[ ] 00 1 0

⎜⎜⎜

⎟⎟⎟

Gradient scatter plot

x-component

y-co

mpo

nent

x-componenty-

com

pone

nt

Roberts

0[ ] 1

−1 0

⎝⎜⎜

⎠⎟⎟

1[ ] 0

0 −1

⎝⎜⎜

⎠⎟⎟

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 12

Edge orientation

Sobel

−1 0 1−2 0[ ] 2

−1 0 1

⎜⎜⎜

⎟⎟⎟

−1 −2 −10 0[ ] 0

1 2 1

⎜⎜⎜

⎟⎟⎟

Prewitt

−1 0 1−1 0[ ] 1−1 0 1

⎜⎜⎜

⎟⎟⎟

−1 −1 −10 0[ ] 01 1 1

⎜⎜⎜

⎟⎟⎟

x-componenty-

com

pone

nt

x-component

y-co

mpo

nent

Gradient scatter plot

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 13

Edge orientation

5x5 “consistent”gradient operator

[Ando, 2000]

x-component

y-co

mpo

nent

Gradient scatter plot

-0.0604 -0.1632 0 0.1632 0.0604-0.4286 -1.1335 0 1.1335 0.4286-0.7448 -1.9612 0[ ] 1.9612 0.7448-0.4286 -1.1335 0 1.1335 0.4286-0.0604 -0.1632 0 0.1632 0.0604

⎜⎜⎜⎜⎜

⎟⎟⎟⎟⎟

-0.0604 -0.4286 -0.7448 -0.4286 -0.0604-0.1632 -1.1335 -1.9612 -1.1335 -0.1632

0 0 0[ ] 0 00.1632 1.1335 1.9612 1.1335 0.1632 0.0604 0.4286 0.7448 0.4286 0.0604

⎜⎜⎜⎜⎜

⎟⎟⎟⎟⎟

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 14

Gradient consistency problem

Knowngray

value

Calculate this valueusing gradient field

Same result,regardless of path?

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 15

Laplacian operator

n Detect edges by considering second derivative

n Isotropic (rotationally invariant) operatorn Zero-crossings mark edge location

∇2 f x, y( ) = ∂2 f x, y( )

∂x2 +∂2 f x, y( )

∂y2

Edge profile f(x)

Detectzero crossing

f’(x) f”(x)

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 16

Approximations of Laplacian operator by 3x3 filter

0 1 01 −4⎡⎣ ⎤⎦ 1

0 1 0

⎜⎜⎜⎜

⎟⎟⎟⎟

1 1 11 −8⎡⎣ ⎤⎦ 1

1 1 1

⎜⎜⎜

⎟⎟⎟

-20

2

-20

20

2

4

6

8

wxwy

|H|

-20

2

-20

20

5

10

15

wxwy

|H|

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 17

Zero crossings of Laplacian

n Sensitive to very fine detail and noise è blur image firstn Responds equally to strong and weak edges

è suppress zero-crossings with low gradient magnitude

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 18

Laplacian of Gaussian

n Filtering of image with Gaussian and Laplacian operators can be combined into convolution with Laplacian of Gaussian (LoG) operator

LoG x, y( ) = − 1πσ 4

1− x2 + y2

2σ 2

⎝⎜

⎠⎟e

−x2+y2

2σ 2

2s =

-4-2

02

4

-4-2

02

4-0.1

-0.08

-0.06

-0.04

-0.02

0

0.02

XY -4-2

02

4

-4-2

02

4-40

-30

-20

-10

0

10

XY

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 19

Discrete approximation of Laplacian of Gaussian

2s =

-20

2

-20

20

50

100

150

200

wxwy

|H|

0 0 1 2 2 2 1 0 0

0 2 3 5 5 5 3 2 0

1 3 5 3 0 3 5 3 1

2 5 3 -12 -23 -12 3 5 2

2 5 0 -23 -40 -23 0 5 2

2 5 3 -12 -23 -12 3 5 2

1 3 5 3 0 3 5 3 1

0 2 3 5 5 5 3 2 0

0 0 1 2 2 2 1 0 0

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 20

Zero crossings of LoG

2 2s = 4 2s = 8 2s =2s =

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 21

Zero crossings of LoG – gradient-based threshold

2 2s = 4 2s = 8 2s =2s =

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 22

Canny edge detector

1. Smooth image with a Gaussian filter2. Approximate gradient magnitude and angle (use Sobel, Prewitt . . .)

3. Apply nonmaxima suppression to gradient magnitude4. Double thresholding to detect strong and weak edge pixels5. Reject weak edge pixels not connected with strong edge pixels

[Canny, IEEE Trans. PAMI, 1986]

M x, y⎡⎣ ⎤⎦ ≈∂f∂x

⎝⎜

⎠⎟

2

+∂f∂y⎛

⎝⎜

⎠⎟

2

α x, y⎡⎣ ⎤⎦ ≈ tan−1 ∂f

∂y∂f∂x

⎝⎜

⎠⎟

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 23

Canny nonmaxima suppression

n Quantize edge normal to one of four directions:horizontal, -45o, vertical, +45o

n If M[x,y] is smaller than either of its neighbors in edge normal direction è suppress; else keep.

[Canny, IEEE Trans. PAMI, 1986]

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 24

Canny thresholding and suppression of weak edges

n Double-thresholding of gradient magnitude

n Typical setting: n Region labeling of edge pixelsn Reject regions without strong edge pixels

Strong edge: M x, y⎡⎣ ⎤⎦ ≥θhigh

Weak edge: θhigh > M x, y⎡⎣ ⎤⎦ ≥θ low

θhigh θ low = 2...3

[Canny, IEEE Trans. PAMI, 1986]

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 25

Canny edge detector

2s = 2 2s = 4 2s =

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 26

Hough transform

n Problem: fit a straight line (or curve) to a set of edge pixelsn Hough transform (1962): generalized template matching techniquen Consider detection of straight lines y = mx + c

x

y

m

c

edge pixel

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 27

Hough transform (cont.)

n Subdivide (m,c) plane into discrete “bins,” initialize all bin counts by 0n Draw a line in the parameter space [m,c] for each edge pixel [x,y] and increment

bin counts along line.n Detect peak(s) in [m,c] plane

x

y

m

c

detect peak

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 28

Hough transform (cont.)

n Alternative parameterization avoids infinite-slope problem

n Similar to Radon transform

p2

xcosq + ysinq = r

x

y

r

qedge pixel

r

p-

-p2 q

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 29

Hough transform example

Original image

200 400 600 800

100

200

300

400

500

600

700

800

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 30

Hough transform example

200 400 600 800

100

200

300

400

500

600

700

800

Original image

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 31

Hough transform example

200 400 600 800

100

200

300

400

500

600

700

800

Original image

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 32

Hough transform example

Paper (3264x2448)

Global thresholding

-50 0 50

-4000

-2000

0

2000

4000 0

500

1000

1500

q

r

De-skewed Paper

-81.8 deg

-50 0 50

-4000

-2000

0

2000

4000 0

500

1000

1500

-81.8 deg

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 33

Circle Hough Transform

n Find circles of fixed radius r

n Equivalent to convolution (template matching) with a circle

x

y

0x

edge pixel

0y

Circle center

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 34

Circle Hough Transform for unknown radius

n 3-d Hough transform for parametersn 2-d Hough transform aided by edge orientation è “spokes” in parameter space

x

y

0x

edge pixel

0y

Circle center

x0 , y0 ,r( )

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Edge Detection 35

Example: circle detection by Hough transform

Original coins image

Prewitt edge detection Detected circles