template matching - web.stanford.edu...optimum detection: prefiltering & template...

11
Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 1 Template matching Problem: locate an object, described by a template t[x,y], in the image s[x,y] Example s [x,y] t[x,y]

Upload: others

Post on 25-Sep-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 1

Template matching

n  Problem: locate an object, described by a template t[x,y], in the image s[x,y] n  Example"

s[x,y]

t[x,y]

Page 2: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 2

Template matching (cont.)

n  Search for the best match by minimizing mean-squared error"

n  Equivalently, maximize area correlation!

n  Area correlation is equivalent to convolution of image s[x,y] with impulse response t[-x,-y]"

E p,q⎡⎣ ⎤⎦ = s[x,y]− t x − p, y − q⎡⎣ ⎤⎦⎡⎣ ⎤⎦2

y=−∞

∑x=−∞

= s[x,y]2+

y=−∞

∑x=−∞

∑ t[x,y]2− 2

y=−∞

∑x=−∞

∑ s[x,y]y=−∞

∑x=−∞

∑ ⋅ t x − p, y − q⎡⎣ ⎤⎦

r p,q[ ]= s[x,y]y=−∞

∑x=−∞

∑ ⋅ t x − p,y− q[ ]= s p,q[ ]∗ t −p,−q[ ]

Page 3: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 3

Template matching (cont.)

n  From Cauchy-Schwarz inequality"

n  Equality, iff"n  Block diagram of template matcher"

n  Remove mean before template matching to avoid bias towards bright image areas"

r p,q⎡⎣ ⎤⎦ = s x, y⎡⎣ ⎤⎦

y=−∞

∑x=−∞

∑ ⋅ t x − p, y − q⎡⎣ ⎤⎦ ≤ s x, y⎡⎣ ⎤⎦2

y=−∞

∑x=−∞

∑⎛

⎝⎜⎞

⎠⎟t x, y⎡⎣ ⎤⎦

2

y=−∞

∑x=−∞

∑⎛

⎝⎜⎞

⎠⎟

s x, y⎡⎣ ⎤⎦ =α ⋅ t x − p, y − q⎡⎣ ⎤⎦ with α ≥ 0

Search"peak(s)"s x,y[ ]

t −x,−y[ ] r x,y[ ] object!location(s) p,q

Page 4: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 4

Template matching example

-3 -2 -1 0 1 2 3 4 5 6 7

x 107

s[x,y]

t[x,y]

r[p,q]

Page 5: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 6

Matched filtering

n  Consider signal detection problem"

n  Signal model"

n  Problem: design filter g[x,y] to maximize"

s x,y[ ]g x, y[ ] r x,y[ ]

Object!location(s) p,q!

s x, y[ ] = t x − p, y − q[ ]+ n x, y[ ]

Other objects : "noise" or "clutter"

psd Φnn e jω x ,e jω y( )

Search"peak(s)"

shifted template"

correct peak"

false readings"

SNR =r p,q⎡⎣ ⎤⎦

2

E n x, y⎡⎣ ⎤⎦∗ g x, y⎡⎣ ⎤⎦2{ }

""

""

r p,q!" #$ =!g H !s

!s =!t + !n R nn = E !n!nH{ }covariance"

SNR =r p,q!" #$

2

E !g H !n2{ }

Vector-matrix!formulation!

Page 6: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 7

Matched filtering (cont.)

n  Optimum filter has frequency response"

n  Proof:"

SNR =r p,q!" #$

2

E n x, y!" #$∗ g x, y!" #$2{ }≈

G e jω x ,e jω y( )−π

π

∫ T e jω x ,e jω y( )dω x−π

π

∫ dω y

2

G e jω x ,e jω y( )−π

π

∫2

Φnn e jω x ,e jω y( )dω x−π

π

∫ dω y

=GΦnn

1/2!" #$−π

π

∫ Φnn−1/2T!" #$dω x−π

π

∫ dω y

2

G−π

π

∫2

Φnn dω x−π

π

∫ dω y

G−π

π

∫2

Φnn dω x−π

π

∫ dω y

!

"-

#

$. T

−π

π

∫2

Φnn−1 dω x−π

π

∫ dω y

!

"-

#

$.

G−π

π

∫2

Φnn dω x−π

π

∫ dω y

= T−π

π

∫2

Φnn−1 dω x−π

π

∫ dω y

G e jω x ,e jω y( ) =T ∗ e jω x ,e jω y( )Φnn e jω x ,e jω y( )

Cauchy-Schwarz inequality,

with equality, iff GΦnn1/2 =α ⋅ Φnn

−1/2T⎡⎣ ⎤⎦∗

max. SNR"

!g = Rnn

−1!t

Vector-matrix!formulation!

Page 7: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 8

Matched filtering (cont.)

n  Optimum filter corresponds to projection on"

n  Proof:"

Cauchy-Schwarz inequality,with equality, iff Rnn

1/2 !g =α ⋅Rnn−1/2!t

max. SNR"

!g = Rnn

−1!t

SNR =r p,q!" #$

2

E !g H !n2{ }≈

!g H!t2

!g H Rnn

!g

=Rnn

1/2 !g( )HRnn−1/2!t( )

2

Rnn1/2 !g( )H

Rnn1/2 !g( )

≤Rnn

1/2 !g( )HRnn

1/2 !g( )!"(

#$)

Rnn−1/2!t( )H

Rnn−1/2!t( )!

"(#$)

Rnn1/2 !g( )H

Rnn1/2 !g( )

=!t H Rnn

−1!t

Page 8: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 9

Matched filtering (cont.)

n  Optimum detection: prefiltering & template matching"

n  For white noise n[x,y], no prefiltering h[x,y] required"n  Low frequency clutter: highpass prefilter"

Search"peak(s)"s x,y[ ] t −x,−y[ ] r x,y[ ]

object!location(s)!

p,q

h x, y[ ]

h x, y⎡⎣ ⎤⎦ =1

4π 2

1

Φnn e jω x ,e jω y( )−π

π

∫ e jω xx+ jω y y dω x−π

π

∫ dω y

Page 9: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 10

Matched filtering example Test Image Template

Template Matching Result

0.92" 0.92" 1.00"Matched Filtering Result

0.64" 0.73" 1.00"

0.84"

0.77"

Page 10: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 11

Matched filtering example (cont.)

Template Clutter

Matched Filter Impulse Response

(180o rotated)

π

-π -π/2 π/2

0

π

-π -π/2

π/2 0

π

-π -π/2 π/2

0

π

-π -π/2

π/2 0

π

-π -π/2 π/2

0

π

-π -π/2

π/2 0

-0.5

0

0.5

1

Page 11: Template matching - web.stanford.edu...Optimum detection: prefiltering & template matching" For white noise n [ x,y ] , no prefiltering h [ x,y ] required" Low frequency clutter:

Digital Image Processing: Bernd Girod, © 2013 Stanford University -- Template Matching 12

Phase correlation

n  Efficient implementation employing the Discrete Fourier Transform"

n  Phase correlation"

s x,y[ ]

t x, y[ ]

r x,y[ ]Peak!

detection!DFT

DFT

H e jω x ,e jω y( )

∗⊗ DFT-1

H e jω x ,e jω y( ) = 1

S e jω x ,e jω y( ) T e jω x ,e jω y( )