Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an...

26
Lecture 3.3 Robust estimation with RANSAC Thomas Opsahl

Transcript of Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an...

Page 1: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Lecture 3.3 Robust estimation with RANSAC

Thomas Opsahl

Page 2: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Motivation

β€’ Two images, captured by perspective cameras, of the same planar scene are related by a homography 𝐻

β€’ This homography can be estimated from 4 or more point-correspondences between the images

β€’ Point-correspondences can be established automatically – Find key points in both images – Represent key points by a descriptor (a

vector of parameters) – Establish point correspondences by

comparing descriptors

β€’ The resulting set of point pairs typically contains several wrong correspondences

β€’ A robust estimation method provides a good estimate of 𝐻 despite the presence of erroneous correspondences (outliers)

2

Image 1 Image 2

𝐻 𝒙�1 𝒙�2

Page 3: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

RANdom SAmple Consensus - RANSAC

β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed data containing outliers

3

𝑆

Observed data

π’š = 𝑓 𝒙;𝜢

Mathematical model with parameters 𝜢 = 𝛼1, … ,𝛼𝑛

Estimation method 𝒙𝑖 ,π’šπ‘–

Page 4: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

RANdom SAmple Consensus - RANSAC

β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed data containing outliers

4

𝑆

Observed data

π’š = 𝑓 𝒙;𝜢

Mathematical model with parameters 𝜢 = 𝛼1, … ,𝛼𝑛

Estimation method 𝒙𝑖 ,π’šπ‘–

𝑦 = π‘Žπ‘Ž + 𝑏

π‘Žπ‘Ž + 𝑏𝑦 + 𝑐 = 0

𝑦 = π‘Žπ‘Ž2 + π‘π‘Ž + 𝑐

π‘Ž2

π‘Ž2 +𝑦2

𝑏2 = 1

Page 5: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

RANdom SAmple Consensus - RANSAC

β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed data containing outliers – Robust method (handles up to 50% outliers)

5

𝑆

Observed data

π’š = 𝑓 𝒙;𝜢

Mathematical model with parameters 𝜢 = 𝛼1, … ,𝛼𝑛

Estimation method 𝒙𝑖 ,π’šπ‘–

Page 6: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

RANdom SAmple Consensus - RANSAC

β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed data containing outliers – Robust method (handles up to 50% outliers) – The estimated model is random but reasonable

6

𝑆

Observed data

π’š = 𝑓 𝒙;𝜢 Estimation

method 𝒙𝑖 ,π’šπ‘– Mathematical model with parameters 𝜢 = 𝛼1, … ,𝛼𝑛

Page 7: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

RANdom SAmple Consensus - RANSAC

β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed data containing outliers – Robust method (handles up to 50% outliers) – The estimated model is random but reasonable – The estimation process divides the observed data into inliers and outliers

7

𝑆

Observed data

π’š = 𝑓 𝒙;𝜢 Estimation

method 𝒙𝑖 ,π’šπ‘– Mathematical model with parameters 𝜢 = 𝛼1, … ,𝛼𝑛

Inliers

Outliers

Page 8: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

RANdom SAmple Consensus - RANSAC

β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed data containing outliers – Robust method (handles up to 50% outliers) – The estimated model is random but reasonable – The estimation process divides the observed data into inliers and outliers – Usually an improved estimate of the model is determined based on the inliers using a less robust

estimation method, e.g. least squares 8

𝑆

Observed data

π’š = 𝑓 𝒙;𝜢 Estimation

method 𝒙𝑖 ,π’šπ‘– Mathematical model with parameters 𝜢 = 𝛼1, … ,𝛼𝑛

Inliers

Outliers

Page 9: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Basic RANSAC

Objective To robustly fit a model π’š = 𝑓 𝒙;𝜢 to a data set 𝑆 containing outliers Algorithm 1. Estimate the model parameters πœΆπ‘‘π‘‘π‘‘ from a randomly sampled subset of 𝑛 data points

from 𝑆

2. Determine the set of inliers 𝑆𝑑𝑑𝑑 βŠ† 𝑆 to be the data points within a distance 𝑑 of the model

3. If this set of inliers is the largest so far, let 𝑆𝐼𝐼 = 𝑆𝑑𝑑𝑑 and let 𝜢 = πœΆπ‘‘π‘‘π‘‘

4. If 𝑆𝐼𝐼 < 𝑇 , where 𝑇 is some threshold value, repeat steps 1-3, otherwise stop

5. After 𝑁 trials, stop

Page 10: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Basic RANSAC

Comments β€’ Typically the number of random samples,

𝑛, is the smallest number of data points required to estimate the model

β€’ Assuming Gaussian noise in the data, the threshold value 𝑑 should be in the region of 2𝜎 were 𝜎 is the expected noise in the data set

β€’ The threshold value 𝑇 is set large enough to return a satisfactory inlier set, or simply omitted

β€’ The maximal number of tests, 𝑁, can be chosen according to how certain we want to be of sampling at least one 𝑛-tuple with no outliers If 𝑝 is the desired probability of sampling at least one 𝑛tuple with no outliers and πœ” is the probability of a random data point to be an inlier, then

𝑁 =𝑙𝑙𝑙 1 βˆ’ 𝑝𝑙𝑙𝑙 1 βˆ’ πœ”π‘›

𝑝 = 0.99 is standard

Page 11: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Basic RANSAC

Comments

β€’ 𝑁 = 𝑙𝑙𝑙 1βˆ’π‘π‘™π‘™π‘™ 1βˆ’πœ”π‘› with 𝑝 = 0.99

β€’ Typically we do not know the ratio of outliers in our data set, hence we do not know the probability πœ” or the number 𝑁

β€’ Instead of operating with a larger than necessary 𝑁 we can modify RANAC to adaptively estimate 𝑁 as we perform the iterations

πœ” 𝑁 90 80 70 60 50

𝑛

2 3 5 7 11 17 3 4 7 11 19 35 4 5 9 17 34 72 5 6 12 26 57 146 6 7 16 37 97 293 7 8 20 54 163 588 8 9 26 78 272 1177

Page 12: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Adaptive RANSAC

Objective To robustly fit a model π’š = 𝑓 𝒙;𝜢 to a data set 𝑆 containing outliers Algorithm 1. Let 𝑁 = ∞, 𝑆𝐼𝐼 = βˆ… and #π‘–π‘‘π‘–π‘–π‘Žπ‘‘π‘–π‘™π‘›π‘– = 0

2. while 𝑁 > #π‘–π‘‘π‘–π‘–π‘Žπ‘‘π‘–π‘™π‘›π‘– repeat 3-5

3. Estimate parameters πœΆπ‘‘π‘‘π‘‘ from a random 𝑛-tuple from 𝑆

4. Determine inlier set 𝑆𝑑𝑑𝑑, i.e. data points within a distance 𝑑 of the model π’š = 𝑓 𝒙;πœΆπ‘‘π‘‘π‘‘

5. If 𝑆𝑑𝑑𝑑 > 𝑆𝐼𝐼 , set 𝑆𝐼𝐼 = 𝑆𝑑𝑑𝑑, 𝜢 = πœΆπ‘‘π‘‘π‘‘, πœ” = 𝑆𝐼𝐼

𝑆 and 𝑁 = 𝑙𝑙𝑙 1βˆ’π‘

𝑙𝑙𝑙 1βˆ’πœ”π‘› with 𝑝 = 0.99 Increase #π‘–π‘‘π‘–π‘–π‘Žπ‘‘π‘–π‘™π‘›π‘– by 1

Page 13: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Example

β€’ Fit a circle π‘Ž βˆ’ π‘Ž0 2 + 𝑦 βˆ’ 𝑦0 2 = 𝑖2 to these data points by estimating the 3 parameters π‘Ž0, 𝑦0 and 𝑖

Page 14: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Example

β€’ Fit a circle π‘Ž βˆ’ π‘Ž0 2 + 𝑦 βˆ’ 𝑦0 2 = 𝑖2 to these data points by estimating the 3 parameters π‘Ž0, 𝑦0 and 𝑖

β€’ The data consists of some points on a circle with Gaussian noise and some random points

Circle + Gaussian noise Random points

Page 15: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Example

β€’ Least-squares approach Separate observables from parameters:

β€’ So for each observation π‘Žπ‘– ,𝑦𝑖 we get one equation

β€’ From all our 𝑁 observations we get a system of linear equations

( ) ( )

[ ]

[ ]

2 2 20 0

2 2 2 2 20 0 0 0

2 2 2 2 20 0 0 0

02 2

02 2 2

0 0

12 2

2

3

2 2

2 22

1 2

1

x x y y r

x xx x y yy y r

xx yy r x y x yx

x y y x yr x y

px y p x y

p

βˆ’ + βˆ’ =

βˆ’ + + βˆ’ + =

+ + βˆ’ βˆ’ = +

= + βˆ’ βˆ’

= +

[ ]1

2 22

3

1i i i i

px y p x y

p

= +

2 21 1 1 1

1 2 22 2 2 2

2

3 2 2

11

1N N N N

x y x yp

x y x ypp

x y x yA

+ + = +

=p b

Page 16: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

β€’ We can solve this using the pseudo inverse 𝒑 = 𝐴𝑇𝐴 βˆ’1𝐴𝑇𝒃 – This is the solution that minimize 𝐴𝒑 βˆ’ 𝒃

Example

Page 17: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

β€’ We can solve this using the pseudo inverse 𝒑 = 𝐴𝑇𝐴 βˆ’1𝐴𝑇𝒃 – This is the solution that minimize 𝐴𝒑 βˆ’ 𝒃

β€’ NOT GOOD! All points are treated equally, so the random points shifts the estimated circle away from the desired solution

Example

Page 18: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Example

β€’ To estimate the circle using RANSAC, we need two things 1. A way to estimate a circle from n-points, where n is as small as possible 2. A way to determine which of the points are inliers for an estimated circle

Page 19: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Example

β€’ To estimate the circle using RANSAC, we need two things 1. A way to estimate a circle from n-points, where n is as small as possible 2. A way to determine which of the points are inliers for an estimated circle

β€’ The smallest number of points required to determine a circle is 3, i.e. 𝑛 = 3, and the algorithm for computing the circle is quite simple

Page 20: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Example

β€’ To estimate the circle using RANSAC, we need two things 1. A way to estimate a circle from n-points, where n is as small as possible 2. A way to determine which of the points are inliers for an estimated circle

β€’ The distance from a point π‘Žπ‘– ,𝑦𝑖 to a circle π‘Ž βˆ’ π‘Ž0 2 + 𝑦 βˆ’ 𝑦0 2 = 𝑖2 is given by π‘Žπ‘– βˆ’ π‘Ž0 2 + 𝑦𝑖 βˆ’ 𝑦0 2 βˆ’ 𝑖

π‘Žπ‘– ,𝑦𝑖

π‘Žπ‘– βˆ’ π‘Ž0 2 + 𝑦𝑖 βˆ’ 𝑦0 2

𝑖 π‘Ž0,𝑦0

Page 21: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Example

β€’ To estimate the circle using RANSAC, we need two things 1. A way to estimate a circle from n-points, where n is as small as possible 2. A way to determine which of the points are inliers for an estimated circle

β€’ The distance from a point π‘Žπ‘– ,𝑦𝑖 to a circle π‘Ž βˆ’ π‘Ž0 2 + 𝑦 βˆ’ 𝑦0 2 = 𝑖2 is given by π‘Žπ‘– βˆ’ π‘Ž0 2 + 𝑦𝑖 βˆ’ 𝑦0 2 βˆ’ 𝑖

β€’ So for a threshold value 𝑑, we say that π‘Žπ‘– ,𝑦𝑖 is an inlier if π‘Žπ‘– βˆ’ π‘Ž0 2 + 𝑦𝑖 βˆ’ 𝑦0 2 βˆ’ 𝑖 < 𝑑

Page 22: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Example

Objective To robustly fit the model π‘Ž βˆ’ π‘Ž0 2 + 𝑦 βˆ’ 𝑦0 2 = 𝑖2 to our data set 𝑆 = π‘Žπ‘– ,𝑦𝑖 Algorithm 1. Let 𝑁 = ∞, 𝑆𝐼𝐼 = βˆ…, 𝑝 = 0.99, 𝑑 = 2 βˆ™ π‘–π‘Žπ‘π‘–π‘π‘‘π‘–π‘’ 𝑛𝑙𝑖𝑖𝑖 and #π‘–π‘‘π‘–π‘–π‘Žπ‘‘π‘–π‘™π‘›π‘– = 0

2. while 𝑁 > #π‘–π‘‘π‘–π‘–π‘Žπ‘‘π‘–π‘™π‘›π‘– repeat 3-5

3. Estimate parameters π‘Žπ‘‘π‘‘π‘‘ ,𝑦𝑑𝑑𝑑 , 𝑖𝑑𝑑𝑑 from three random points from 𝑆

4. Determine inlier set 𝑆𝑑𝑑𝑑 = π‘Žπ‘– ,𝑦𝑖 ∈ 𝑆 such that π‘Žπ‘– βˆ’ π‘Ž0 2 + 𝑦𝑖 βˆ’ 𝑦0 2 βˆ’ 𝑖 < 𝑑

5. If 𝑆𝑑𝑑𝑑 > 𝑆𝐼𝐼 , set 𝑆𝐼𝐼 = 𝑆𝑑𝑑𝑑, π‘Ž0,𝑦0, 𝑖 = π‘Žπ‘‘π‘‘π‘‘,𝑦𝑑𝑑𝑑, 𝑖𝑑𝑑𝑑 , πœ” = 𝑆𝐼𝐼

𝑆 and 𝑁 = 𝑙𝑙𝑙 1βˆ’π‘

𝑙𝑙𝑙 1βˆ’πœ”π‘› Increase #π‘–π‘‘π‘–π‘–π‘Žπ‘‘π‘–π‘™π‘›π‘– by 1

Page 23: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

β€’ The RANSAC algorithm evaluates many different circles and returns the circle with the largest inlier set

Example

Page 24: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

β€’ The RANSAC algorithm evaluates many different circles and returns the circle with the largest inlier set

β€’ Inliers can be used to get an improved estimate of the circle

Example

Inliers

Page 25: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Robust estimation

β€’ RANSAC is not perfect…

β€’ Several other robust estimation methods exist – Least Median Squares (LMS) – Preemptive RANSAC – PROgressive Sample and Consensus

(PROSAC) – M-estimator Sample and Consensus

(MSAC) – Maximum Likelihood Estimation Sample

and Consensus (MLESAC) – Randomized RANSAC (R-RANSAC) – KALMANSAC – +++

Page 26: Lecture 3.3 Robust estimation with RANSAC...RANdom SAmple Consensus - RANSAC β€’ RANSAC is an iterative method for estimating the parameters of a mathematical model from a set of observed

Summary

β€’ RANSAC – A robust iterative method for estimating the parameters of a mathematical model from a set of

observed data containing outliers – Separates the observed data into β€œinliers” and β€œoutliers” – Very useful if we want to use better, but less robust, estimation methods – Not perfect

β€’ Additional reading

– Szeliski: 6.1.4

β€’ Homework? – Implement a RANSAC algorithm for estimating a line

27