Template Matching (Image Search) function in Python Imaging Library

微笑、不失礼 提交于 2019-12-22 01:11:46

问题


I had a problem where I need to search for a pattern (present as a numpy ndarray) within another image (also present as a numpy ndarray) and compute a template match (minimum difference position in the image). My question is... is there any in-built image that I can possibly use in the Python Imaging Library or Numpy or anything possible that can do this without me manually writing a function to do so???

Thank you....


回答1:


This is likely best done as an inverse convolution or correlation. Numpy/scipy has code to do both.

edit: including a little example.

Go here for the ipython notebook file: http://nbviewer.ipython.org/4020770/

I made a little gaussian and then use scipy.signal.correlate2d with the original image and a small subset.

you can see that the highest values of the correlation are centered around where the subset of the image was taken. note that for large kernels or images, this code can take a while (because correlation is expensive)



来源:https://stackoverflow.com/questions/13240176/template-matching-image-search-function-in-python-imaging-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!