You are on page 1of 33

CCAI-433: Computer Vision

Chapter 3-Part 2: Feature Matching and


RANSAC

AI Program
College of Computer Science and Engineering
University of Jeddah

Slides are based on 15-463 (15-862) Carnegie Mellon University


http://graphics.cs.cmu.edu/courses/15-463/2012_fall/463.html
Compiled and modified by Dr. Nuha Zamzami, CSAI, University of Jeddah
Feature matching

?
Feature matching
• Exhaustive search
• for each feature in one image, look at all the other features
in the other image(s)
• Hashing
• compute a short descriptor from each feature vector, or hash
longer descriptors (randomly)
• Nearest neighbor techniques
• k-trees and their variants
What about outliers?

?
Feature-space outlier rejection
Let’s not match all features, but only these that have
“similar enough” matches?
How can we do it?
• SSD(patch1,patch2) < threshold
• How to set threshold?
Feature-space outlier rejection
A better way [Lowe, 1999]:
• 1-NN: Sum of Squared Difference (SSD) of the closest
match
• 2-NN: SSD of the second-closest match
• Look at how much better 1-NN is than 2-NN, e.g. 1-NN/2-NN
• That is, is our best match so much better than the rest?
Feature-space outliner rejection

Can we now compute H from the blue points?


• No! Still too many outliers…
• What can we do?
Matching features

What do we do about the “bad” matches?


RAndom SAmple Consensus

Select one match, count inliers


What’s RANSAC ?
• RANSAC is an abbreviation for "RANdom SAmple
Consensus".
• It is an iterative method to estimate parameters of a
mathematical model from a set of observed data
which contains outliers.
• RANSAC can estimate a model which ignored
outliers.
Example:
• To fit a line
– Least Squares method:
» Optimally fitted to all points including outliers.
– RANSAC:
» Only computed from the inliers.

10
Illustration of RANSAC

11
Illustration of RANSAC

• Select sample of m points


at random

12
Illustration of RANSAC

• Select sample of m points


at random

• Calculate model
parameters that fit the
data in the sample

13
Illustration of RANSAC

• Select sample of m points


at random

• Calculate model
parameters that fit the
data in the sample

• Calculate error function


for each data point

14
Illustration of RANSAC

• Select sample of m points


at random

• Calculate model
parameters that fit the
data in the sample

• Calculate error function


for each data point

• Select data that support


current hypothesis

15
Illustration of RANSAC

• Select sample of m points


at random

• Calculate model
parameters that fit the
data in the sample

• Calculate error function


for each data point

• Select data that support


current hypothesis

• Repeat sampling
16
Illustration of RANSAC

• Select sample of m points


at random

• Calculate model
parameters that fit the
data in the sample

• Calculate error function


for each data point

• Select data that support


current hypothesis

• Repeat sampling
17
Illustration of RANSAC

ALL-INLIER SAMPLE
RANSAC time complexity

k … number of samples
drawn
N … number of data points
tM … time to compute a single

model
mS … average number of
18
models per sample
RANSAC Algorithm
Input:
• data: a set of observations
• model: a model that can be fitted to data
• n: the minimum number of data required to fit the model
• k: the maximum number of iterations allowed in the algorithm
• t: a threshold value for determining when a datum fits a model
• d: the number of close data values required to assert that a model
fits well to data
Output:
• best_model : model parameters which best fit the data (or nil if no
good model is found)
• best_consensus_set : data point from which this model has been
estimated
• best_error : the error of this model relative to the data

19
RANSAC Algorithm

20
Parameters

1  p  1  w  k: Iteration times.
n k
n: Selected points in one iteration.
p: Probability in k iteration
log1  p  selects
k only inliers.
log(1  w )
n
w: Probability of a point which is
a inlier.

In general, the p is unknown. If we fixed p,


the k increased when n increased.
21
RANSAC for estimating homography

RANSAC loop:
1. Select four feature pairs (at random)
2. Compute homography H (exact)
3. Compute inliers where SSD(pi’, H pi) < ε
4. Keep largest set of inliers
5. Re-compute least-squares H estimate on all of the
inliers
RANSAC
Why “Recognising Panoramas”?

1D Rotations (q)
• Ordering  matching images

• 2D Rotations (q, f)
– Ordering  matching images
Why “Recognising Panoramas”?
RANSAC for Homography
RANSAC for Homography
Application: Image stitching
Probabilistic model for verification
Finding the panoramas
Finding the panoramas
Finding the panoramas
Finding the panoramas

You might also like