kavitabala - cornell university · 2016-03-07 · alignment •...

56
Lecture 17: RANSAC CS4670/5760: Computer Vision Kavita Bala

Upload: others

Post on 18-Mar-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Lecture  17:  RANSAC  

CS4670/5760:  Computer  Vision  Kavita  Bala  

Page 2: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Alignment  •  Alignment:  find  parameters  of  model  that  maps  one  set  of  points  to  another  

•  Typically  want  to  solve  for  a  global  transformaJon  that  accounts  for  *most*  true  correspondences  

•  DifficulJes  – Noise  (typically  1-­‐3  pixels)  – Outliers  (oTen  50%)  

Page 3: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Least  squares:  find  t  to  minimize  

•  To  solve,  form  the  normal  equa+ons  •  DifferenJate  and  equate  to  0  to  minimize  

Page 4: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Affine  transformaJons  

•  Matrix  form  

2n  x  6   6  x  1   2n  x  1  

Page 5: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Solving  for  homographies  

Page 6: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Solving  for  homographies  

Page 7: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Solving  for  homographies  

Defines  a  least  squares  problem:  •  Since                is  only  defined  up  to  scale,  solve  for  unit  vector  •  SoluJon:                =  eigenvector  of                                with  smallest  eigenvalue  •  Works  with  4  or  more  points  

2n  ×  9   9   2n  

Page 8: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Recap:  Two  Common  OpJmizaJon  Problems  

Problem  statement   SoluJon      

1 s.t. minimize =xxAxAx TTT

0 osolution tlsq trivial-non =Ax

1..21 :)eig(],[

vxAAv

=<

=

n

T

λλ

λ

Problem  statement   SoluJon      

bAx = osolution t squaresleast bAx \=

2 minimize bAx − ( ) bAAAx TT 1−=

(matlab)  

Page 9: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal
Page 10: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Hybrid  Image  compeJJon  results  

•  Hall  of  Fame:  hdp://www.cs.cornell.edu/courses/cs4670/2016sp/arJfacts/pa1/hof.html  

Page 11: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Runners Up

Page 12: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Benjamin  Siper,  Sania  Nagpal  

Page 13: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Nadav  Nehoran,  Thomas  Ilyevsky  

Page 14: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Daniel  Donenfeld,  Markus  Salasoo  

Page 15: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Joshua  Chan,  Jerica  Huang  

Page 16: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Third Place

Page 17: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

AdiJ  Jain,  Ross  Tannenbaum  

Page 18: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

James  Briggs,  Vishwanathan  Ramanathan  

Page 19: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Second Place

Page 20: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Aaron  Ferber,  Mateo  Espinosa  Zarlenga  

Page 21: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

First Place

Page 22: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Mingyang  Li,  Yuan  Huang  

Page 23: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

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

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

Fikng  and  Alignment  

Page 24: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Least  squares:  linear  regression  

0 1 2 3 4 5 60

2

4

6

8

10

12

Time

Mile

age

y  =  mx  +  b  

(yi,  xi)  

Page 25: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Linear  regression  

0 1 2 3 4 5 60

2

4

6

8

10

12

Time

Mile

age

residual  error  

Page 26: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Linear  regression  

Page 27: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Image  Alignment  Algorithm  

Given  images  A  and  B  

1.  Compute  image  features  for  A  and  B  2.  Match  features  between  A  and  B  3.  Compute  homography  between  A  and  B  

using  least  squares  on  set  of  matches  

What  could  go  wrong?  

Page 28: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Outliers  outliers  

inliers  

Page 29: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Robustness  

Problem:  Fit  a  line  to  these  datapoints   Least  squares  fit  

Page 30: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Idea  

•  Given  a  hypothesized  line  •  Count  the  number  of  points  that  “agree”  with  the  line  – “Agree”  =  within  a  small  distance  of  the  line  –  I.e.,  the  inliers  to  that  line    

•  For  all  possible  lines,  select  the  one  with  the  largest  number  of  inliers  

Page 31: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

CounJng  inliers  

Page 32: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

CounJng  inliers  

Inliers:  3  

Page 33: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

CounJng  inliers  

Inliers:  20  

Page 34: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

How  do  we  find  the  best  line?  

•  Unlike  least-­‐squares,  no  simple  closed-­‐form  soluJon    

•  Hypothesize-­‐and-­‐test  – Try  out  many  lines,  keep  the  best  one  – Which  lines?  

Page 35: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RANSAC  (Random  Sample  Consensus)  

Algorithm:    

1.   Sample  (randomly)  the  number  of  points  required  to  fit  the  model  (#=2)  2.   Solve  for  model  parameters  using  samples    3.   Score  by  the  fracJon  of  inliers  within  a  preset  threshold  of  the  model    Repeat  1-­‐3  unJl  the  best  model  is  found  with  high  confidence  

IllustraJon  by  Savarese  

Line  fikng  example  

Page 36: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RANSAC  

Algorithm:    

1.   Sample  (randomly)  the  number  of  points  required  to  fit  the  model  (#=2)  2.   Solve  for  model  parameters  using  samples    3.   Score  by  the  fracJon  of  inliers  within  a  preset  threshold  of  the  model    Repeat  1-­‐3  unJl  the  best  model  is  found  with  high  confidence  

Line  fikng  example  

Page 37: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

δ

RANSAC  

6=IN

Algorithm:    

1.   Sample  (randomly)  the  number  of  points  required  to  fit  the  model  (#=2)  2.   Solve  for  model  parameters  using  samples    3.   Score  by  the  fracJon  of  inliers  within  a  preset  threshold  of  the  model    Repeat  1-­‐3  unJl  the  best  model  is  found  with  high  confidence  

Line  fikng  example  

Page 38: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

δ

RANSAC  

14=INAlgorithm:    

1.   Sample  (randomly)  the  number  of  points  required  to  fit  the  model  (#=2)  2.   Solve  for  model  parameters  using  samples    3.   Score  by  the  fracJon  of  inliers  within  a  preset  threshold  of  the  model    Repeat  1-­‐3  unJl  the  best  model  is  found  with  high  confidence  

Page 39: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RANSAC  

•  Idea:  – All  the  inliers  will  agree  with  each  other  on  the  translaJon  vector;  the  (hopefully  small)  number  of  outliers  will  (hopefully)  disagree  with  each  other  

•  RANSAC  only  has  guarantees  if  there  are  <  50%  outliers  

– “All  good  matches  are  alike;  every  bad  match  is  bad  in  its  own  way.”          –  Tolstoy  via  Alyosha  Efros  

Page 40: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

TranslaJons  

Page 41: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RAndom  SAmple  Consensus  

Select  one  match  at  random,  count  inliers  

Page 42: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RAndom  SAmple  Consensus  

Select  another  match  at  random,  count  inliers  

Page 43: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RAndom  SAmple  Consensus  

Output  the  translaJon  with  the  highest  number  of  inliers  

Page 44: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Final  step:  least  squares  fit  

Find  average  translaJon  vector  over  all  inliers  

Page 45: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RANSAC  

•  Inlier  threshold  related  to  the  amount  of  noise  we  expect  in  inliers  – OTen  model  noise  as  Gaussian  with  some  standard  deviaJon  (e.g.,  3  pixels)  

•  Number  of  rounds  related  to  the  percentage  of  outliers  we  expect,  and  the  probability  of  success  we’d  like  to  guarantee  – Suppose  there  are  20%  outliers,  and  we  want  to  find  the  correct  answer  with  99%  probability    

– How  many  rounds  do  we  need?  

Page 46: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

How  many  rounds?    

•  If  we  have  to  choose  k  samples  each  Jme  – with  an  inlier  raJo  p  – and  we  want  the  right  answer  with  probability  P  

proporJon  of  inliers  p  k   95%   90%   80%   75%   70%   60%   50%  2   2   3   5   6   7   11   17  3   3   4   7   9   11   19   35  4   3   5   9   13   17   34   72  5   4   6   12   17   26   57   146  6   4   7   16   24   37   97   293  7   4   8   20   33   54   163   588  8   5   9   26   44   78   272   1177  

Source:  M.  Pollefeys  

P  =  0.99  

Page 47: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

proporJon  of  inliers  p  k   95%   90%   80%   75%   70%   60%   50%  2   2   3   5   6   7   11   17  3   3   4   7   9   11   19   35  4   3   5   9   13   17   34   72  5   4   6   12   17   26   57   146  6   4   7   16   24   37   97   293  7   4   8   20   33   54   163   588  8   5   9   26   44   78   272   1177  

P  =  0.99  

Page 48: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

How  big  is  k?  •  For  alignment,  depends  on  the  moJon  model  

– Here,  each  sample  is  a  correspondence  (pair  of  matching  points)  

Page 49: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RANSAC  pros  and  cons  

•  Pros  – Simple  and  general  – Applicable  to  many  different  problems  – OTen  works  well  in  pracJce  

•  Cons  – Parameters  to  tune  – SomeJmes  too  many  iteraJons  are  required  – Can  fail  for  extremely  low  inlier  raJos  

Page 50: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

RANSAC  

•  An  example  of  a  “voJng”-­‐based  fikng  scheme  •  Each  hypothesis  gets  voted  on  by  each  data  point,  best  hypothesis  wins  

•  There  are  many  other  types  of  voJng  schemes  – E.g.,  Hough  transforms…  

Page 51: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

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 52: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Hough  Transform:  Outline  

1.  Create  a  grid  of  parameter  values  

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

3.  Find  maximum  or  local  maxima  in  grid  

Page 53: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

x

y

b

m

x

y m 3 5 3 3 2 2

3 7 11 10 4 3

2 3 1 4 5 2 2 1 0 1 3 3

b Slide  from  S.  Savarese  

Hough transform

Page 54: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal
Page 55: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Hough  transform  

d

θ

Page 56: KavitaBala - Cornell University · 2016-03-07 · Alignment • Alignment:’find’parameters’of’model’that maps’one’setof’points’to’another’ • Typically’wantto’solve’for’aglobal

Fikng  Summary  •  Least  Squares  Fit    

–  closed  form  soluJon  –  robust  to  noise  –  not  robust  to  outliers  

•  Hough  transform  –  robust  to  noise  and  outliers  –  can  fit  mulJple  models  –  only  works  for  a  few  parameters  (1-­‐4  typically)  

•  RANSAC  –  robust  to  noise  and  outliers  –  works  with  a  moderate  number  of  parameters  (e.g,  1-­‐8)