Back to Adaptive Vision Studio website

You are here: Start » Filter Reference » Template Matching » LocateSingleObject_SAD


Finds a single occurrence of a predefined template on an image by analysing the Square Average Difference between pixel values.

Name Type Range Description
inImage Image Image on which model occurrence will be searched
inSearchRegion Region* Possible centers of the object occurrence
inGrayModel GrayModel Model which will be sought
inMinPyramidLevel Integer 0 - 12 Defines the highest resolution level
inMaxPyramidLevel Integer* 0 - 12 Defines the number of reduced resolution levels that can be used to speed up computations
inIgnoreBoundaryObjects Bool Flag indicating whether objects crossing image boundary should be ignored or not
inMaxDifference Real 0.0 - Maximum accepted average difference between pixel values
outObject Object2D? Found object
outPyramidHeight Integer Highest pyramid level used to speed up computations
diagImagePyramid ImageArray Pyramid of iteratively downsampled input image
diagMatchPyramid ImageArray Locations found on each pyramid level
diagScores RealArray? Scores of found match on each pyramid level


Almost always inferior to NCC, so rarely used in real applications.


The operation matches the object model, inGrayModel, against the input image, inImage. The inSearchRegion region restricts the search area so that only in this region the centers of the objects can be presented. The inMaxDifference parameter determines the maximum average difference between corresponding pixel values of the valid object occurrence.

The computation time of the filter depends on the size of the model, the sizes of inImage and inSearchRegion, but also on the value of inMaxDifference. This parameter is a score threshold. Based on its value some partial computation can be sufficient to reject some locations as valid object instances. Moreover, the pyramid of the images is used. Thus, only the highest pyramid level is searched exhaustively, and potential candidates are later validated at lower levels. The inMinPyramidLevel parameter determines the lowest pyramid level used to validate such candidates. Setting this parameter to a value greater than 0 may speed up the computation significantly, especially for higher resolution images. However, the accuracy of the found object occurrences can be reduced. Lower inMaxDifference generates less potential candidates on the highest level to verify on lower levels. It should be noted that some valid occurrences with score above this score threshold can be missed. On higher levels score can be slightly lower than on lower levels. Thus, some valid object occurrences which on the lowest level would be deemed to be valid object instances can be incorrectly missed on some higher level. The diagMatchPyramid output represents all potential candidates recognized on each pyramid level and can be helpful during the difficult process of the proper parameter setting.

To be able to locate objects which are partially outside the image, the filter assumes that there are only black pixels beyond the image border.

The outObject.Point contains the model reference point of the matched object occurrence. The outObject.Angle contains the rotation angle of the object. The outObject.Match provides information about both the position and the angle of the found match combined into value of Rectangle2D type. The outObject.Alignment contains information about the transform required for geometrical objects defined in the context of template image to be transformed into object in the context of outObject.Match position. This value can be later used e.g. by 1D Edge Detection or Shape Fitting categories filters.

The SAD (Sum of Absolute Differences) method can be significantly slower than NCC (Normalized Cross-Correlation) method. Moreover, it is not illumination-invariant, as it is required in most applications. Thus, it is highly recommended to use the latter, NCC method instead.


For more information about local coordinate systems please refer to the following article.

More informations about creating models can be found in article: Creating Models for Template Matching.

Additional information about Template Matching can be found in Machine Vision Guide: Template Matching

Hardware Acceleration

This operation supports automatic parallelization for multicore and multiprocessor systems.

Complexity Level

This filter is available on Expert Complexity Level.

Filter Group

This filter is member of LocateObjects_SAD filter group.

See Also

  • LocateMultipleObjects_SAD – Finds multiple occurrences of a predefined template on an image by analysing the Square Average Difference between pixel values.
  • LocateSingleObject_NCC – Finds a single occurrence of a predefined template on an image by analysing the normalized correlation between pixel values.