问题
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