Learn R Programming

Rvision (version 0.4.2)

matchTemplate: Template Matching

Description

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" were used) or maximums (when methods "CCORR", "CCORR_NORMED", "CCOEFF" or "CCOEF_NORMED" were used) using the minMaxLoc function.

Usage

matchTemplate(image, template, method, mask = NULL)

Arguments

image

An Image object.

template

An Image object of the same type as image. template cannot be larger than image.

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 of the same type and dimensions as template (default: NULL). mask is currently only supported when SQDIFF and CCORR_NORMED are used.

Value

A 16-bit grayscale Image object of the same dimensions as image.

See Also

Image, minMaxLoc

Examples

Run this code
# NOT RUN {
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)
plot(balloon)
points(mm[1, 2], mm[1, 3], col = "red", pch = 20, cex = 5)

# }

Run the code above in your browser using DataLab