Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl...

54
Photo by Carl Warner

Transcript of Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl...

Page 1: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Photo by Carl Warner

Page 2: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Photo by Carl Warner

Page 3: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Photo by Carl Warner

Page 4: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Feature Matching and Robust Fitting

Computer Vision

James Hays

Acknowledgment: Many slides from Derek Hoiem and Grauman&Leibe 2008 AAAI Tutorial

Read Szeliski 4.1

Page 5: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Project 2

Page 6: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

This section: correspondence and alignment

• Correspondence: matching points, patches, edges, or regions across images

Page 7: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Overview of Keypoint Matching

K. Grauman, B. Leibe

AfBf

A1

A2 A3

Tffd BA ),(

1. Find a set of

distinctive key-

points

3. Extract and

normalize the

region content

2. Define a region

around each

keypoint

4. Compute a local

descriptor from the

normalized region

5. Match local

descriptors

Page 8: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Harris Corners – Why so complicated?

• Can’t we just check for regions with lots of gradients in the x and y directions?

– No! A diagonal line would satisfy that criteria

Current

Window

Page 9: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Harris Detector [Harris88]

• Second moment matrix

)()(

)()()(),(

2

2

DyDyx

DyxDx

IDIIII

IIIg

9

1. Image

derivatives

2. Square of

derivatives

3. Gaussian

filter g(I)

Ix Iy

Ix2 Iy

2 IxIy

g(Ix2) g(Iy

2) g(IxIy)

222222 )]()([)]([)()( yxyxyx IgIgIIgIgIg

])),([trace()],(det[ 2

DIDIhar

4. Cornerness function – both eigenvalues are strong

har5. Non-maxima suppression

1 2

1 2

det

trace

M

M

(optionally, blur first)

Page 10: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Harris Corners – Why so complicated?

• What does the structure matrix look here?

CC

CC

Current

Window

Page 11: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Harris Corners – Why so complicated?

• What does the structure matrix look here?

00

0C

Current

Window

Page 12: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Harris Corners – Why so complicated?

• What does the structure matrix look here?

C

C

0

0

Current

Window

Page 13: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Affine intensity change

• Only derivatives are used =>

invariance to intensity shift I I + b

• Intensity scaling: I a I

R

x (image coordinate)

threshold

R

x (image coordinate)

Partially invariant to affine intensity change

I a I + b

Page 14: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Image translation

• Derivatives and window function are shift-invariant

Corner location is covariant w.r.t. translation

Page 15: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Image rotation

Second moment ellipse rotates but its shape

(i.e. eigenvalues) remains the same

Corner location is covariant w.r.t. rotation

Page 16: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Scaling

All points will

be classified

as edges

Corner

Corner location is not covariant to scaling!

Page 17: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Review: Local Descriptors

• Most features can be thought of as templates, histograms (counts), or combinations

• The ideal descriptor should be

– Robust and Distinctive

– Compact and Efficient

• Most available descriptors focus on edge/gradient information

– Capture texture information

– Color rarely used

K. Grauman, B. Leibe

Page 18: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Feature Matching

• Simple criteria: One feature matches to another if those features are nearest neighbors and their distance is below some threshold.

• Problems:

– Threshold is difficult to set

– Non-distinctive features could have lots of close matches, only one of which is correct

Page 19: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Distance: 0.34, 0.30, 0.40

Distance: 0.61, 1.22

How do we decide which features match?

Page 20: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Nearest Neighbor Distance Ratio

•𝑁𝑁1

𝑁𝑁2where NN1 is the distance to the first

nearest neighbor and NN2 is the distance to the second nearest neighbor.

• Sorting by this ratio puts matches in order of confidence.

Page 21: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Can we refine this further?

Page 22: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Fitting: find the parameters of a model that best fit the data

Alignment: find the parameters of the transformation that best align matched points

Page 23: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Fitting and Alignment

• Design challenges

– Design a suitable goodness of fit measure

• Similarity should reflect application goals

• Encode robustness to outliers and noise

– Design an optimization method

• Avoid local optima

• Find best parameters quickly

Page 24: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Fitting and Alignment: Methods

• Global optimization / Search for parameters

– Least squares fit

– Robust least squares

– Iterative closest point (ICP)

• Hypothesize and test

– Generalized Hough transform

– RANSAC

Page 25: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Simple example: Fitting a line

Page 26: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Least squares line fitting•Data: (x1, y1), …, (xn, yn)

•Line equation: yi = m xi + b

•Find (m, b) to minimize

022 yAApATT

dp

dE

)()()(2

1

1

12

2

11

1

2

ApApyApyy

yAp

TTT

nn

n

i ii

y

y

b

m

x

x

yb

mxE

n

i ii bxmyE1

2)(

(xi, yi)

y=mx+b

yAAApyAApATTTT 1

Matlab: p = A \ y;

Modified from S. Lazebnik

Page 27: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Least squares (global) optimization

Good• Clearly specified objective

• Optimization is easy

Bad• May not be what you want to optimize

• Sensitive to outliers– Bad matches, extra points

• Doesn’t allow you to get multiple good fits– Detecting multiple objects, lines, etc.

Page 28: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Least squares: Robustness to noise

• Least squares fit to the red points:

Page 29: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Least squares: Robustness to noise

• Least squares fit with an outlier:

Problem: squared error heavily penalizes outliers

Page 30: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Fitting and Alignment: Methods

• Global optimization / Search for parameters

– Least squares fit

– Robust least squares

– Iterative closest point (ICP)

• Hypothesize and test

– Generalized Hough transform

– RANSAC

Page 31: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Robust least squares (to deal with outliers)General approach:

minimize

ui (xi, θ) – residual of ith point w.r.t. model parameters θρ – robust function with scale parameter σ

;,xu ii

i

The robust function ρ• Favors a configuration

with small residuals

• Constant penalty for large

residuals

n

i ii bxmyu1

22 )(

Slide from S. Savarese

Page 32: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Choosing the scale: Just right

The effect of the outlier is minimized

Page 33: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

The error value is almost the same for every

point and the fit is very poor

Choosing the scale: Too small

Page 34: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Choosing the scale: Too large

Behaves much the same as least squares

Page 35: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Robust estimation: Details

• Robust fitting is a nonlinear optimization problem that must be solved iteratively

• Least squares solution can be used for initialization

• Scale of robust function should be chosen adaptively based on median residual

Page 36: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Other ways to search for parameters (for when no closed form solution exists)

• Line search1. For each parameter, step through values and choose value

that gives best fit2. Repeat (1) until no parameter changes

• Grid search1. Propose several sets of parameters, evenly sampled in the

joint set2. Choose best (or top few) and sample joint parameters around

the current best; repeat

• Gradient descent1. Provide initial position (e.g., random)2. Locally search for better parameters by following gradient

Page 37: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Fitting and Alignment: Methods

• Global optimization / Search for parameters

– Least squares fit

– Robust least squares

– Iterative closest point (ICP)

• Hypothesize and test

– Generalized Hough transform

– RANSAC

Page 38: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Hypothesize and test

1. Propose parameters– Try all possible

– Each point votes for all consistent parameters

– Repeatedly sample enough points to solve for parameters

2. Score the given parameters– Number of consistent points, possibly weighted by

distance

3. Choose from among the set of parameters– Global or local maximum of scores

4. Possibly refine parameters using inliers

Page 39: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Fitting and Alignment: Methods

• Global optimization / Search for parameters

– Least squares fit

– Robust least squares

– Iterative closest point (ICP)

• Hypothesize and test

– Generalized Hough transform

– RANSAC

Page 40: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Hough Transform: Outline

1. Create a grid of parameter values

2. Each point votes for a set of parameters, incrementing those values in grid

3. Find maximum or local maxima in grid

Page 41: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

x

y

b

m

y = m x + b

Hough transform

Given a set of points, find the curve or line that explains

the data points best

P.V.C. Hough, Machine Analysis of Bubble Chamber Pictures, Proc. Int. Conf. High

Energy Accelerators and Instrumentation, 1959

Hough space

Slide from S. Savarese

Page 42: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

x

y

b

m

x

y m3 5 3 3 2 2

3 7 11 10 4 3

2 3 1 4 5 2

2 1 0 1 3 3

b

Hough transform

Slide from S. Savarese

Page 43: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

x

y

Hough transform

Issue : parameter space [m,b] is unbounded…

P.V.C. Hough, Machine Analysis of Bubble Chamber Pictures, Proc. Int. Conf. High

Energy Accelerators and Instrumentation, 1959

Hough space

siny cosx

Use a polar representation for the parameter space

Slide from S. Savarese

Page 44: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

features votes

Hough transform - experiments

Slide from S. Savarese

Page 45: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

features votes

Need to adjust grid size or smooth

Hough transform - experiments

Noisy data

Slide from S. Savarese

Page 46: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Issue: spurious peaks due to uniform noise

features votes

Hough transform - experiments

Slide from S. Savarese

Page 47: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

1. Image Canny

Page 48: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

2. Canny Hough votes

Page 49: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

3. Hough votes Edges

Find peaks and post-process

Page 50: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Hough transform example

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

Page 51: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

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 52: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Finding lines using Hough transform

• Using m,b parameterization

• Using r, theta parameterization

– Using oriented gradients

• Practical considerations

– Bin size

– Smoothing

– Finding multiple lines

– Finding line segments

Page 53: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Hough Transform

• How would we find circles?

– Of fixed radius

– Of unknown radius

– Of unknown radius but with known edge

orientation

Page 54: Photo by Carl Warner - gatech.eduhays/compvision2017/lectures/... · 2017. 9. 18. · Photo by Carl Warner. Feature Matching and Robust Fitting Computer Vision James Hays Acknowledgment:

Next lecture

• RANSAC

• Connecting model fitting with feature matching