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.
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.
2-D or 3-D input image.
Template to locate. It must be :None:None:`(m <= M, n <= N[, d <= D])`
.
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.
Padding mode.
Constant values used in conjunction with mode='constant'
.
Response image with correlation coefficients.
Match a template to a 2-D or 3-D image using normalized correlation.
>>> template = np.zeros((3, 3))This example is valid syntax, but we were not able to check execution
... template[1, 1] = 1
... template array([[0., 0., 0.], [0., 1., 0.], [0., 0., 0.]])
>>> image = np.zeros((6, 6))This example is valid syntax, but we were not able to check execution
... 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.]])
>>> result = match_template(image, template)This example is valid syntax, but we were not able to check execution
... 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. ]])
>>> result = match_template(image, template, pad_input=True)See :
... 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]])
The following pages refer to to this document either explicitly or contain code examples using this.
skimage.feature.template.match_template
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