diff --git a/skimage/feature/template.py b/skimage/feature/template.py index b328131f..6ad45926 100644 --- a/skimage/feature/template.py +++ b/skimage/feature/template.py @@ -6,12 +6,11 @@ import _template from skimage.util.dtype import _convert -def match_template(image, template, pad_output=False): +def match_template(image, template, pad_input=False): """Match a template to an image using normalized correlation. The output is an array with values between -1.0 and 1.0, which correspond - to the probability that the template's *origin* (i.e. its top-left - corner) is found at that position. + to the probability that the template is found at that position. Parameters ---------- @@ -19,18 +18,19 @@ def match_template(image, template, pad_output=False): Image to process. template : array_like Template to locate. - pad_output : bool - If True, pad output array to be the same size as the input image. + pad_input : bool + If True, pad `image` with image mean so that output is the same size as + the image, and output values correspond to the template center. Otherwise, the output is an array with shape `(M - m + 1, N - n + 1)` - for an `(M, N)` image and an `(m, n)` template. + for an `(M, N)` image and an `(m, n)` template, and matches correspond + to origin (top-left corner) of the template. Returns ------- output : ndarray - Correlation results between -1.0 and 1.0. The `output` is truncated - (`pad_output = False`) or zero-padded (`pad_output = True`) at the - bottom and right edges, where the template would otherwise extend - beyond the image edges. + Correlation results between -1.0 and 1.0. For an `(M, N)` image and an + `(m, n)` template, the `output` is `(M - m + 1, N - n + 1)` when + `pad_input = False` and `(M, N)` when `pad_input = True`. """ if np.any(np.less(image.shape, template.shape)): @@ -38,7 +38,7 @@ def match_template(image, template, pad_output=False): image = _convert(image, np.float32) template = _convert(template, np.float32) - if pad_output: + if pad_input: pad_size = tuple(np.array(image.shape) + np.array(template.shape) - 1) pad_image = np.mean(image) * np.ones(pad_size, dtype=np.float32) h, w = image.shape