tags:

views:

823

answers:

3

I am looking for the best way to detect an image within another image. I have a small image and would like to find the location that it appears within a larger image - which will actually be screen captures. Conceptually, it is like a 'Where's Waldo?' sort of search in the larger image.

Are there any efficient/quick ways to accomplish this? Speed is more important than memory.

Edit:

The 'inner' image may not always have the same scale but will have the same rotation.

It is not safe to assume that the image will be perfectly contained within the other, pixel for pixel.

A: 

You can treat this as a substring problem, where characters in the alphabet are pixels and your string is the image. You would need also to use a special character in a similar vein to a linebreak, to denote the image boundary.

The algorithm you want is on wikipedia: http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm

Update: If you cannot assume that the image is perfectly contained within the other, pixel for pixel, then this approach will not work.

There are other, more complicated algorithms based on the same dynamic programming concept as the above, but I won't go into them unless it's necessary.

Owen
If the images are JPEGs you are going to have a headache :-)
PolyThinker
Yes. That is a very, very good point. If you cannot assume a perfect match, then the notion of 'best' because difficult and 'efficient/quick' become hard. You would need to do something based on energy minimization / dynamic programming
Owen
Voted down because methods like this will not work at all on images.
endolith
+6  A: 

Wikipedia has an article on Template Matching, with sample code.

(While that page doesn't handle changed scales, it has links to other styles of matching, for example Scale invariant feature transform)

Stephen Denne
+1, the SIFT algorithm I have used much in http://user.cs.tu-berlin.de/~nowozin/autopano-sift/ , and its very effective at what it does, even handles image distortion sometimes.
Kent Fredric
There's a java implementation of SIFT at http://fly.mpi-cbg.de/~saalfeld/javasift.html
Stephen Denne
+1  A: 

If rotation also had to be catered for, the Generalised Hough Transform can be used.

Stephen Denne