<s>
Template	B-Algorithm
matching	I-Algorithm
is	O
a	O
technique	O
in	O
digital	B-Algorithm
image	I-Algorithm
processing	I-Algorithm
for	O
finding	O
small	O
parts	O
of	O
an	O
image	O
which	O
match	O
a	O
template	O
image	O
.	O
</s>
<s>
It	O
can	O
be	O
used	O
for	O
quality	O
control	O
in	O
manufacturing	O
,	O
navigation	B-General_Concept
of	I-General_Concept
mobile	I-General_Concept
robots	I-General_Concept
,	O
or	O
edge	B-Algorithm
detection	I-Algorithm
in	O
images	O
.	O
</s>
<s>
The	O
main	O
challenges	O
in	O
a	O
template	B-Algorithm
matching	I-Algorithm
task	O
are	O
detection	O
of	O
occlusion	O
,	O
when	O
a	O
sought-after	O
object	O
is	O
partly	O
hidden	O
in	O
an	O
image	O
;	O
detection	O
of	O
non-rigid	O
transformations	O
,	O
when	O
an	O
object	O
is	O
distorted	O
or	O
imaged	O
from	O
different	O
angles	O
;	O
sensitivity	O
to	O
illumination	O
and	O
background	O
changes	O
;	O
background	O
clutter	O
;	O
and	O
scale	O
changes	O
.	O
</s>
<s>
The	O
feature-based	O
approach	O
to	O
template	B-Algorithm
matching	I-Algorithm
relies	O
on	O
the	O
extraction	O
of	O
image	B-Algorithm
features	I-Algorithm
,	O
such	O
as	O
shapes	O
,	O
textures	O
,	O
and	O
colors	O
,	O
that	O
match	O
the	O
target	O
image	O
or	O
frame	O
.	O
</s>
<s>
This	O
approach	O
is	O
usually	O
achieved	O
using	O
neural	B-Architecture
networks	I-Architecture
and	O
deep-learning	B-Algorithm
classifiers	B-General_Concept
such	O
as	O
VGG	O
,	O
AlexNet	B-Algorithm
,	O
and	O
ResNet.Convolutional	O
neural	B-Architecture
networks	I-Architecture
(	O
CNNs	B-Architecture
)	O
,	O
which	O
many	O
modern	O
classifiers	B-General_Concept
are	O
based	O
on	O
,	O
process	O
an	O
image	O
by	O
passing	O
it	O
through	O
different	O
hidden	O
layers	O
,	O
producing	O
a	O
vector	O
at	O
each	O
layer	O
with	O
classification	O
information	O
about	O
the	O
image	O
.	O
</s>
<s>
These	O
vectors	O
are	O
extracted	O
from	O
the	O
network	O
and	O
used	O
as	O
the	O
features	B-Algorithm
of	O
the	O
image	O
.	O
</s>
<s>
Feature	B-Algorithm
extraction	I-Algorithm
using	O
deep	O
neural	B-Architecture
networks	I-Architecture
,	O
like	O
CNNs	B-Architecture
,	O
has	O
proven	O
extremely	O
effective	O
has	O
become	O
the	O
standard	O
in	O
state-of-the-art	O
template	B-Algorithm
matching	I-Algorithm
algorithms	O
.	O
</s>
<s>
This	O
feature-based	O
approach	O
is	O
often	O
more	O
robust	O
than	O
the	O
template-based	O
approach	O
described	O
below	O
.	O
</s>
<s>
As	O
such	O
,	O
it	O
has	O
become	O
the	O
state-of-the-art	O
method	O
for	O
template	B-Algorithm
matching	I-Algorithm
,	O
as	O
it	O
can	O
match	O
templates	O
with	O
non-rigid	O
and	O
out-of-plane	O
transformations	B-Algorithm
,	O
as	O
well	O
as	O
high	O
background	O
clutter	O
and	O
illumination	O
changes	O
.	O
</s>
<s>
For	O
templates	O
without	O
strong	O
features	B-Algorithm
,	O
or	O
for	O
when	O
the	O
bulk	O
of	O
a	O
template	O
image	O
constitutes	O
the	O
matching	O
image	O
as	O
a	O
whole	O
,	O
a	O
template-based	O
approach	O
may	O
be	O
effective	O
.	O
</s>
<s>
This	O
pre-processing	B-General_Concept
method	O
creates	O
a	O
multi-scale	O
,	O
or	O
pyramid	B-Algorithm
,	O
representation	O
of	O
images	O
,	O
providing	O
a	O
reduced	O
search	O
window	O
of	O
data	O
points	O
within	O
a	O
search	O
image	O
so	O
that	O
the	O
template	O
does	O
not	O
have	O
to	O
be	O
compared	O
with	O
every	O
viable	O
data	O
point	O
.	O
</s>
<s>
Pyramid	B-Algorithm
representations	O
are	O
a	O
method	O
of	O
dimensionality	B-Algorithm
reduction	I-Algorithm
,	O
a	O
common	O
aim	O
of	O
machine	O
learning	O
on	O
data	O
sets	O
that	O
suffer	O
the	O
curse	O
of	O
dimensionality	O
.	O
</s>
<s>
In	O
instances	O
where	O
the	O
template	O
may	O
not	O
provide	O
a	O
direct	O
match	O
,	O
it	O
may	O
be	O
useful	O
to	O
implement	O
eigenspaces	O
to	O
create	O
templates	O
that	O
detail	O
the	O
matching	O
object	O
under	O
a	O
number	O
of	O
different	O
conditions	O
,	O
such	O
as	O
varying	O
perspectives	O
,	O
illuminations	O
,	O
color	O
contrasts	O
,	O
or	O
object	O
poses	B-Architecture
.	O
</s>
<s>
For	O
example	O
,	O
if	O
an	O
algorithm	O
is	O
looking	O
for	O
a	O
face	O
,	O
its	O
template	O
eigenspaces	O
may	O
consist	O
of	O
images	O
(	O
i.e.	O
,	O
templates	O
)	O
of	O
faces	O
in	O
different	O
positions	O
to	O
the	O
camera	O
,	O
in	O
different	O
lighting	O
conditions	O
,	O
or	O
with	O
different	O
expressions	O
(	O
i.e.	O
,	O
poses	B-Architecture
)	O
.	O
</s>
<s>
Template	B-Algorithm
matching	I-Algorithm
is	O
a	O
central	O
tool	O
in	O
computational	B-Algorithm
anatomy	I-Algorithm
(	O
CA	O
)	O
.	O
</s>
<s>
Template	B-Algorithm
matching	I-Algorithm
arises	O
as	O
an	O
approach	O
to	O
finding	O
the	O
unknown	O
diffeomorphism	O
that	O
acts	O
on	O
a	O
template	O
image	O
to	O
match	O
the	O
target	O
image	O
.	O
</s>
<s>
Template	B-Algorithm
matching	I-Algorithm
algorithms	O
in	O
CA	O
have	O
come	O
to	O
be	O
called	O
large	O
deformation	O
diffeomorphic	O
metric	O
mappings	O
(	O
LDDMMs	O
)	O
.	O
</s>
<s>
Currently	O
,	O
there	O
are	O
LDDMM	O
template	B-Algorithm
matching	I-Algorithm
algorithms	O
for	O
matching	O
anatomical	O
landmark	B-General_Concept
points	I-General_Concept
,	O
curves	O
,	O
surfaces	O
,	O
volumes	O
.	O
</s>
<s>
A	O
basic	O
method	O
of	O
template	B-Algorithm
matching	I-Algorithm
sometimes	O
called	O
"	O
Linear	O
Spatial	O
Filtering	O
"	O
uses	O
an	O
image	O
patch	O
(	O
i.e.	O
,	O
the	O
"	O
template	O
image	O
"	O
or	O
"	O
filter	O
mask	O
"	O
)	O
tailored	O
to	O
a	O
specific	O
feature	B-Algorithm
of	O
search	O
images	O
to	O
detect	O
.	O
</s>
<s>
This	O
technique	O
can	O
be	O
easily	O
performed	O
on	O
grey	O
images	O
or	O
edge	B-Algorithm
images	O
,	O
where	O
the	O
additional	O
variable	O
of	O
color	O
is	O
either	O
not	O
present	O
or	O
not	O
relevant	O
.	O
</s>
<s>
Let	O
represent	O
the	O
value	O
of	O
a	O
search	O
image	O
pixel	B-Algorithm
,	O
where	O
represents	O
the	O
coordinates	O
of	O
the	O
pixel	B-Algorithm
in	O
the	O
search	O
image	O
.	O
</s>
<s>
For	O
simplicity	O
,	O
assume	O
pixel	B-Algorithm
values	O
are	O
scalar	O
,	O
as	O
in	O
a	O
greyscale	O
image	O
.	O
</s>
<s>
Similarly	O
,	O
let	O
represent	O
the	O
value	O
of	O
a	O
template	O
pixel	B-Algorithm
,	O
where	O
represents	O
the	O
coordinates	O
of	O
the	O
pixel	B-Algorithm
in	O
the	O
template	O
image	O
.	O
</s>
<s>
To	O
apply	O
the	O
filter	O
,	O
simply	O
move	O
the	O
center	O
(	O
or	O
origin	O
)	O
of	O
the	O
template	O
image	O
over	O
each	O
point	O
in	O
the	O
search	O
image	O
and	O
calculate	O
the	O
sum	O
of	O
products	O
,	O
similar	O
to	O
a	O
dot	O
product	O
,	O
between	O
the	O
pixel	B-Algorithm
values	O
in	O
the	O
search	O
and	O
template	O
images	O
over	O
the	O
whole	O
area	O
spanned	O
by	O
the	O
template	O
.	O
</s>
<s>
More	O
formally	O
,	O
if	O
is	O
the	O
center	O
(	O
or	O
origin	O
)	O
of	O
the	O
template	O
image	O
,	O
then	O
the	O
cross	O
correlation	O
at	O
each	O
point	O
in	O
the	O
search	O
image	O
can	O
be	O
computed	O
as:For	O
convenience	O
,	O
denotes	O
both	O
the	O
pixel	B-Algorithm
values	O
of	O
the	O
template	O
image	O
as	O
well	O
as	O
its	O
domain	B-Algorithm
,	O
the	O
bounds	O
of	O
the	O
template	O
.	O
</s>
<s>
Since	O
cross	O
correlation	O
values	O
are	O
greatest	O
when	O
the	O
values	O
of	O
the	O
search	O
and	O
template	O
pixels	B-Algorithm
align	O
,	O
the	O
best	O
matching	O
position	O
corresponds	O
to	O
the	O
maximum	O
value	O
of	O
over	O
.	O
</s>
<s>
Another	O
way	O
to	O
handle	O
translation	O
problems	O
on	O
images	O
using	O
template	B-Algorithm
matching	I-Algorithm
is	O
to	O
compare	O
the	O
intensities	O
of	O
the	O
pixels	B-Algorithm
,	O
using	O
the	O
sum	B-Algorithm
of	I-Algorithm
absolute	I-Algorithm
differences	I-Algorithm
(	O
SAD	O
)	O
measure	O
.	O
</s>
<s>
To	O
formulate	O
this	O
,	O
let	O
and	O
denote	O
the	O
light	O
intensity	O
of	O
pixels	B-Algorithm
in	O
the	O
search	O
and	O
template	O
images	O
with	O
coordinates	O
and	O
,	O
respectively	O
.	O
</s>
<s>
Then	O
by	O
moving	O
the	O
center	O
(	O
or	O
origin	O
)	O
of	O
the	O
template	O
to	O
a	O
point	O
in	O
the	O
search	O
image	O
,	O
as	O
before	O
,	O
the	O
sum	B-Algorithm
of	I-Algorithm
absolute	I-Algorithm
differences	I-Algorithm
between	O
the	O
template	O
and	O
search	O
pixel	B-Algorithm
intensities	O
at	O
that	O
point	O
is:With	O
this	O
measure	O
,	O
the	O
lowest	O
SAD	O
gives	O
the	O
best	O
position	O
for	O
the	O
template	O
,	O
rather	O
than	O
the	O
greatest	O
as	O
with	O
cross	O
correlation	O
.	O
</s>
<s>
A	O
simple	O
C++	B-Language
implementation	O
of	O
SAD	O
template	B-Algorithm
matching	I-Algorithm
is	O
given	O
below	O
.	O
</s>
<s>
In	O
this	O
simple	O
implementation	O
,	O
it	O
is	O
assumed	O
that	O
the	O
above	O
described	O
method	O
is	O
applied	O
on	O
grey	O
images	O
:	O
This	O
is	O
why	O
Grey	O
is	O
used	O
as	O
pixel	B-Algorithm
intensity	O
.	O
</s>
<s>
One	O
way	O
to	O
perform	O
template	B-Algorithm
matching	I-Algorithm
on	O
color	O
images	O
is	O
to	O
decompose	O
the	O
pixels	B-Algorithm
into	O
their	O
color	O
components	O
and	O
measure	O
the	O
quality	O
of	O
match	O
between	O
the	O
color	O
template	O
and	O
search	O
image	O
using	O
the	O
sum	O
of	O
the	O
SAD	O
computed	O
for	O
each	O
color	O
separately	O
.	O
</s>
<s>
In	O
the	O
past	O
,	O
this	O
type	O
of	O
spatial	O
filtering	O
was	O
normally	O
only	O
used	O
in	O
dedicated	O
hardware	O
solutions	O
because	O
of	O
the	O
computational	O
complexity	O
of	O
the	O
operation	O
,	O
however	O
we	O
can	O
lessen	O
this	O
complexity	O
by	O
filtering	O
it	O
in	O
the	O
frequency	O
domain	B-Algorithm
of	O
the	O
image	O
,	O
referred	O
to	O
as	O
'	O
frequency	O
domain	B-Algorithm
filtering	O
,	O
'	O
this	O
is	O
done	O
through	O
the	O
use	O
of	O
the	O
convolution	O
theorem	O
.	O
</s>
<s>
Another	O
way	O
of	O
speeding	O
up	O
the	O
matching	O
process	O
is	O
through	O
the	O
use	O
of	O
an	O
image	B-Algorithm
pyramid	I-Algorithm
.	O
</s>
<s>
Other	O
methods	O
can	O
handle	O
problems	O
such	O
as	O
translation	O
,	O
scale	O
,	O
image	O
rotation	O
and	O
even	O
all	O
affine	O
transformations	B-Algorithm
.	O
</s>
<s>
It	O
is	O
also	O
possible	O
to	O
improve	O
the	O
accuracy	O
of	O
the	O
matching	O
method	O
by	O
hybridizing	O
the	O
feature-based	O
and	O
template-based	O
approaches	O
.	O
</s>
<s>
Naturally	O
,	O
this	O
requires	O
that	O
the	O
search	O
and	O
template	O
images	O
have	O
features	B-Algorithm
that	O
are	O
apparent	O
enough	O
to	O
support	O
feature	B-Algorithm
matching	O
.	O
</s>
<s>
Other	O
methods	O
which	O
are	O
similar	O
include	O
'	O
Stereo	O
matching	O
 '	O
,	O
'	O
Image	B-Algorithm
registration	I-Algorithm
 '	O
and	O
'	O
Scale-invariant	B-Algorithm
feature	I-Algorithm
transform	I-Algorithm
 '	O
.	O
</s>
<s>
Template	B-Algorithm
matching	I-Algorithm
has	O
various	O
applications	O
and	O
is	O
used	O
in	O
such	O
fields	O
as	O
face	O
recognition	O
(	O
see	O
facial	O
recognition	O
system	O
)	O
and	O
medical	O
image	B-Algorithm
processing	I-Algorithm
.	O
</s>
