image analysis edge detection - cs.uoi.gr

31
1 Image Analysis Edge Detection Christophoros Nikou [email protected] Edge Detection University of Ioannina - Department of Computer Science Images taken from: Computer Vision course by Kristen Grauman, University of Texas at Austin (http://www.cs.utexas.edu/~grauman/courses/spring2011/index.html ). Computer Vision course by Svetlana Lazebnik, University of North Carolina at Chapel Hill (http://www.cs.unc.edu/~lazebnik/spring10/ ). D. Forsyth and J. Ponce. Computer Vision: A Modern Approach, Prentice Hall, 2003. R. Gonzalez and R. Woods. Digital Image Processing, Prentice Hall, 2008. 2 Edge detection Goal: Identify sudden changes (discontinuities) in an image. – Intuitively, most semantic and shape information from the image can be encoded in the edges. – More compact than pixels. C. Nikou – Image Analysis (T-14) Ideal: artist’s line drawing (artist also uses object-level knowledge) Source: D. Lowe

Upload: others

Post on 07-Jan-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image Analysis Edge Detection - cs.uoi.gr

1

Image Analysis

Edge Detection

Christophoros [email protected]

Edge Detection

University of Ioannina - Department of Computer Science

Images taken from:Computer Vision course by Kristen Grauman, University of Texas at Austin(http://www.cs.utexas.edu/~grauman/courses/spring2011/index.html).Computer Vision course by Svetlana Lazebnik, University of North Carolina at Chapel Hill(http://www.cs.unc.edu/~lazebnik/spring10/).D. Forsyth and J. Ponce. Computer Vision: A Modern Approach, Prentice Hall, 2003.R. Gonzalez and R. Woods. Digital Image Processing, Prentice Hall, 2008.

2 Edge detection

• Goal: Identify sudden changes (discontinuities) in an image.

– Intuitively, most semantic and shape information from the image can be encoded in the edges.

– More compact than pixels.

C. Nikou – Image Analysis (T-14)

• Ideal: artist’s line drawing (artist also uses object-level knowledge)

Source: D. Lowe

Page 2: Image Analysis Edge Detection - cs.uoi.gr

2

3 Origin of Edges

surface normal discontinuity

depth discontinuity

surface color discontinuity

illumination discontinuity

C. Nikou – Image Analysis (T-14)

• Edges are caused by a variety of factors

Source: Steve Seitz

4 Edge model

C. Nikou – Image Analysis (T-14)

Page 3: Image Analysis Edge Detection - cs.uoi.gr

3

5 Edge model (cont.)

Edge point detection• Magnitude of the first

derivative.• Sign change of the second

derivative.

Observations:• Second derivative produces

C. Nikou – Image Analysis (T-14)

two values for an edge (undesirable).

• Its zero crossings may be used to locate the centres of thick edges.

6 Image gradient• The gradient of an image:

The gradient points in the direction of most rapid increase in intensity

The gradient direction is given by

C. Nikou – Image Analysis (T-14)

The gradient direction is given by• how does this relate to the direction of the edge?

The edge strength is given by the gradient magnitude

Source: Steve Seitz

Page 4: Image Analysis Edge Detection - cs.uoi.gr

4

7 Differentiation and convolution

• Recall, for 2D function, f(x,y):

• Approximation:

∂f f ( ) f ( )

• This is linear and shift invariant It is therefore

which is a convolution with the mask:

∂f

∂x= lim

ε→0

f x + ε, y( )ε

−f x,y( )

ε⎛ ⎝ ⎜

⎞ ⎠ ⎟

∂f∂x

≈f xn+1,y( )− f xn , y( )

Δx

C. Nikou – Image Analysis (T-14)

invariant. It is therefore the result of a convolution.

-1 1

Source: D. Forsyth, D. Lowe

8 Finite difference filters

• Other approximations of derivative filters:

C. Nikou – Image Analysis (T-14) Source: K. Grauman

Page 5: Image Analysis Edge Detection - cs.uoi.gr

5

9 Finite differences: example

C. Nikou – Image Analysis (T-14)

10Effect of Finite Differences on White

NoiseLet f be an observed instance of the image f0corrupted by noise w:p y

with noise samples having mean value E[w(n)]=0 and being uncorrelated with

0f f w= +

C. Nikou – Image Analysis (T-14)

[ ( )] grespect to location:

2 ,[ ( ) ( )]

0,m n

E w m w nm n

σ⎧ == ⎨

≠⎩

Page 6: Image Analysis Edge Detection - cs.uoi.gr

6

11Effect of Finite Differences on White

Noise (cont.)Applying a filter h to the degraded image:

*h f *( )h f

The expected value of the output is:

*g h f= 0*( )h f w= + 0* *h f h w= +

0[ ] [ * ] [ * ]E g E h f E h w= + 0* * [ ]h f h E w= +

C. Nikou – Image Analysis (T-14)

The noise is removed in average.0* *0h f h= + 0*h f=

12Effect of Finite Differences on White

Noise (cont.)What happens to the standard deviation of g?

N2 2 2

1

( )N

gi

h kσ σ=

= ∑

Assume that a finite difference filter is used, which approximates the first derivative:

C. Nikou – Image Analysis (T-14)

2 22gσ σ=-1 1

Page 7: Image Analysis Edge Detection - cs.uoi.gr

7

13Effect of Finite Differences on White

Noise (cont.)For a second derivative approximation:

0001-21000

2 26gσ σ=

The standard deviation increases sharply!

C. Nikou – Image Analysis (T-14)

The standard deviation increases sharply!Higher order coefficients form a Pascal triangle.

14Effect of Finite Differences on White

Noise (cont.)Another perspective: differentiation in the Fourier domain:Fourier domain:

( ) ( )d f x j Fdx

↔ Ω Ω

High frequencies are heavily emphasized

C. Nikou – Image Analysis (T-14)

with respect to low spatial frequencies.

Page 8: Image Analysis Edge Detection - cs.uoi.gr

8

15 Edge model and noiseIntensity profile First derivative Second derivative

C. Nikou – Image Analysis (T-14)

16 Edge model and noise (cont.)Intensity profile First derivative Second derivative

C. Nikou – Image Analysis (T-14)

Page 9: Image Analysis Edge Detection - cs.uoi.gr

9

17 Noise

• Edge detectors respond strongly to sharp changes and noise is a sharp change.g p g

• As we have seen, simple finite differences are unusable.

• Noise is sometimes useful! – Pictures in a dark room with the lens cap on

C. Nikou – Image Analysis (T-14)

helps to determine information about the camera temperature.

18 Noise (cont.)

• Independent additive stationary Gaussian noise is the simplest model.I• Issues

– this model allows noise values that could be greater than maximum camera output or less than zero.

– for small standard deviations, this isn’t too much of a problem - it’s a fairly good model.

– independence may not be justified (e.g. damage to

C. Nikou – Image Analysis (T-14)

p y j ( g glens).

– may not be stationary (e.g. thermal gradients in the ccd).

Page 10: Image Analysis Edge Detection - cs.uoi.gr

10

19 Why smoothing helps

Smoothing (e.g. average) kernels have

2

1 1 1 1( , ) 1 ( , ) 1

N N N N

i j i jh i j h i j

= = = =

= ⇔ ≤∑∑ ∑∑Therefore, the noise standard deviation is reduced at the output, as we saw before.

C. Nikou – Image Analysis (T-14)

Also, after smoothing (e.g. average), noise samples are no longer independent. They look like their neighbors and the derivatives are smaller.

20 Application of noise smoothing

In computer graphics, noise smoothing is widely used as it is a source of representingwidely used as it is a source of representing natural textures (e.g. smoke).

C. Nikou – Image Analysis (T-14)

Page 11: Image Analysis Edge Detection - cs.uoi.gr

11

21 Noisy Edge Smoothing

f

g

f * g

C. Nikou – Image Analysis (T-14)

• To find edges, look for peaks in )( gfdxd

)( gfdxd

Source: S. Seitz

22

gdxdfgf

dxd

∗=∗ )(

Convolution property

f

d

• Convolve with the derivative of the filter.

C. Nikou – Image Analysis (T-14)

gdxdf ∗

gdxd

Source: S. Seitz

Page 12: Image Analysis Edge Detection - cs.uoi.gr

12

23 Derivative of Gaussian

* [1 -1] =

C. Nikou – Image Analysis (T-14)

24 Derivative of Gaussian (cont.)

x-direction y-direction

C. Nikou – Image Analysis (T-14)

Page 13: Image Analysis Edge Detection - cs.uoi.gr

13

25Tradeoff between smoothing and

localization

C. Nikou – Image Analysis (T-14)

Smoothed derivative removes noise but blurs edge. It also finds edges at different “scales” affecting the semantics of the edge.

σ =1

Source: D. Forsyth

σ =3 σ =7

26 The LoG operator

A good place to look for edges is the maxima of the first derivative or the zeros of the second derivative.The 2D extension approximates the second derivative by the Laplacian operator (which is rotationally invariant):

2 22

2 2( , ) f ff x yx y

∂ ∂∇ = +

∂ ∂

M d Hild th [1980] d th t ti f t t

C. Nikou – Image Analysis (T-14)

Marr and Hildreth [1980] argued that a satisfactory operator that could be tuned in scale to detect edges is the Laplacianof the Gaussian (LoG).

D. Marr and E. Hildreth. Theory of Edge Detection, Proceedings of the Royal Society of London, B-207, pp. 187-207, 1980.

Page 14: Image Analysis Edge Detection - cs.uoi.gr

14

27 The LoG operator (cont.)

( )2 2( , )* ( , ) ( , )* ( , )G x y f x y G x y f x y∇ = ∇

• The zero crossings of the operator indicate edge pixels

• The LoG operator is given by:2 2

22 2 2 2 2

2 22 2 4

2( , )x yG G x yG x y e

x yσσ

σ

+−⎛ ⎞∂ ∂ + −

∇ = + = ⎜ ⎟∂ ∂ ⎝ ⎠

C. Nikou – Image Analysis (T-14)

• The zero crossings of the operator indicate edge pixels. These may be computed, for instance, by using a 3x3 window around a pixel and detect if two of its opposite neighbors have different signs (and their difference is significant compared to a threshold) in result of the LoGoperator.

28 The LoG operator (cont.)2 2

22 2 2 2 2

2 22 2 4

2( , )x yG G x yG x y e

x yσσ

σ

+−⎛ ⎞∂ ∂ + −

∇ = + = ⎜ ⎟∂ ∂ ⎝ ⎠

C. Nikou – Image Analysis (T-14)

Page 15: Image Analysis Edge Detection - cs.uoi.gr

15

29 The LoG operator (cont.)

Image LoG

ZeroZero crossings with a threshold

C. Nikou – Image Analysis (T-14)

Zerocrossings

with a threshold of 4% of the image max

30 The LoG operator (cont.)Contrast threshold = 1 Contrast threshold = 4

σ =2

C. Nikou – Image Analysis (T-14)

σ =4

Page 16: Image Analysis Edge Detection - cs.uoi.gr

16

31 The LoG operator (cont.)

• Filter the image at various scales and keep the zero crossings that are common to all responsescrossings that are common to all responses.

• Marr and Hildreth [1980] showed that LoG may be approximated by a difference of Gaussinas (DOG):

2 2 2 2

2 21 22 2

1 22 21 2

1 1DoG( , ) ,2 2

x y x y

x y e eσ σ σ σπσ πσ

+ +− −

= − >

C. Nikou – Image Analysis (T-14)

• Certain channels of the human visual system are selective with respect to orientation and frequency and can be modeled by a DoG with a ratio of standard deviations of 1.75.

32 The LoG operator (cont.)

• Meaningful comparison between LoG and DoG may be obtained after selecting theDoG may be obtained after selecting the value of σ for LoG so that LoG has the same zero crossings as DoG:

2 2 22 1 2 1

2 2 2lnσ σ σσ⎛ ⎞

= ⎜ ⎟

C. Nikou – Image Analysis (T-14)

2 2 21 2 2σ σ σ⎜ ⎟− ⎝ ⎠

• The two functions should also be scaled to have the same value at the origin.

Page 17: Image Analysis Edge Detection - cs.uoi.gr

17

33 The LoG operator (cont.)

• LoG has fallen to some disfavour.• It is not oriented and its response averages the• It is not oriented and its response averages the

responses across the two directions.– Poor response at corners.– Difficulty in recording the topology of T-junctions

(trihedral vertices).• Several studies showed that image components

C. Nikou – Image Analysis (T-14)

Several studies showed that image components along an edge contribute to the response of LoG to noise but not to a true edge. Thus, zero crossings may not lie exactly on an edge.

34 The LoG operator (cont.)

Poor corner and trihedral vertices detection

C. Nikou – Image Analysis (T-14)

Page 18: Image Analysis Edge Detection - cs.uoi.gr

18

35Problems with gradient-based edge

detectors

σ =1 σ =2There are three major issues:

C. Nikou – Image Analysis (T-14)

1. The gradient magnitude at different scales is different; which scale should we choose?

2. The gradient magnitude is large along thick trail; how do we identify only the significant points?

3. How do we link the relevant points up into curves?

36 Designing an optimal edge detector• Criteria for an “optimal” edge detector [Canny 1986]:

– Good detection: the optimal detector must minimize the probability of false positives (detecting spurious edges caused by noise), as well as th t f f l ti ( i i l d )that of false negatives (missing real edges).

– Good localization: the edges detected must be as close as possible to the true edges

– Single response: the detector must return one point only for each true edge point; that is, minimize the number of local maxima around the true edge.

C. Nikou – Image Analysis (T-14) Source: L. Fei-Fei

Page 19: Image Analysis Edge Detection - cs.uoi.gr

19

37 Canny edge detector

• Probably the most widely used edge detector in computer vision.p

• Theoretical model: step-edges corrupted by additive Gaussian noise.

• Canny has shown that the first derivative of the Gaussian closely approximates the

C. Nikou – Image Analysis (T-14)

operator that optimizes the product of signal-to-noise ratio and localization.

J. Canny, A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8:679-714, 1986.

Source: L. Fei-Fei

38 Canny edge detector (cont.)

1. Filter image with derivative of Gaussian. 2 Find magnitude and orientation of2. Find magnitude and orientation of

gradient.3. Non-maximum suppression:

– Thin multi-pixel wide “ridges” down to single pixel width.

C. Nikou – Image Analysis (T-14)

4. Linking and thresholding (hysteresis):– Define two thresholds: low and high– Use the high threshold to start edge curves

and the low threshold to continue them.Source: D. Lowe, L. Fei-Fei

Page 20: Image Analysis Edge Detection - cs.uoi.gr

20

39 Canny edge detector (cont.)

C. Nikou – Image Analysis (T-14)

original image

40 Canny edge detector (cont.)

C. Nikou – Image Analysis (T-14)

Gradient magnitude

Page 21: Image Analysis Edge Detection - cs.uoi.gr

21

41 Canny edge detector (cont.)

C. Nikou – Image Analysis (T-14)

Non-maximum suppression and hysteresis thresholding

42 Non-maximum suppression (cont.)We wish to mark points along the curve where the gradient magnitude is bi tbiggest.

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

These points should form a

C. Nikou – Image Analysis (T-14)Source: D. Forsyth

pcurve.

There are then two algorithmic issues: at which point is the maximum, and where is the next one?

Page 22: Image Analysis Edge Detection - cs.uoi.gr

22

43 Non-maximum suppression (cont.)At pixel q, we have a maximum if the value of the gradient magnitudethe gradient magnitude is larger than the values at both p and at r.

Interpolation provides these values.

C. Nikou – Image Analysis (T-14)Source: D. Forsyth

44

Assume the marked point is an edge point. Then we construct the

Edge linking

Then we construct the tangent to the edge curve (which is normal to the gradient at that point) and use this to predict the next points (here either r or s).

C. Nikou – Image Analysis (T-14)

( )

Source: D. Forsyth

Page 23: Image Analysis Edge Detection - cs.uoi.gr

23

45

Reduces false edge pixels. It uses a low (TL) and a high threshold (TH) to create two additional images from the gradient magnitude image g (x y):

Hysteresis Thresholding

gradient magnitude image g (x,y):

( , ) ( , ) ( , ) ( , )( , ) , ( , )

0 otherwise 0 otherwiseL H

L H

g x y g x y T g x y g x y Tg x y g x y

≥ ≥⎧ ⎧= =⎨ ⎨

⎩ ⎩

gL(x,y) has more non zero pixels than gH(x,y). We eliminate from gL(x,y) all the common non zero pixels:

C. Nikou – Image Analysis (T-14) Source: S. Seitz

gL( y) p

( , ) ( , ) ( , )L L Hg x y g x y g x y= −

gL(x,y) and gH(x,y) may be viewed as weak and strong edge pixels.Canny suggested a ratio of 2:1 to 3:1 between the thresholds.

46

• After the thresholdings, all strong pixels are assumed to be valid edge pixels. Depending

Hysteresis Thresholding (cont.)

g p p gon the value of TH, the edges in gH(x,y)typically have gaps.

• All pixels in gL(x,y) are considered valid edge pixels if they are 8-connected to a valid edge i l i ( )

C. Nikou – Image Analysis (T-14) Source: S. Seitz

pixel in gH(x,y).

Page 24: Image Analysis Edge Detection - cs.uoi.gr

24

47 Hysteresis thresholding (cont.)

C. Nikou – Image Analysis (T-14)

high threshold(strong edges)

low threshold(weak edges)

hysteresis threshold

Source: L. Fei-Fei

48 Canny vs LoG

Image Thresholded gradient

C. Nikou – Image Analysis (T-14)

LoG Canny

Page 25: Image Analysis Edge Detection - cs.uoi.gr

25

49 Canny vs LoGImage Thresholded gradient

C. Nikou – Image Analysis (T-14)LoG Canny

50 Edge Linking

• Even after hysteresis thresholding, the detected pixels do not completely characterize edges completely due to occlusions, non-uniform illumination and noise. Edge linking may be:

– Local: requiring knowledge of edge points in a small neighborhood.

– Regional: requiring knowledge of edge

C. Nikou – Image Analysis (T-14)

points on the boundary of a region.– Global: the Hough transform, involving the

entire edge image, will be presented at a later stage in the course.

Page 26: Image Analysis Edge Detection - cs.uoi.gr

26

51 Edge Linking by Local Processing

A simple algorithm:1. Compute the gradient magnitude and angle p g g g

arrays M(x,y) and a(x,y) of the input image f(x,y).2. Let Sxy denote the neighborhood of pixel (x,y).3. A pixel (s,t) in Sxy in is linked to (x,y) if:

( , ) ( , ) and ( , ) ( , )M x y M s t E a x y a s t A− ≤ − ≤

C. Nikou – Image Analysis (T-14)

A record of linked points must be kept as the center of Sxy moves.Computationally expensive as all neighbors of every pixel should be examined.

52Edge Linking by Local Processing

(cont.)A faster algorithm:1. Compute the gradient magnitude and angle arrays

M( ) d ( ) f th i t i f( )M(x,y) and a(x,y) of the input image f(x,y).2. Form a binary image:

1 ( , ) and ( , ) [ , ]( , )

0 otherwiseM A AM x y T a x y A T A T

g x y≥ ∈ − +⎧

= ⎨⎩

C. Nikou – Image Analysis (T-14)

3. Scan the rows of g(x,y) (for Α=0) and fill (set to 1) all gaps (zeros) that do not exceed a specified length K.

4. To detect gaps in any other direction Α=θ, rotate g(x,y)by θ and apply the horizontal scanning.

Page 27: Image Analysis Edge Detection - cs.uoi.gr

27

53Edge Linking by Local Processing

(cont.)Image Gradient magnitude Horizontal linking

We may detect the licence plate from the ratio width/length (2:1 in the USA)

C. Nikou – Image Analysis (T-14)

Vertical linking Logical OR Morphological thinning

54Edge Linking by Regional

Processing• Often, the location of regions of interest is known

and pixel membership to regions is available.• Approximation of the region boundary by fitting a

polygon. Polygons are attractive because:– They capture the essential shape.– They keep the representation simple.

• Requirements

C. Nikou – Image Analysis (T-14)

– Two starting points must be specified (e.g. rightmost and leftmost points).

– The points must be ordered (e.g. clockwise).

Page 28: Image Analysis Edge Detection - cs.uoi.gr

28

55Edge Linking by Regional

Processing (cont.)• Variations of the algorithm handle both open and

closed curves.• If this is not provided, it may be determined by

distance criteria:– Uniform separation between points indicate a closed

curve.– A relatively large distance between consecutive

points with respect to the distances between other

C. Nikou – Image Analysis (T-14)

points with respect to the distances between other points indicate an open curve.

• We present here the basic mechanism for polygon fitting.

56Edge Linking by Regional

Processing (cont.)– Given the end points A and

B, compute the straight line ABAB.

– Compute the perpendicular distance from all other points to this line.

– If this distance exceeds a threshold, the

di i t C

C. Nikou – Image Analysis (T-14)

corresponding point Chaving the maximum distance from AB is declared a vertex.

– Compute lines AC and CBand continue.

Page 29: Image Analysis Edge Detection - cs.uoi.gr

29

57Edge Linking by Regional

Processing (cont.)Regional processing for edge linking is used in combination with other methods in a chain of processing.

C. Nikou – Image Analysis (T-14)

58 Edge detection is just the beginningimage human segmentation gradient magnitude

C. Nikou – Image Analysis (T-14)

• Berkeley segmentation database:http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/segbench/

Page 30: Image Analysis Edge Detection - cs.uoi.gr

30

59 Learning to detect image boundaries

Learn from humans whichhumans which combination of features is most indicative of a “good” contour?

C. Nikou – Image Analysis (T-14)

D. Martin, C. Fowlkes and J. Malik. Learning to detect natural image boundaries usinglocal brightness, color and texture cues. IEEE Transactions on Pattern Analysis andMachine Intelligence, Vol. 26, No 5, pp. 530-549, 2004.

60What features are responsible for

perceived edges?

C. Nikou – Image Analysis (T-14)

Feature profiles (oriented energy, brightness, color, and texture gradients) along the patch’s horizontal diameter

D. Martin, C. Fowlkes and J. Malik. Learning to detect natural image boundaries usinglocal brightness, color and texture cues. IEEE Transactions on Pattern Analysis andMachine Intelligence, Vol. 26, No 5, pp. 530-549, 2004.

Page 31: Image Analysis Edge Detection - cs.uoi.gr

31

61What features are responsible for

perceived edges? (cont.)

C. Nikou – Image Analysis (T-14)

D. Martin, C. Fowlkes and J. Malik. Learning to detect natural image boundaries using local brightness, color andtexture cues. IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 26, No 5, pp. 530-549, 2004.