34
Lecture 10: Harris Corner Detector CS4670/5670: Computer Vision Kavita Bala

lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Lecture  10:  Harris  Corner  Detector  

CS4670/5670:  Computer  Vision  Kavita  Bala  

Page 2: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Announcements  

•  HW  1  will  be  out  early  next  week  

•  Quiz  1  graded  

Page 3: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Finding Corners

•  Key property: in the region around a corner, image gradient has two or more dominant directions

•  Corners are repeatable and distinctive C.Harris  and  M.Stephens,  1988.  "A  Combined  Corner  and  Edge  Detector.“  Proceedings  of  the  4th  Alvey  Vision  Conference:  pages  147-­‐-­‐151.      

Page 4: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Feature extraction: Corners 9300 Harris Corners Pkwy, Charlotte, NC

Slides from Rick Szeliski, Svetlana Lazebnik, and Kristin Grauman

Page 5: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Local  measures  of  uniqueness  

Suppose  we  only  consider  a  small  window  of  pixels  – What  defines  whether  a  feature  is  a  good  or  bad  candidate?  

Credit:  S.  Seitz,  D.  Frolova,  D.  Simakov  

Page 6: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner Detection: Basic Idea •  We should easily recognize the point by looking

through a small window •  Shifting a window in any direction should give a

large change in intensity

“edge”:no change along the edge direction

“corner”:significant change in all directions

“flat” region:no change in all directions

Source: A. Efros

Page 7: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Consider  shiZing  the  window  W  by  (u,v)  •  how  do  the  pixels  in  W  change?  •  compare  each  pixel  before  and  aZer  by  summing  up  the  squared  differences  (SSD)  

•  this  defines  an  SSD  “error”  E(u,v):  

Harris  corner  detec`on:    the  math  

W  

Page 8: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner Detection: Mathematics

[ ]2,

( , ) ( , ) ( , ) ( , )x y

E u v w x y I x u y v I x y= + + −∑

We want to find out how this function behaves for small shifts

Change in appearance of window for the shift [u,v]:

E(u, v)

Page 9: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Taylor  Series  expansion  of  I:      If  the  mo`on  (u,v)  is  small,  then  first  order  approxima`on  is  good                Plugging  this  into  the  formula  on  the  previous  slide…  

Small  mo`on  assump`on  

Page 10: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner  detec`on:    the  math  

Consider  shiZing  the  window  W  by  (u,v)  •  define  an  SSD  “error”  E(u,v):  

W  

Page 11: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner  detec`on:    the  math  

Consider  shiZing  the  window  W  by  (u,v)  •  define  an  SSD  “error”  E(u,v):  

W  

•  Thus,  E(u,v)  is  locally  approximated  as  a  quadra`c  error  func`on  

Page 12: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

The surface E(u,v) is locally approximated by a quadratic form. Let’s try to understand its shape.

Interpreting the second moment matrix

⎥⎦

⎤⎢⎣

⎡≈

vu

MvuvuE ][),(

∑⎥⎥⎦

⎢⎢⎣

⎡=

yx yyx

yxx

IIIIII

yxwM,

2

2

),(

Page 13: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

The  surface  E(u,v)  is  locally  approximated  by  a  quadra`c  form.    

The  second  moment  matrix  

Let’s  try  to  understand  its  shape.  

Page 14: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Horizontal  edge:    

u  v  

E(u,v)  

M  M  

M  

Page 15: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Ver`cal  edge:    

u  v  

E(u,v)  

M  

M  

Page 16: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Consider a horizontal “slice” of E(u, v):

Interpreting the second moment matrix

This is the equation of an ellipse.

const][ =⎥⎦

⎤⎢⎣

vu

Mvu

Page 17: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Quick  eigenvalue/eigenvector  review  The  eigenvectors  of  a  matrix  A  are  the  vectors  x  that  sa`sfy:  

 The  scalar  λ  is  the  eigenvalue  corresponding  to  x  

–  The  eigenvalues  are  found  by  solving:  

–  Say,  A  =  H  is  a  2x2  matrix,  so  we  have  

 –  The  solu`on:  

Once  you  know  λ,  you  find  x  by  solving  

Page 18: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Consider a horizontal “slice” of E(u, v):

Interpreting the second moment matrix

This is the equation of an ellipse.

RRM ⎥⎦

⎤⎢⎣

⎡= −

2

11

00λ

λ

The axis lengths of the ellipse are determined by the eigenvalues and the orientation is determined by R

direction of the slowest change

direction of the fastest change

(λmax) -1/2

(λmin)-1/2

const][ =⎥⎦

⎤⎢⎣

vu

Mvu

Diagonalization of M:

Page 19: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner  detec`on:    the  math  

Eigenvalues  and  eigenvectors  of  M  •  Define  shiZ  direc`ons  with  the  smallest  and  largest  change  in  error  •  xmax  =  direc`on  of  largest  increase  in  E  •  λmax  =  amount  of  increase  in  direc`on  xmax  

•  xmin  =  direc`on  of  smallest  increase  in  E    •  λmin  =  amount  of  increase  in  direc`on  xmin  

xmin

xmax

M  

M  

Page 20: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Interpreting the eigenvalues

λ1

λ2

“Corner” λ1 and λ2 are large, λ1 ~ λ2; E increases in all directions

λ1 and λ2 are small; E is almost constant in all directions

“Edge” λ1 >> λ2

“Edge” λ2 >> λ1

“Flat” region

Classification of image points using eigenvalues of M:

Page 21: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner  detec`on:    the  math  How  are  λmax,  xmax,  λmin,  and  xmin  relevant  for  feature  detec`on?  

•  Need  a  feature  scoring  func`on      

Page 22: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner  detec`on:    the  math  How  are  λmax,  xmax,  λmin,  and  xmin  relevant  for  feature  detec`on?  

•  Need  a  feature  scoring  func`on  Want  E(u,v)  to  be  large  for  small  shiZs  in  all  direc`ons  

•  the  minimum  of  E(u,v)  should  be  large,  over  all  unit  vectors  [u  v]  •  this  minimum  is  given  by  the  smaller  eigenvalue  (λmin)  of  M  

Page 23: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner  detec`on  summary  Here’s  what  you  do  

•  Compute  the  gradient  at  each  point  in  the  image  •  Create  the  M  matrix  from  the  entries  in  the  gradient  •  Compute  the  eigenvalues    •  Find  points  with  large  response  (λmin  >  threshold)  •  Choose  those  points  where  λmin  is  a  local  maximum  as  features  

Page 24: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner  detec`on  summary  Here’s  what  you  do  

•  Compute  the  gradient  at  each  point  in  the  image  •  Create  the  H  matrix  from  the  entries  in  the  gradient  •  Compute  the  eigenvalues.    •  Find  points  with  large  response  (λmin  >  threshold)  •  Choose  those  points  where  λmin  is  a  local  maximum  as  features  

Page 25: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

The  Harris  operator  

λmin  is  a  variant  of  the  “Harris  operator”  for  feature  detec`on  

•  The  trace  is  the  sum  of  the  diagonals,  i.e.,  trace(H)  =  h11  +  h22  •  Very  similar  to  λmin  but  less  expensive  (no  square  root)  •  Called  the  “Harris  Corner  Detector”  or  “Harris  Operator”  

•  Actually  the  Noble  variant  of  the  Harris  Corner  Detector  •  Lots  of  other  detectors,  this  is  one  of  the  most  popular  

Page 26: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Corner response function

“Corner” R > 0

“Edge” R < 0

“Edge” R < 0

“Flat” region

|R| small

22121

2 )()(trace)det( λλαλλα +−=−= MMR

α: constant (0.04 to 0.15)

Page 27: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

The  Harris  operator  

Harris operator

Page 28: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Harris Detector [Harris88]

•  Second  moment  matrix  

⎥⎥⎦

⎢⎢⎣

⎡∗=

)()()()(

)(),( 2

2

DyDyx

DyxDxIDI III

IIIg

σσ

σσσσσµ

28  

1. Image derivatives

2. Square of derivatives

3. Gaussian filter g(σI)

Ix Iy

Ix2 Iy2 IxIy

g(Ix2) g(Iy2) g(IxIy)

222222 )]()([)]([)()( yxyxyx IgIgIIgIgIg +−− α

=−= ])),([trace()],(det[ 2DIDIhar σσµασσµ

4. Cornerness function – both eigenvalues are strong

har 5. Non-maxima suppression

1 2

1 2

dettrace

MM

λ λ

λ λ

=

= +

(optionally, blur first)

Page 29: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Weigh`ng  the  deriva`ves  

•  In  prac`ce,  using  a  simple  window  W  doesn’t  work  too  well  

•  Instead,  we’ll  weight  each  deriva`ve  value  based  on  its  distance  from  the  center  pixel  

Page 30: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Harris  detector  example  

Page 31: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

f  value  (red  high,  blue  low)  

Page 32: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Threshold  (f  >  value)    

Page 33: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Find  local  maxima  of  f  

Page 34: lec10 features2 web - Cornell UniversityFinding Corners • Key property: in the region around a corner, image gradient has two or more dominant directions • Corners are repeatable

Harris  features  (in  red)