Add doctest example to match_template.

This commit is contained in:
Tony S Yu
2012-03-30 00:10:03 -04:00
parent a2f91585ef
commit 06bd3ebd6f
+32
View File
@@ -32,6 +32,38 @@ def match_template(image, template, pad_input=False):
`(m, n)` template, the `output` is `(M - m + 1, N - n + 1)` when
`pad_input = False` and `(M, N)` when `pad_input = True`.
Examples
--------
>>> template = np.zeros((3, 3))
>>> template[1, 1] = 1
>>> print template
[[ 0. 0. 0.]
[ 0. 1. 0.]
[ 0. 0. 0.]]
>>> image = np.zeros((6, 6))
>>> image[1, 1] = 1
>>> image[4, 4] = -1
>>> print image
[[ 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)
>>> print np.round(result, 3)
[[ 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)
>>> print np.round(result, 3)
[[-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]]
"""
if np.any(np.less(image.shape, template.shape)):
raise ValueError("Image must be larger than template.")