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, seeWhat Are System Objects?
Creation
Description
returns a template matcher object,tMatcher
=愿景。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
=愿景。TemplateMatcher(Name,Value
)tMatcher = vision.TemplateMatcher('Metric','Sum of absolute differences')
道具erties
Usage
Syntax
Description
returns the [xy] 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 matchlocation
,numberOfValues
,numValid
] = tMatcher(I
,T
,ROI
)location
, the metric values around the best matchnumberOfValues
, and a logical flagnumValid
. This applies when you set theOutputValue
property to'Best match location'
and theBestMatchNeighborhoodOutputPort
property totrue
.
[
also returns a logical flag,location
,numberOfValues
,numValid
,ROIvalid
] = tMatcher(I
,T
,ROI
)ROIvalid
to indicate whether theROI
is outside the bounds of the input imageI
. This applies when you set theOutputValue
property to'Best match location'
, and theBestMatchNeighborhoodOutputPort
,ROIInputPort
, andROIValidityOutputPort
properties totrue
.
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 namedobj
, 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 [xy] 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 |
---|---|