Template Matching
Given a I1 × I2 image, called landscape, and a P1 × P2 image patch, called pattern, the template matching consists in finding the precise location (x,y) of the pattern inside the landscape image. Here, it is assumed that the pattern size is smaller than the landscape image.
A simple approach to do this is using a sliding window along the landscape image. The process basically consists in sliding a window, of the same size of the example pattern, over every pixel of the landscape image, and extracting a patch. This patch is then compared with the example pattern using a similarity measure. Figure 1 shows an example of this process. The window with the highest similarity value is said the matching point. Several similarity measures can be used, and the common choices are the sum of the absolute differences and the sum of the squared differences.
Figure 1. Example of the sliding window approach for the pattern detection problem using template matching
Most common template matching approaches restrict the search in a 2D plane, in this case translation in x and y axis. This restriction occurs mainly to reduce the computational effort demanded to solve the problem.
Besides the translations of the pattern in the 2D plane, other image transformations could occur, such as scale (translation in the z axis) and rotation. Consequently, the template matching problem can be more properly defined as finding a 4-tuple (x, y, s, Θ), where x and y are the center coordinates of the pattern, s, is the scale factor, and Θ, the rotation angle (Gonzales, 2009).