vision.TemplateMatcher
Locate template in image
Description
To locate a template in an image.
Create the
vision.TemplateMatcher
object and set its properties.Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?
Creation
Description
returns
a template matcher object, tMatcher
= vision.TemplateMatchertMatcher
. This object performs template
matching by shifting a template in single-pixel increments throughout the interior of an
image.
sets properties using one or more name-value pairs. Enclose each property name in
quotes. For example, tMatcher
= vision.TemplateMatcher(Name,Value
)tMatcher = vision.TemplateMatcher('Metric','Sum of
absolute differences')
Properties
Usage
Syntax
Description
returns the [x
y] location coordinates of the best template match relative to the
top left corner of the image between the image matrix, location
= tMatcher(I
,T
)I
, and the
template matrix, T
. The object computes the location by shifting
the template in single-pixel increments throughout the interior of the image.
[
returns
the location of the best template match location
,numberOfValues
,numValid
] = tMatcher(I
,T
,ROI
)location
, the metric values
around the best match numberOfValues
, and a logical flag
numValid
. This applies when you set the OutputValue
property to 'Best match location'
and the
BestMatchNeighborhoodOutputPort
property to
true
.
[
also returns a logical flag, location
,numberOfValues
,numValid
,ROIvalid
] = tMatcher(I
,T
,ROI
)ROIvalid
to indicate whether the
ROI
is outside the bounds of the input image
I
. This applies when you set the OutputValue
property to 'Best match location'
, and the
BestMatchNeighborhoodOutputPort
, ROIInputPort
, and ROIValidityOutputPort
properties to true
.
[
also
returns a logical flag location
,ROIvalid
] = tMatcher(I
,T
,ROI
)ROIvalid
indicating if the specified
ROI
is outside the bounds of the input image
I
. This applies when you set the OutputValue
property to 'Best match location'
, and both
the ROIInputPort
and ROIValidityOutputPort
properties to true
.
Input Arguments
Output Arguments
Object Functions
To use an object function, specify the
System object™ as the first input argument. For
example, to release system resources of a System object named obj
, use
this syntax:
release(obj)
Examples
Algorithms
Typical use of the template matcher involves finding a small region within a larger image. The region is specified by the template image which can be as large as the input image, but which is typically smaller than the input image.
The object outputs the best match coordinates, relative to the top-left corner of the
image. The [x
y] coordinates of the location correspond to the center of the template.
When you use a template with an odd number of pixels, the object uses the center of the
template. When you use a template with an even number of pixels, the object uses the centered
upper-left pixel for the location. The following table shows how the object outputs the
location (LOC
), of odd and even templates:
Odd number of pixels in template | Even number of pixels in template |
---|---|
Extended Capabilities
Version History
Introduced in R2012a
See Also
opticalFlowHS
| opticalFlowLKDoG
| opticalFlowLK
| opticalFlowFarneback
| insertMarker