diff --git a/skimage/feature/template.py b/skimage/feature/template.py index 398e7c78..67064d5a 100644 --- a/skimage/feature/template.py +++ b/skimage/feature/template.py @@ -33,6 +33,8 @@ def match_template(image, template, pad_output=True): beyond the image edges. """ + if np.any(np.less(image.shape, template.shape)): + raise ValueError("Image must be larger than template.") image = _convert(image, np.float32) template = _convert(template, np.float32) diff --git a/skimage/feature/tests/test_template.py b/skimage/feature/tests/test_template.py index 36b72fd5..5ad1fb9b 100644 --- a/skimage/feature/tests/test_template.py +++ b/skimage/feature/tests/test_template.py @@ -70,6 +70,12 @@ def test_normalization(): assert np.allclose(result.flat[iflat_max], 1) +def test_switched_arguments(): + image = np.ones((5, 5)) + template = np.ones((3, 3)) + np.testing.assert_raises(ValueError, match_template, template, image) + + if __name__ == "__main__": from numpy import testing testing.run_module_suite()