0

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....

gran_profaci
  • 8,087
  • 15
  • 66
  • 99

1 Answers1

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)

giessel
  • 452
  • 4
  • 5
  • hopefully that's more useful now ;) – giessel Nov 05 '12 at 22:20
  • So let me get this right. I have to convert my image into a Gaussian and then do a template by template iteration through my image till it hits a spot that has a similar gaussian to my original image's gaussian?? – gran_profaci Nov 07 '12 at 04:37
  • no- the guassian is simply an example, use your own patterns and template image. The correlation routine does the comparison across the whole image and returns an array. This result array is high where the template and the large image are similar. – giessel Nov 08 '12 at 22:16