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
Image
object.- template
An
Image
object with the same number of channels and bit depth asimage
.template
cannot be greater thanimage
in 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
Image
object 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 32FImage
object. 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.mask
is not supported whenmethod='CCOEFF_NORMED'
.- target
The location where the results should be stored. It can take 2 values:
- "new":
a new
Image
object is created and the results are stored inside (the default).- An
Image
object: the results are stored in another existing
Image
object. This is fast but will replace the content oftarget
. Note thattarget
must be a single-channel, 32FImage
object with(R-r+1)
rows and(C-c+1)
columns, whereCxR
andcxr
are the dimensions ofimage
andtemplate
, 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)