edge detection and geometric primitive extraction

Post on 22-Feb-2016

43 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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

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

depth discontinuity

surface color discontinuity

illumination discontinuity

surface normal discontinuity

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?

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

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

Gradients

How to Calculate Gradient?

How to compute ?xf

Intensity

Pixel column

The Good ole’ Taylor Series

Subtracting the second from the first we obtain

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

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

or…

)(2

)()()(' 2hOh

hxfhxfxf

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)()()('

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

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.

Taking the Discrete Derivative

] 1 0 1[

abs()

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?

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

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

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

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?

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

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

- Thresholding!

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

Results from threshold values of 50 and 100

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

The effects of Filtering Noise

Threshold20

Gaussian SmoothingUnsmoothed Edges

Threshold50

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

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

)(

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?

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

)(

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

Second Derivative Edge Detector

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

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?

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?

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

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

The Laplacian of Gaussian Kernel

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

2

22

24

222222 2

yx

eyxxG

xGG

The Laplacian of Gaussian Filter Kernel

0.1

4.1

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

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

Outline

Edge detection

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

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

Parameter space representation• A line in the image corresponds to a point

in Hough space

Image space Hough parameter space

Source: S. Seitz

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

space map to in the Hough space?

Image space Hough parameter space

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

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

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

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

Parameter space representation

• 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

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 θ

ρ

θ

features votes

Basic illustration

Square Circle

Other shapes

Several lines

A more complicated image

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

features votes

Effect of noise

features votes

Effect of noise

• Peak gets fuzzy and hard to locate

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

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

Line detection

• Matlab functions for line detection:

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

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

space have?

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

space have?

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

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

top related