edge detection, lines, hough transform · 2d edge detection: canny 1. filter out noise – use a 2d...
TRANSCRIPT
CSE152, Spr 07 Intro Computer Vision
Edge Detection, Lines, Hough Transform
Introduction to Computer VisionCSE 152
Lecture 10
CSE152, Spr 07 Intro Computer Vision
Announcements
• Assignment 2 on tracking due Tuesday, May 8.• Midterm: Thursday, May 10.
CSE152, Spr 07 Intro Computer Vision
Last Lecture
CSE152, Spr 07 Intro Computer Vision
Median filters : examplefilters have width 5 :
CSE152, Spr 07 Intro Computer Vision
Edges
1. Object boundaries2. Surface normal discontinuities3. Reflectance (albedo) discontinuities4. Lighting discontinuities (shadow boundaries)
CSE152, Spr 07 Intro Computer Vision
Edge is Where Change Occurs: 1-D• Change is measured by derivative in 1D
Smoothed Edge
First Derivative
Second Derivative
Ideal Edge
• Biggest change, derivative has maximum magnitude• Or 2nd derivative is zero.
CSE152, Spr 07 Intro Computer Vision
Numerical Derivativesf(x)
xX0 X0+hX0-h
Take Taylor series expansion of f(x) about x0f(x) = f(x0)+f’(x0)(x-x0) + ½ f’’(x0)(x-x0)2 + …
Consider Samples taken at increments of h and first two terms, we have
f(x0+h) = f(x0)+f’(x0)h+ ½ f’’(x0)h2
f(x0-h) = f(x0)-f’(x0)h+ ½ f’’(x0)h2
Subtracting and adding f(x0+h) and f(x0-h) respectively yields
20
0
0
2)()(2)(
)(''
2)()(
)('
00
00
hhxfxfhxf
xf
hhxfhxf
xf
−−++−=
−−+=
CSE152, Spr 07 Intro Computer Vision
Implementing 1-D Edge Detection1. Filter out noise: convolve with Gaussian
2. Take a derivative: convolve with [-1 0 1]– We can combine 1 and 2.
3. Find the peak of the magnitude of the convolved image: Two issues:
– Should be a local maximum.– Should be sufficiently high.
CSE152, Spr 07 Intro Computer Vision
2D Edge Detection: Canny
1. Filter out noise– Use a 2D Gaussian Filter.
2. Take a derivative– Compute the magnitude of the gradient:
22
Gradient theis ,),(
yx
yx
JJJ
yJ
xJJJJ
+=∇
⎟⎟⎠
⎞⎜⎜⎝
⎛∂∂
∂∂
==∇
GIJ *=
CSE152, Spr 07 Intro Computer Vision
Next stepCan next step, be the same for 2-D edge
detector as in 1-D detector??
NO!!
CSE152, Spr 07 Intro Computer Vision
What is the gradient?
)0,(, kyI
xI
=⎟⎟⎠
⎞⎜⎜⎝
⎛∂∂
∂∂
Change
No Change
CSE152, Spr 07 Intro Computer Vision
Smoothing and Differentiation• Need two derivatives, in x and y direction. • Filter with Gaussian and then compute
gradient, or• Use a derivative of Gaussian filter
• because differentiation is convolution, and convolution is associative
CSE152, Spr 07 Intro Computer Vision
xG∂∂ σ
yG∂∂ σ
yG
xG
∂∂
+∂∂ σσ θθ sincos
θ
Directional Derivatives
CSE152, Spr 07 Intro Computer Vision
Finding derivatives
x
y
Is this dI/dx or dI/dy?
CSE152, Spr 07 Intro Computer Vision
There are three major issues: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 the significant points?3. How do we link the relevant points up into curves?
σ = 1 σ = 2
CSE152, Spr 07 Intro Computer Vision
There is ALWAYS a tradeoff between smoothing and good edge localization!
Image with Edge Edge Location
Image + Noise Derivatives detect edge and noise
Smoothed derivative removes noise, but blurs edge
CSE152, Spr 07 Intro Computer VisionThe scale of the smoothing filter affects derivative estimates1 pixel 3 pixels 7 pixels
CSE152, Spr 07 Intro Computer Vision
We wish to mark points along the curve where the magnitude is biggest.We can do this by looking for a maximum along a slice normal to the curve(non-maximum suppression). These points should form a curve. There arethen two algorithmic issues: at which point is the maximum, and where is thenext one?
Magnitude ofGradient
CSE152, Spr 07 Intro Computer Vision
Non-maximum suppression
For every pixel in the image (e.g., q) we have an estimate of edge direction and edge normal (shown at q)
CSE152, Spr 07 Intro Computer Vision
Non-maximum suppression
Using normal at q, find two points p and r on adjacent rows (or columns).
We have a maximum if the value is larger than those at both p and at r.
Interpolate to get values.
CSE152, Spr 07 Intro Computer Vision
Assume the marked point is an edge point. 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).
Non-maximum suppressionPredicting the next edge point
CSE152, Spr 07 Intro Computer Vision
Hysteresis• Track edge points by starting at point where
gradient magnitude > τhigh.
• Follow edge in direction orthogonal to gradient.
• Stop when gradient magnitude < τlow.• i.e., use a high threshold to start edge curves and a
low threshold to continue them.
τhigh
τlow
gradient magnitude
CSE152, Spr 07 Intro Computer Vision
Input image
CSE152, Spr 07 Intro Computer Vision
T=15 T=5
HysteresisTh=15 Tl = 5
Hysteresisthresholding
SingleThreshold
CSE152, Spr 07 Intro Computer Vision
CSE152, Spr 07 Intro Computer Vision
fine scale
high thresholds
CSE152, Spr 07 Intro Computer Vision
coarse scale,High thresholds
CSE152, Spr 07 Intro Computer Vision
coarsescaleLower highthresholds
CSE152, Spr 07 Intro Computer Vision
Why is Canny so Dominant• Still widely used after 20 years.
1. Theory is nice (but end result same,).2. Details good (magnitude of gradient, non-max
suppression).3. Hysteresis an important heuristic.4. Code was distributed.
CSE152, Spr 07 Intro Computer Vision
Corner Detection Sample Results
Threshold=25,000 Threshold=10,000
Threshold=5,000
CSE152, Spr 07 Intro Computer Vision
• Segment linked edge chains into curve features (e.g., line segments).
• Group unlinked or unrelated edges into lines (or curves in general).
• Accurately fitting parametric curves (e.g., lines) to grouped edge points.
What to do with edges?
CSE152, Spr 07 Intro Computer Vision
Hough Transform[ Patented 1962 ]
Finding lines in an imageOption 1:
• Search for the line at every possible position/orientation• What is the cost of this operation?
Option 2:• Use a voting scheme: Hough transform
Finding lines in an image
Connection between image (x,y) and Hough (m,b) spaces• A line in the image corresponds to a point in Hough space• To go from image space to Hough space:
– given a set of points (x,y), find all (m,b) such that y = mx + b
x
y
m
b
m0
b0
image space Hough space
Finding lines in an image
Connection between image (x,y) and Hough (m,b) spaces• A line in the image corresponds to a point in Hough space• To go from image space to Hough space:
– given a set of points (x,y), find all (m,b) such that y = mx + b• What does a point (x0, y0) in the image space map to?
x
y
m
b
image space Hough space
– A: the solutions of b = -x0m + y0
– this is a line in Hough space
x0
y0