Template match - different sizes of template and image

mnn picture mnn · Mar 19, 2011 · Viewed 7.6k times · Source

I have an image, which I can obtain at better quality (e.g. higher size). The problem is that I can't do template match on default size, only on a higher one. And the higher one is not fixed - it can be anything from 1.0 to 2.5x of original image.

I was thinking of retrieving templates in higher resolution and then depending on what's the size of the image, resize down the templates. However, that might yield completely wrong results, when I use different resize algorithm.

What do you suggest? How should I proceed, when I want to do template matching in such circumstances?

Edit: Just note - templates will always be the same and their counterparts in images too (images are computer-generated).

Answer

code-gijoe picture code-gijoe · Mar 19, 2011

So are you saying you have an image template at nominal scale of 1.0 and target image in which you want to match ranging from 1.0 to 2.5x?

Scale invariant pattern matching algorithms are pretty complex. The simplest thing to do is to scale down your target image to multiple intermediate resolutions and try to match it with your template. For better performance, try to reduce the scale of your template (say 0.5) so that your target will fall in the 0.5-1.75 range. When working on different resolutions, try to smooth your images a bit.

Finally to make sure your template match is accurate, increase your scale of your target image and template image tracking the last {x, y} position up to your new res. You can do this until greatest resolution is attained. Normalized grayscale correlation is a pretty good and fast algo for pattern matching.