skimage 0.17.2

NotesParametersReturnsBackRef
match_template(image, template, pad_input=False, mode='constant', constant_values=0)

The output is an array with values between -1.0 and 1.0. The value at a given position corresponds to the correlation coefficient between the image and the template.

For :None:None:`pad_input=True` matches correspond to the center and otherwise to the top-left corner of the template. To find the best match you must search for peaks in the response (output) image.

Notes

Details on the cross-correlation are presented in . This implementation uses FFT convolutions of the image and the template. Reference presents similar derivations but the approximation presented in this reference is not used in our implementation.

Parameters

image : (M, N[, D]) array

2-D or 3-D input image.

template : (m, n[, d]) array

Template to locate. It must be :None:None:`(m <= M, n <= N[, d <= D])`.

pad_input : bool

If True, pad :None:None:`image` 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 :None:None:`(M - m + 1, N - n + 1)` for an :None:None:`(M, N)` image and an :None:None:`(m, n)` template, and matches correspond to origin (top-left corner) of the template.

mode : see `numpy.pad`, optional

Padding mode.

constant_values : see `numpy.pad`, optional

Constant values used in conjunction with mode='constant' .

Returns

output : array

Response image with correlation coefficients.

Match a template to a 2-D or 3-D image using normalized correlation.

Examples

This example is valid syntax, but we were not able to check execution
>>> template = np.zeros((3, 3))
... template[1, 1] = 1
... template array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]])
This example is valid syntax, but we were not able to check execution
>>> image = np.zeros((6, 6))
... image[1, 1] = 1
... image[4, 4] = -1
... image array([[ 0., 0., 0., 0., 0., 0.], [ 0., 1., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., -1., 0.], [ 0., 0., 0., 0., 0., 0.]])
This example is valid syntax, but we were not able to check execution
>>> result = match_template(image, template)
... np.round(result, 3) array([[ 1. , -0.125, 0. , 0. ], [-0.125, -0.125, 0. , 0. ], [ 0. , 0. , 0.125, 0.125], [ 0. , 0. , 0.125, -1. ]])
This example is valid syntax, but we were not able to check execution
>>> result = match_template(image, template, pad_input=True)
... np.round(result, 3) array([[-0.125, -0.125, -0.125, 0. , 0. , 0. ], [-0.125, 1. , -0.125, 0. , 0. , 0. ], [-0.125, -0.125, -0.125, 0. , 0. , 0. ], [ 0. , 0. , 0. , 0.125, 0.125, 0.125], [ 0. , 0. , 0. , 0.125, -1. , 0.125], [ 0. , 0. , 0. , 0.125, 0.125, 0.125]])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

skimage.feature.template.match_template

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /skimage/feature/template.py#31
type: <class 'function'>
Commit: