edge detection - tucpetrakis/courses/computervision... · e.g.m. petrakis edge detection 5. edge...

43
E.G.M. Petrakis Edge Detection 1 Edge Detection • Edges: local changes in the image intensity Edges typically occur on the boundary between two regions Important features for image analysis The changes due to noise are not edges – real images are very noisy – its very difficult to find edges in noisy images The changes due to shading are not edges

Upload: doanminh

Post on 17-Apr-2018

222 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 1

Edge Detection

• Edges: local changes in the image intensity• Edges typically occur on the boundary

between two regions• Important features for image analysis• The changes due to noise are not edges

– real images are very noisy– its very difficult to find edges in noisy images

• The changes due to shading are not edges

Page 2: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 2

I.

line of profile

Original noisy imageII. Edge profile

• The edges are not perfectly sharp

Page 3: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 3

Ideal Edges

step

roof

ramp

line

Page 4: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 4

Noisy Edgesstep

orramp

line or

roof

Page 5: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 5

Edge Detection

• An edge point is a point at the location of a local intensity change

• An edge detector is an algorithm that computes the edges in an image

• A contour is a list of edges or the curve that matches the list of edges

• Edge following is the process of searching the image to determine contours

Page 6: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 6

Edge Results

• The produced set of edges contain – correct edges corresponding to real - useful

information e.g., object boundaries– false edges do not correspond to real edges e.g.,

noise• There are also missing edges

– edge linking may try to recover missing edges– edge following will form contours from

existing and recovered edges

Page 7: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 7

First Derivative Operator

• Gradient: vector denoting the max rate of change of intensity f(x,y):

– direction

– magnitude

jyfi

xff

rrr

ϑϑ

ϑϑ

+=∇

∂∂

∂∂

= −

yf

xf1tanθ

...,max,22

∂∂

∂∂

∂∂

+

∂∂

yf

xf

yf

xf

Page 8: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 8

Gradient

• For any vertical directions (x,y), (x’,y’) and image f(x,y):

( ) ( )yxfyxf ′′∇=∇ ,,rr

′∂∂

′∂∂=′=

∂∂

∂∂= −−

yf

xf

yf

xf 11 tantan θθ

2222

′∂

∂+

′∂∂

=

∂∂

+

∂∂

yf

xf

yf

xf

Page 9: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 9

Digital Approximation of Gradient

• Compute

• Equivalently convolve with

( ) ( ) ( )jifjifjifG xx ,1,, −+=∆≈

( ) ( ) ( )jifjifjifG yy ,1,, +−=∆≈

[ ]11−=xG

=1

1yG

Page 10: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 10

Gradient Convolution Masks

• computes edge point at (i+1/2,j+1/2) • computes edge point at (i+1/2,j)

• 2x2 masks: edge point at (i+1/2, j+1/2)

• edge points at center pixel (i,j) use 3x3 masks

−−

=1111

xG

−−

=11

11yG

=1

1yG

[ ]11−=xG

−−−

=101202101

41

xG

−−−=

121000121

41

yG

Page 11: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 11

Roberts operator

• Computes the edge at the interpolated point (i+1/2,j+1/2)– magnitude: |Gx| + |Gy|

=10

01xG

−=

0110

yG

Page 12: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 12

Sobel Operator

• One the most commonly used edge operators– computes the edge at (i,j)– Smoothing at the same time– places emphasis on pixels closest to (i,j)

−−−

=101202101

41

xG

−−−=

121000121

41

yG

Page 13: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 13

Prewit Operator

• Similar to Sobel but does not place any emphasis on pixels

−−−

=101101101

31

xG

−−−=

111000111

31

yG

Page 14: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 14

Edge operatorswith smoothingfirst

a. Original imageb. Smoothed imagec. Gradient with 1x2,2x1 masks, T=32d. Gradient with 2x2 masks, T=64e. Roberts operator, T=64f. Sobel operator, T=225g. Prewit operator, T=225

Page 15: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 15

a. Original imageb. Simple Gradient with 1x2,2x1 masks, T=64c. Gradient with 2x2 masks, T=64d. Roberts operator, T=64e. Sobel operator, T=225f. Prewitt operator, T=225

Edge operatorswithout smoothing

Page 16: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 16

a. Noisy imageb. Filtered imagec. Simple Gradient with 1x2,2x1 masks,T=32d. Gradient with 2x2 masks, T=64e. Roberts operator, T=64f. Sobel operator, t=225g. Prewitt operator, T=225

Edge operatorswith smoothingon noisy image

Page 17: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 17

a. Noisy imageb. Simple Gradient using 1x2,2x1 masks, T=64c. Gradient using 2x2 masks, T=128d. Roberts operator, T=64e. Sobel operator, T=225f. Prewitt operator, T=225

Edge detectionon noisy imagewithout smoothing

Page 18: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 18

Edge Detection with Edge Patterns

• Comparison (filtering) with 4 or 8 edge masks– each one represents an edge orientation– combine their results– the edge pattern with the max magnitude represents the

magnitude and the orientation of the edge– thresholding is still necessary!

• Optimization: apply 4 of the 8, the other 4 are symmetric • give opposite orientations and negative values of

magnitude • take the absolute value of negative edge strengths

Page 19: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 19

Prewit Edge Patterns

−−−−

111121111

−−−−

111121111

−−−−

111121

111

−−−−

111121111

−−−

111121111

−−−−

111121111

−−−

111121111

−−−−

111121111 arrow denotes

orientation of edgedetection

Page 20: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 20

Kirsch edge patterns

−−−−−

333305355

−−−−−

335305335

−−−−−

333303

555

−−−−−

355305333

−−−−−

555303333

−−

−−−

553503333

−−−

−−

533503533

−−−−−

333503553 arrow denotes

orientation of edgedetection

Page 21: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 21

Steps in Edge Detection1. Filtering removes noise and improves the performance

of edge detection– there is a trade off between edge strength and noise reduction– filtering smoothes the edge too!!

2. Edge enhancement apply a Gradient operator3. Detection keeps only edge points and eliminates false

edge points– keep points with strong edge content– above a threshold T

4. Localization computes location and orientation of edge

Page 22: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 22

6

3

4

7

4

5

5

6

6

6

93

original image

gradient

Page 23: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 23

7

5

5

6

6

6

9

6

7

6

6

6

9

Detection and Localization

thershold T= 4 keep edges points with strength > 4noise is retained

6

thershold T= 5 keep edges points with strength > 5removes noise but significant parts of the contour are lost

Page 24: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 24

Smoothing & Thresholding

• Smoothing:– high degree of smoothing (large mask, repeated

smoothing) removes noise but blurs the edges– low degree of smoothing retains noise

• Threshold selection: – large thresholds remove noise along with edge

points– low thresholds retain noise

Page 25: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 25

Second Derivative Operators

• Edge points: peaks of the first derivative – use of thresholds – detects too many edge points

• Equivalently, zero’s of the second derivative

• Combine first and second derivatives– locate peak in the first derivative and zero

crossing in the second derivative

Page 26: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 26

Combination of Derivatives

• Edge detection – smoothing by Gaussian– presence of zero crossing in second derivative

– large peak in the first derivative

[ ] 0,2 ≈∇ jifr

[ ] Thresholdjif >∇ ,r

Page 27: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 27

all points in [a,b] are edge points

edge point

Page 28: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 28

Laplacian Operator

• Two dimensional equivalent of the second derivative

• Digital approximation

( ) 2

2

2

22 ,

yf

xfyxf

∂∂

+∂∂

=∇

( ) ( ) ( ) ( )( ) ( )jifjif

jifjifjifjif,41,

1,,1,1,2

−−+++−++≈∇

Page 29: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 29

Proof

( )

],[]1,[2]2,[]),[]1,[(])1,[]2,[(

],[]1,[

],[]1,[2

2

jifjifjifjifjifjifjif

xjif

xjif

xjifjif

xG

xf x

++−+=−+−+−+

=∂

∂−

∂+∂

=∂−+∂

=∂∂

=∂∂

Page 30: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 30

Proof (2)

• Second derivative on X is centered around [i,j+1], – replace j with j-1 to center edge around [i,j]

• Similarly for Y

]1,[],[2]1,[2

2

−+−+=∂∂ jifjifjif

xf

],1[],[2],1[2

2

jifjifjifyf

−+−+=∂∂

Page 31: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 31

Laplacian Mask

• The following mask approximates the Laplacian (both x,y)

−≈∇

010141010

],[2 jif

Page 32: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 32

Response of Laplacian

• Zero’s signal the presence of an edge– trivial zeros (uniform regions) are ignored– strong response to edges, lines, points, noise!

............0

.........01000110011101111

f2∇

1231231

122111122011

13221121111111

Page 33: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 33

Response to Step Edges

888888

888888

888888

222222

222222

822

2222

2

2222

2

8

8

88

8

000000

-6-6-6-6-6-6

000000

000000

000000

060

0000

0

6666

6

0

0

00

0f2∇

edge lies between 6 and –6

• The edge point (zero crossing location) may need to be approximated to sub-pixel resolution

Page 34: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 34

Response to Ramp Edges

888888

888888

888888

222222

222222

8522

2222

2

5555

5

82

82

8282

82

000000

-3-3-3-3-3-3

000000

000000

000000

0030

3333

3

0000

0

00

00

0000

00f2∇

edge

Page 35: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 35

Laplacian of Gaussian

• The second derivative responds strongly to noise

• It is desired to filter the noise before edge detection

• The Laplacian of a Gaussian (LoG) combines Gaussian filtering with Laplacianfor edge detection

Page 36: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 36

One-Step LoG

• Notice that • In practice LoG is

applied in one step by filtering with

• Known also asMexican hat operator

fGfG ∗∇=∗∇ )()( 22

( )

−−=∇ 2

2

2

2

42

2exp

211

σσπσrrrG

Page 37: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 37

Discrete Approximation of LoG

Page 38: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 38

LoG Smoothing

• σ controls the degree of smoothing– large σ results in better noise filtering but also – blurs and displaces edges– small σ results in too many noise points and false edges– edge points are better localized using small σ

• The best size of the filter is unknown• Scale space filtering: combine results from

multiple filters with varying – resembles filtering on the retina

Page 39: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 39

LoG filtering with varying σ

Page 40: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 40

DoG Approximation of LoG

• The best engineering approximation of LoGis obtained by taking the Difference of two Gaussians (DoG) with– amplitude ratio 1:1.16

• The same mechanism operates in the retina– many filters with varying σ

Page 41: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 41

DoG: continuous line LoG: dashed line

Page 42: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 42

DoG Filtering on the Retina

Page 43: Edge Detection - TUCpetrakis/courses/computervision... · E.G.M. Petrakis Edge Detection 5. Edge Detection •An edge point is a point at the location of a local intensity change

E.G.M. Petrakis Edge Detection 43

“Center-Surround” Filtering

• Filtering by cells in retina resemble the effects of DoG– the photoreceptors are connected to retinal

gaglion cells which send visual data to the brain– “Red” photoreceptors excite “ON center”

gaglion cells (generate neural signals)– “Blue” photoreceptors in its surrounding inhibit

the gaglion cell “OFF surround”