edge detection and geometric primitive extraction jinxiang chai

63
Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Upload: reynard-fisher

Post on 13-Dec-2015

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Edge Detection and Geometric Primitive Extraction

Jinxiang Chai

Page 2: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Outline

Edge detection

Geometric primitive extraction

Page 3: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Edge Detection

What are edges in this image?

Page 4: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Edge Detection

What are edges in this image?

Page 5: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Origin of Edges

• Edges are caused by a variety of factors

depth discontinuity

surface color discontinuity

illumination discontinuity

surface normal discontinuity

Page 6: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Edge Detection

One of the most important vision problems - really easy for human - really difficult for computers - fundamental for computer vision (object recognition,

3D reconstruction, etc.)

How to tell a pixel is on the edge?

Page 7: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Characterizing edges• An edge is a place of rapid change in

the image intensity function

imageintensity function

(along horizontal scanline) first derivative

edges are related to derivative

Page 8: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Gradient

A vector variable - Direction of the maximum growth of the function

- Magnitude of the growth

- Perpendicular to the edge direction

2

)/

/tan(

),(

),(

22

xf

yfa

y

f

x

fyxf

yy

fxx

fyxf

),( yxf

Page 9: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Gradients

Page 10: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

How to Calculate Gradient?

How to compute ?x

f

Intensity

Pixel column

Page 11: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

The Good ole’ Taylor Series

Subtracting the second from the first we obtain

...)(''2

1)(')()( 2 xfhxhfxfhxf

...)(''2

1)(')()( 2 xfhxhfxfhxf

or…

)(2

)()()(' 2hO

h

hxfhxfxf

Page 12: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Discrete Gradient Estimation

For discrete functions, we can use the first order approximation of the gradient

where h corresponds to the step size

h

hxfhxfxf

2

)()()('

Page 13: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Discrete Gradient Estimation

For discrete functions, we can use the first order approximation of the gradient

where h corresponds to the step size

For our purposes, h corresponds to the width of 1 pixel =>

h

hxfhxfxf

2

)()()('

2

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

),1(),1(),(

yxIyxI

y

yxI

yxIyxI

x

yxI

Page 14: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Discrete Gradient Estimation

So how can we compute the image gradient efficiently?

- Using our good old friend convolution!

1

0

1

*

101*

Iy

I

Ix

I

- Dropped off the “divide by 2” for speed considerations.- This only scales the gradient.

Page 15: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Taking the Discrete Derivative

] 1 0 1[

abs()

Page 16: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Basic Edge Detection Step 1

INPUT IMAGE

1) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

x

yxI

),(

y

yxI

),(

But isn’t edge detection susceptible to noise?

Page 17: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Basic Edge Detection Steps 1-2

INPUT IMAGE

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

x

yxI

),(

y

yxI

),(

1) NoiseSmoothing

16/

121

242

121

Page 18: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Discrete Gradient EstimationRemember that the gradient is a vector and we have calculated the coefficients in the x and y directions at each point in the image

After convolving, we get the magnitude of the gradient from at each point (pixel) from

In practice, we often sum the absolute values of the components for computational efficiency

22

),(

y

I

x

IyxG

Page 19: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Basic Edge Detection (cont’d)

INPUT IMAGE

1) NoiseSmoothing

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

x

yxI

),(

y

yxI

),(

2

122 ),(),(

|),(|

y

yxI

x

yxIyxI

“GRADIENT” IMAGE

16/

121

242

121

Page 20: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Basic Edge Detection (cont’d)

INPUT IMAGE

1) NoiseSmoothing

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

x

yxI

),(

y

yxI

),(

2

122 ),(),(

|),(|

y

yxI

x

yxIyxI

“GRADIENT” IMAGE

16/

121

242

121

What does the gradient image mean?

Page 21: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Basic Edge Detection (cont’d)

INPUT IMAGE

1) NoiseSmoothing

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

x

yxI

),(

y

yxI

),(

2

122 ),(),(

|),(|

y

yxI

x

yxIyxI

“GRADIENT” IMAGE

16/

121

242

121

What does the gradient image mean?

- Magnitude of intensity changes around each pixel

Page 22: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Discrete Gradient EstimationSo how do we segment the edges from the rest of the scene?

- Thresholding!

Page 23: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

The Effects of ThresholdingWhile edge features are independent of illumination, the edge strength is not!

Results from threshold values of 50 and 100

Page 24: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Basic Edge Detection Summary

INPUT IMAGE

1) NoiseSmoothing

EDGE IMAGE

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

x

yxI

),(

y

yxI

),(

2

122 ),(),(

|),(|

y

yxI

x

yxIyxI

“GRADIENT” IMAGE

3)Threshold

16/

121

242

121

Page 25: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

The effects of Filtering Noise

Threshold20

Gaussian SmoothingUnsmoothed Edges

Threshold50

Page 26: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Sobel Edge DetectionOne of the dominant edge detection schemes uses the Sobel

operators

Convolving each of these with the original image generates horizontal and vertical gradient images that are combined as before

101

202

101

VSobel

121

000

121

HSobel

Page 27: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Sobel Edge Detection

One of the dominant edge detection schemes uses the Sobel operators

101

202

101

VSobel

121

000

121

HSobel

- Can be approximated as a derivative of Gaussian

- First Gaussian smoothing and then compute derivatives

Ix

G

x

IG

)(

Page 28: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Sobel Edge Detection

One of the dominant edge detection schemes uses the Sobel operators

101

202

101

VSobel

121

000

121

HSobel

- Can be approximated as a derivative of Gaussian

- First Gaussian smoothing and then compute derivatives

Ix

G

x

IG

)( Why?

Page 29: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Sobel Edge Detection

One of the dominant edge detection schemes uses the Sobel operators

101

202

101

VSobel

121

000

121

HSobel

- Can be approximated as a derivative of Gaussian

- First Gaussian smoothing and then compute derivatives

- In practice we may still need to smooth for noise

Ix

G

x

IG

)(

Page 30: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Robert and Prewitt Edge Detectors

The Prewitt is similar to the Sobel, but uses a different kernel

Roberts was an early edge detector kernel

101

101

101

VP

111

000

111

HP

11

111R

11

112R

Page 32: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Second Derivative Edge Detector

Sobel Operator can produce thick edges; ideally we are looking for infinitely thin boundaries

Page 33: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Second Derivative Edge Detector

Sobel Operator can produce thick edges; ideally we are looking for infinitely thin boundaries

An alternative approach is to look for local extrema in the first derivative

A peak in the first derivative corresponds what in the second derivative?

Page 34: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Second Derivative Edge Detector

Sobel Operator can produce thick edges; ideally we are looking for infinitely thin boundaries

An alternative approach is to look for local extrema in the first derivative

A peak in the first derivative corresponds what in the second derivative?

Page 35: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Localization with Laplacian

An equivalent measure of the second derivative in 2D is the Laplacian:

Numerically, we approximate the Laplacian using the following filtering kernel:

Zeros crossings of the filter corresponds to positions of maximum gradient.

- can be used for detecting edges - might be sensitive to noise - need to filter the image

Page 36: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Laplacian of Gaussian

In the LoG, there are two methods which are mathematically equivalent:

- Convolve the image with a gaussian smoothing filter and compute the Laplacian of the result

- Convolve the image with the linear filter that is the Laplacian of the Gaussian filter

Page 37: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

The Laplacian of Gaussian Kernel

),()()),(( 22 yxIGyxIG

2

22

24

222222 2

yx

eyx

x

G

x

GG

Page 38: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

The Laplacian of Gaussian Filter Kernel

0.1

4.1

Page 39: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

To avoid detection of insignificant edges, only the zero crossings whose corresponding first derivative is above some threshold, are selected as edge point.

Laplacian Edge Detector

Java applet: Click here

Page 40: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Edge Detection

• Matlab functions for edge detection: - BW = edge(I,'sobel') % Sobel detector

- BW = edge(I,'prewitt') % Prewitt detector

- BW = edge(I,'roberts') % Robert detector

- BW = edge(I,'log') % Laplacian of Gaussian detector

- BW = edge(I,'canny') % canny detector

Page 41: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Outline

Edge detection

Geometric primitive extraction

Page 42: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Finding straight lines

• One solution: try many possible lines and see how many points each line passes through

• Hough transform provides a fast way to do this

Page 43: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Hough transform• An early type of voting scheme

• General outline: – Discretize parameter space into bins– For each feature point in the image, put a vote in every bin in the

parameter space that could have generated this point– Find bins that have the most votes

P.V.C. Hough, Machine Analysis of Bubble Chamber Pictures, Proc. Int. Conf. High Energy Accelerators and Instrumentation, 1959

Image space Hough parameter space

Page 44: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Parameter space representation

• A line in the image corresponds to a point in Hough space

Image space Hough parameter space

Source: S. Seitz

Page 45: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Parameter space representation• What does a point (x0, y0) in the image

space map to in the Hough space?

Image space Hough parameter space

Page 46: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Parameter space representation• What does a point (x0, y0) in the image

space map to in the Hough space?– Answer: the solutions of b = –x0m + y0

– This is a line in Hough spaceImage space Hough parameter space

Page 47: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Parameter space representation• Where is the line that contains both (x0,

y0) and (x1, y1)?

Image space Hough parameter space

(x0, y0)

(x1, y1)

b = –x1m + y1

Page 48: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Parameter space representation• Where is the line that contains both (x0,

y0) and (x1, y1)?– It is the intersection of the lines b = –x0m + y0 and

b = –x1m + y1

Image space Hough parameter space

(x0, y0)

(x1, y1)

b = –x1m + y1

Page 49: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

• Problems with the (m,b) space:– Unbounded parameter domain– Vertical lines require infinite m

Parameter space representation

Page 50: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

• Problems with the (m,b) space:– Unbounded parameter domain– Vertical lines require infinite m

• Alternative: polar representation

Parameter space representation

sincos yx

Each point will add a sinusoid in the (,) parameter space

Page 51: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Algorithm outline• Initialize accumulator H

to all zeros• For each edge point (x,y)

in the imageFor θ = 0 to 180 ρ = x cos θ + y sin θ H(θ, ρ) = H(θ, ρ) + 1

endend

• Find the value(s) of (θ, ρ) where H(θ, ρ) is a local maximum– The detected line in the image is given by

ρ = x cos θ + y sin θ

ρ

θ

Page 52: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

features votes

Basic illustration

Page 53: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Square Circle

Other shapes

Page 54: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Several lines

Page 55: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

A more complicated image

http://ostatic.com/files/images/ss_hough.jpg

Page 56: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

features votes

Effect of noise

Page 57: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

features votes

Effect of noise

• Peak gets fuzzy and hard to locate

Page 58: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Dealing with noise• Choose a good grid / discretization

– Too coarse: large votes obtained when too many different lines correspond to a single bucket

– Too fine: miss lines because some points that are not exactly collinear cast votes for different buckets

• Increment neighboring bins (smoothing in accumulator array)

• Try to get rid of irrelevant features – Take only edge points with significant gradient

magnitude

Page 59: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Incorporating image gradients• Recall: when we detect an

edge point, we also know its gradient direction

• But this means that the line is uniquely determined!

• Modified Hough transform:

• For each edge point (x,y) θ = gradient orientation at (x,y)ρ = x cos θ + y sin θH(θ, ρ) = H(θ, ρ) + 1

end

Page 60: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Line detection

• Matlab functions for line detection:

[H, theta, rho] = hough(BW)

Page 61: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Hough transform for Other Shapes 

• How many dimensions will the parameter space have?

Page 62: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Hough transform for Other Shapes 

• How many dimensions will the parameter space have?

(x0,y0, r) (x0,y0, a,b,theta)

Page 63: Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Things to remember

• Edge detector - First order method: smooth-

>gradients->thresholding

- Second order method: zero crossings for LOG

• Hough transform = points vote for shape parameters