matchTemplate compares a template against overlapping
image regions using the specified method. After the function finishes
the comparison, the best matches can be found as global minimums (when
methods "SQDIFF" or "SQDIFF_NORMED" are used) or maximums (when methods
"CCORR", "CCORR_NORMED", "CCOEFF" or "CCOEF_NORMED" are used) using the
minMaxLoc function.
Arguments
- image
An
Imageobject.- template
An
Imageobject with the same number of channels and bit depth asimage.templatecannot be greater thanimagein any dimension.- method
A string indicating the comparison method to use. It can be any of the following (see https://bit.ly/2RjELvJ for a full description of each comparison method):
"SQDIFF"
"SQDIFF_NORMED"
"CCORR"
"CCORR_NORMED"
"CCOEFF"
"CCOEFF_NORMED"
- mask
An
Imageobject with the same dimensions astemplate(default: NULL). It can have either one channel or the same number of channels astemplate. It can be an 8U or 32FImageobject. If 8U, it is interpreted as a binary mask, meaning only elements where mask is nonzero are used and are kept unchanged independent of the actual mask value. If 32F, then the mask values are used as weights.maskis not supported whenmethod='CCOEFF_NORMED'.- target
The location where the results should be stored. It can take 2 values:
- "new":
a new
Imageobject is created and the results are stored inside (the default).- An
Imageobject: the results are stored in another existing
Imageobject. This is fast but will replace the content oftarget. Note thattargetmust be a single-channel, 32FImageobject with(R-r+1)rows and(C-c+1)columns, whereCxRandcxrare the dimensions ofimageandtemplate, respectively.
Value
If target="new", the function returns an Image
object with (R-r+1) rows and (C-c+1) columns, where CxR
and cxr are the dimensions of image and template,
respectively. If target is an Image object, the
function returns nothing and modifies that Image object in
place.
Author
Simon Garnier, garnier@njit.edu
Examples
balloon <- image(system.file("sample_img/balloon1.png", package = "Rvision"))
sub <- subImage(balloon, 290, 170, 150, 150)
match <- matchTemplate(balloon, sub, method = "SQDIFF")
mm <- minMaxLoc(match)