{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1712","labels_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1712/labels{/name}","comments_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1712/comments","events_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1712/events","html_url":"https://github.com/scikit-image/scikit-image/issues/1712","id":107035602,"number":1712,"title":"feature.match_template gives out-of-range match values","user":{"login":"zpincus","id":174217,"avatar_url":"https://avatars.githubusercontent.com/u/174217?v=3","gravatar_id":"","url":"https://api.github.com/users/zpincus","html_url":"https://github.com/zpincus","followers_url":"https://api.github.com/users/zpincus/followers","following_url":"https://api.github.com/users/zpincus/following{/other_user}","gists_url":"https://api.github.com/users/zpincus/gists{/gist_id}","starred_url":"https://api.github.com/users/zpincus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zpincus/subscriptions","organizations_url":"https://api.github.com/users/zpincus/orgs","repos_url":"https://api.github.com/users/zpincus/repos","events_url":"https://api.github.com/users/zpincus/events{/privacy}","received_events_url":"https://api.github.com/users/zpincus/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/scikit-image/scikit-image/labels/bug","name":"bug","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":35,"created_at":"2015-09-17T17:41:17Z","updated_at":"2015-12-16T19:11:18Z","closed_at":null,"body":"Hello all,\r\n\r\nI have found that in at least certain modes, `skimage.feature.match_template` calculates very incorrect cross-correlation values, well outside of the [-1,1] range that is expected. I have attached a simple test case, with a large image and a small template. [This old StackOverflow answer](http://stackoverflow.com/questions/20102353/scikit-image-match-template-returns-undocumented-values) by @stefanv seems to suggest that such a bug was fixed a while ago, but if so, it's back.\r\n\r\nDifferent padding modes change the scale of the misbehavior, but even `pad_input=False` still yields wrong cross-correlation values.\r\n\r\n```python\r\nimport skimage\r\nskimage.__version__ # '0.12dev'\r\nfrom skimage import feature\r\nfrom skimage import io\r\ntemplate = io.imread('template.png')\r\nimage = io.imread('image.png')\r\npeaks = feature.match_template(image, template, pad_input=True, mode='edge')\r\npeaks.min() # -26.632982\r\npeaks.max() # 1.7565135\r\n```\r\n\r\nStrangely, if I crop the image a little, to include the positions of the erroneous min and max values, then the values change. But cross-correlation should be a local operation! Maybe the problem appears if the image is too large?\r\n\r\n```python\r\nimport numpy\r\nnumpy.unravel_index(peaks.argmin(), peaks.shape) # (2449, 885)\r\nnumpy.unravel_index(peaks.argmax(), peaks.shape) # (2494, 404)\r\nimage.shape # (2500, 1660)\r\ntemplate.shape # (76, 76)\r\nsmall = image[2000:, :1200]\r\npeaks_small = feature.match_template(small, template, pad_input=True, mode='edge')\r\npeaks_small.min() # -0.5584954\r\npeaks_small.max() # 0.82173121\r\n```\r\n\r\n\r\n![image](https://cloud.githubusercontent.com/assets/174217/9940631/9ce28896-5d36-11e5-93d2-13459eb34577.png)\r\n![template](https://cloud.githubusercontent.com/assets/174217/9940683/e6758ecc-5d36-11e5-8659-d26af9e0e85d.png)"},"comment":{"url":"https://api.github.com/repos/scikit-image/scikit-image/issues/comments/165215145","html_url":"https://github.com/scikit-image/scikit-image/issues/1712#issuecomment-165215145","issue_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1712","id":165215145,"user":{"login":"stefanv","id":45071,"avatar_url":"https://avatars.githubusercontent.com/u/45071?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanv","html_url":"https://github.com/stefanv","followers_url":"https://api.github.com/users/stefanv/followers","following_url":"https://api.github.com/users/stefanv/following{/other_user}","gists_url":"https://api.github.com/users/stefanv/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanv/subscriptions","organizations_url":"https://api.github.com/users/stefanv/orgs","repos_url":"https://api.github.com/users/stefanv/repos","events_url":"https://api.github.com/users/stefanv/events{/privacy}","received_events_url":"https://api.github.com/users/stefanv/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T19:11:18Z","updated_at":"2015-12-16T19:11:18Z","body":"@MartinSavc Did you get a chance to try the new version of Kahan I sent?"}}