edge detection and geometric primitive extraction

63
Edge Detection and Geometric Primitive Extraction Jinxiang Chai

Upload: ailsa

Post on 22-Feb-2016

46 views

Category:

Documents


0 download

DESCRIPTION

Edge Detection and Geometric Primitive Extraction. Jinxiang Chai. Outline. Edge detection Geometric primitive extraction. Edge Detection. What are edges in this image?. Edge Detection. What are edges in this image?. Origin of Edges. Edges are caused by a variety of factors. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Edge Detection and Geometric Primitive Extraction

Edge Detection and Geometric Primitive Extraction

Jinxiang Chai

Page 2: Edge Detection and Geometric Primitive Extraction

Outline

Edge detection

Geometric primitive extraction

Page 3: Edge Detection and Geometric Primitive Extraction

Edge Detection

What are edges in this image?

Page 4: Edge Detection and Geometric Primitive Extraction

Edge Detection

What are edges in this image?

Page 5: Edge Detection and Geometric Primitive Extraction

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

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

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

Gradient

A vector variable - Direction of the maximum growth of the function - Magnitude of the growth - Perpendicular to the edge direction

2

)//tan(

),(

),(

22

xfyfa

yf

xfyxf

yyfx

xfyxf

),( yxf

Page 9: Edge Detection and Geometric Primitive Extraction

Gradients

Page 10: Edge Detection and Geometric Primitive Extraction

How to Calculate Gradient?

How to compute ?xf

Intensity

Pixel column

Page 11: Edge Detection and Geometric Primitive Extraction

The Good ole’ Taylor Series

Subtracting the second from the first we obtain

...)(''21)(')()( 2 xfhxhfxfhxf

...)(''21)(')()( 2 xfhxhfxfhxf

or…

)(2

)()()(' 2hOh

hxfhxfxf

Page 12: Edge Detection and Geometric Primitive Extraction

Discrete Gradient Estimation

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

where h corresponds to the step size

hhxfhxfxf

2)()()('

Page 13: Edge Detection and Geometric Primitive Extraction

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 =>

hhxfhxfxf

2)()()('

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

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

yxIyxIyyxI

yxIyxIxyxI

Page 14: Edge Detection and Geometric Primitive Extraction

Discrete Gradient Estimation

So how can we compute the image gradient efficiently?

- Using our good old friend convolution!

101

*

101*

IyI

IxI

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

Page 15: Edge Detection and Geometric Primitive Extraction

Taking the Discrete Derivative

] 1 0 1[

abs()

Page 16: Edge Detection and Geometric Primitive Extraction

Basic Edge Detection Step 1

INPUT IMAGE

1) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

xyxI

),(

yyxI

),(

But isn’t edge detection susceptible to noise?

Page 17: Edge Detection and Geometric Primitive Extraction

Basic Edge Detection Steps 1-2

INPUT IMAGE

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

xyxI

),(

yyxI

),(

1) NoiseSmoothing

16/121242121

Page 18: Edge Detection and Geometric Primitive Extraction

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

),(

yI

xIyxG

Page 19: Edge Detection and Geometric Primitive Extraction

Basic Edge Detection (cont’d)INPUT IMAGE

1) NoiseSmoothing

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

xyxI

),(

yyxI

),(

21

22 ),(),(|),(|

yyxI

xyxIyxI

“GRADIENT” IMAGE

16/121242121

Page 20: Edge Detection and Geometric Primitive Extraction

Basic Edge Detection (cont’d)INPUT IMAGE

1) NoiseSmoothing

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

xyxI

),(

yyxI

),(

21

22 ),(),(|),(|

yyxI

xyxIyxI

“GRADIENT” IMAGE

16/121242121

What does the gradient image mean?

Page 21: Edge Detection and Geometric Primitive Extraction

Basic Edge Detection (cont’d)INPUT IMAGE

1) NoiseSmoothing

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

xyxI

),(

yyxI

),(

21

22 ),(),(|),(|

yyxI

xyxIyxI

“GRADIENT” IMAGE

16/121242121

What does the gradient image mean?

- Magnitude of intensity changes around each pixel

Page 22: Edge Detection and Geometric Primitive Extraction

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

- Thresholding!

Page 23: Edge Detection and Geometric Primitive Extraction

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

Basic Edge Detection Summary

INPUT IMAGE

1) NoiseSmoothing

EDGE IMAGE

2) EdgeEnhancement

Horizontal [-1 0 1]

Vertical [-1 0 1]T

),( yxI

xyxI

),(

yyxI

),(

21

22 ),(),(|),(|

yyxI

xyxIyxI

“GRADIENT” IMAGE

3)Threshold

16/121242121

Page 25: Edge Detection and Geometric Primitive Extraction

The effects of Filtering Noise

Threshold20

Gaussian SmoothingUnsmoothed Edges

Threshold50

Page 26: Edge Detection and Geometric Primitive Extraction

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

101202101

VSobel

121000121

HSobel

Page 27: Edge Detection and Geometric Primitive Extraction

Sobel Edge DetectionOne of the dominant edge detection schemes uses

the Sobel operators

101202101

VSobel

121000121

HSobel

- Can be approximated as a derivative of Gaussian

- First Gaussian smoothing and then compute derivatives

IxG

xIG

)(

Page 28: Edge Detection and Geometric Primitive Extraction

Sobel Edge DetectionOne of the dominant edge detection schemes uses

the Sobel operators

101202101

VSobel

121000121

HSobel

- Can be approximated as a derivative of Gaussian

- First Gaussian smoothing and then compute derivatives

IxG

xIG

)( Why?

Page 29: Edge Detection and Geometric Primitive Extraction

Sobel Edge DetectionOne of the dominant edge detection schemes uses

the Sobel operators

101202101

VSobel

121000121

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

IxG

xIG

)(

Page 30: Edge Detection and Geometric Primitive Extraction

Robert and Prewitt Edge Detectors

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

Roberts was an early edge detector kernel

101101101

VP

111000111

HP

1111

1R

1111

2R

Page 32: Edge Detection and Geometric Primitive Extraction

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

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

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

Localization with LaplacianAn 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

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

The Laplacian of Gaussian Kernel

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

2

22

24

222222 2

yx

eyxxG

xGG

Page 38: Edge Detection and Geometric Primitive Extraction

The Laplacian of Gaussian Filter Kernel

0.1

4.1

Page 39: Edge Detection and Geometric Primitive Extraction

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

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

Outline

Edge detection

Geometric primitive extraction

Page 42: Edge Detection and Geometric Primitive Extraction

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

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

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

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

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

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

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

• 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

• 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

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

features votes

Basic illustration

Page 53: Edge Detection and Geometric Primitive Extraction

Square Circle

Other shapes

Page 54: Edge Detection and Geometric Primitive Extraction

Several lines

Page 55: Edge Detection and Geometric Primitive Extraction

A more complicated image

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

Page 56: Edge Detection and Geometric Primitive Extraction

features votes

Effect of noise

Page 57: Edge Detection and Geometric Primitive Extraction

features votes

Effect of noise

• Peak gets fuzzy and hard to locate

Page 58: Edge Detection and Geometric Primitive Extraction

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

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

Line detection

• Matlab functions for line detection:

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

Page 61: Edge Detection and Geometric Primitive Extraction

Hough transform for Other Shapes • How many dimensions will the parameter

space have?

Page 62: Edge Detection and Geometric Primitive Extraction

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

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