Template matching is one of the simplest image detection methods. The idea is to
slide an image template (binary shapes, or gray level patterns) over the image at
hand - a 2D search - to see if an image object matching the template can be found
somewhere in the image. The image template can be stored in the library as a 2D array
,
where
is the
size of the object.
Specifically, we define a distance between the template and a subimage
This distance can be written as
The distance defined above should also be normalized by the total energy contained in
the subimage to represent the relative difference between the template and the image,
so that the distance is not affected by the subimage intensity. We redefine the distance as
D(k,l) | = | ![]() |
|
= | ![]() |
Rotational and size invariance can be achieved by extending the template match
to a 4D to include two more dimensions for rotational angle
and scaling
factor s.