Image Processing Reference
In-Depth Information
| H
| F
|
|
where θ is the angle between the two vectors, and
are the lengths
of the two vectors. The normalization of the dot product between the vectors is a
fact because cos θ
and
| H
∈[−
1 , 1
]
. The length of
|
, which is also the “length” of the
template, is calculated as
R
R
Length of template
=
h(i, j )
·
h(i, j)
(5.6)
j
=−
R
i
=−
R
where R is the radius of the template and h(i, j ) is the coefficient in the template at
position (i, j ) . The length of the image patch is calculated in the same manner.
When using this normalization the bright spots in the output no longer depend on
whether the image is bright or not but only on how similar the template and the un-
derlying image patch are. This version of template matching is denoted normalized
cross-correlation (NCC) and calculated for each pixel (x, y) using the following
equation:
Correlation
Length of image patch
NCC (x, y)
=
·
Length of template
j =− R i =− R (H
·
F)
NCC (x, y)
=
j =− R i =− R (F
j =− R i =− R (H
(5.7)
·
F)
·
·
H)
where R is the radius of the template, H
= h(i, j) is the template and F
=
f(x + i, y + j) is the image patch. cos θ ∈[−
but since the image patch and
the template always contain positive numbers, cos θ ∈[
1 , 1
]
0 , 1
]
, i.e., the output of nor-
[
]
malized cross-correlation is normalized to the interval
, where 0 means no
similarity and 1 means a complete similarity. In Fig. 5.10 the benefit of applying
normalized cross-correlation can be seen.
An even more advanced version of template matching exist. Here the mean values
of the template and image patch are subtracted from H and F , respectively. This is
known as the zero-mean normalized cross-correlation or the correlation coefficient .
The output is in the interval
0 , 1
[−
1 , 1
]
where 1 indicates a maximum similarity (as for
NCC) and
1 indicates a maximum negative similarity, meaning the same pattern
but opposite gray-scale values: 255 instead of 0, 254 instead of 1, etc.
Independent of the type of template matching, the kernel (template) is usually
much bigger than the kernels/filters used in other neighborhood operations. Tem-
plate matching is therefore a time consuming method and can benefit from intro-
ducing a region-of-interest, see Sect. 2.4.1.
A general assumption in template matching is that the object we are looking for
has roughly the same size and rotation in both the template and the image. If this
cannot be ensured, then we need to have multiple scaled and rotated versions of
the template and perform template matching using each of these templates. This
requires significant resources and the speed of the system is likely to drop.
Search WWH ::

Custom Search