Added to Favorites

Popular Searches

Definitions

Template matching is a technique in Digital image processing for finding small parts of an image which match a template image. It can be used in manufacturing as a part of quality control, a way to navigate a mobile robot, or as a way to detect edges in images.
## Approach

There are different approaches to accomplish template matching. Some are faster performers than others, and some find better matches. ## Implementation

## Example

+ =
## Speeding up the Process

## Improving the performance of the matching

## Similar Methods

## Examples of Use

## References

## See also

## External links

The basic method of template matching uses a convolution mask (template), tailored to a specific feature of the search image, which we want detect. This technique can be easily performed on grey images or edge images. It is intuitively likely that the convolution output will be highest at places where the image structure matches the mask structure, where large image values get multiplied by large mask values.

This method is normally implemented by firstly picking out a part of the search image to use as a template:
We will call the search image S(x, y), where (x, y) represent the coordinates of each pixel in the search image. We will call the template T(x _{t}, y _{t}), where (x_{t}, y_{t}) represent the coordinates of each pixel in the template. We then simply move the center (or the origin) of the template T(x _{t}, y _{t}) over each (x, y) point in the search image and calculate the sum of products between the coefficients in S(x, y) and T(x_{t}, y_{t}) over the whole area spanned by the template. As all possible positions of the template with respect to the search image are considered, the position with the highest score is the best position. This method is sometimes referred to as 'Linear Spatial Filtering' and the template is called a filter mask.

For example, one way to handle translation problems on images, using template matching is to compare the intensities of the pixels, using the SAD (Sum of absolute differences) measure.

A pixel in the search image with coordinates (x_{s}, y_{s}) has intensity I_{s}(x_{s}, y_{s}) and a pixel in the template with coordinates (x_{t}, y_{t}) has intensity I_{t}(x_{t} , y_{t} ). Thus the absolute difference in the pixel intensities is defined as Diff(x_{s}, y_{s}, x _{t}, y _{t}) = | I_{s}(x_{s}, y_{s}) – I_{t}(x _{t}, y _{t}) |.

$SAD(x,\; y)\; =\; sum\_\{i=0\}^\{T\_\{rows\}\}sum\_\{j=0\}^\{T\_\{cols\}\}\; \{Diff(x+i,\; y+j,i,j)\}$

The mathematical representation of the idea about looping through the pixels in the search image as we translate the origin of the template at every pixel and take the SAD measure is the following:

$max\_\{x=0\}^\{S\_\{rows\}\}max\_\{y=0\}^\{S\_\{cols\}\}\; \{SAD(x,\; y)\}$

S_{rows} and S_{cols} denote the rows and the columns of the search image and T_{rows} and T_{cols} denote the rows and the columns of the template image, respectively.
In this method the lowest SAD score gives the estimate for the best position of template within the search image. The method is simple to implement and understand, but it is one of the slowest methods.

In this simple implementation, it is assumed that the above described method is applied on grey images: This is why Grey is used as pixel intensity.

// loop through the search image for (int x = 0; x <= S_rows - T_rows; x++ ) {

for (int y = 0; y <= S_cols - T_cols; y++ ) {

SAD = 0.0;

// loop through the template image for (int i = 0; i < T_rows; i++ ) for (int j = 0; j < T_cols; j++ ) {

pixel p_SearchIMG = S[x+i][y+j];

pixel p_TemplateIMG = T[i][j];

SAD += abs(p_SearchIMG.Grey - p_TemplateIMG.Grey );}

// save the best found positionif (minSAD > SAD ) { minSAD = SAD; position.bestRow = x; position.bestCol = y; position.bestSAD = SAD; } } }

One way to perform template matching on color images is to decompose the pixels into their color components and measure the quality of match between the color template and search image using the sum of the SAD computed for each color separately.

In the past, this type of spatial filtering was normally only used in dedicated hardware solutions because of the computational complexity of the operation, however we can lessen this complexity by filtering it in the frequency domain of the image, referred to as 'frequency domain filtering,' this is done through the use of the convolution theorem.

Another way of speeding up the matching process is through the use of an image pyramid. This is a series of images, at different scales, which formed by repeatedly filtering and subsampling the original image in order to generate a sequence of reduced resolution images. These lower resolution images can then be searched for the template (with a similarly reduced resolution), in order to yield possible start positions for searching at the larger scales. The larger images can then be searched in a small window around the start position to find the best template location.

Other methods can handle problems such as translation, scale and image rotation.

Improvements can be made to the matching method by using more than one template, these other templates can have different scales and rotations.

Other methods which are similar include 'Stereo matching,' 'Image registration' and 'Scale-invariant feature transform.'

Template matching has various different applications and is used in such fields as face recognition (see facial recognition system) and medical image processing. Systems have been developed and used in the past to count the number of faces that walk across part of a bridge within a certain amount of time. Other systems include automated calcified nodule detection within digital chest X-rays.

- Template Matching
- Visual Object Recognition using Template Matching
- Rotation, scale, translation-invariant template matching demonstration program

Wikipedia, the free encyclopedia © 2001-2006 Wikipedia contributors (Disclaimer)

This article is licensed under the GNU Free Documentation License.

Last updated on Friday August 15, 2008 at 15:40:04 PDT (GMT -0700)

View this article at Wikipedia.org - Edit this article at Wikipedia.org - Donate to the Wikimedia Foundation

This article is licensed under the GNU Free Documentation License.

Last updated on Friday August 15, 2008 at 15:40:04 PDT (GMT -0700)

View this article at Wikipedia.org - Edit this article at Wikipedia.org - Donate to the Wikimedia Foundation

Copyright © 2015 Dictionary.com, LLC. All rights reserved.