Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is a huge topic, with answers from 3 lines of code to entire research magazines.

I will outline the most common such techniques and their results.

  • Comparing histograms. One of the simplest & fastest methods. Proposed decades ago as a means to find picture simmilarities. The idea is that a forest will have a lot of green, and a human face a lot of pink, or whatever. So, if you compare two pictures with forests, you'll get some simmilarity between histograms, because you have a lot of green in both.

    Downside: it is too simplistic. What is the difference between a banana and a beach? both are yellow.

    OpenCV method: compareHist()

  • Template matching : http://stackoverflow.com/questions/8520882/matchtemplate-finding-good-match. It convolutes the search image with the one being search into. It is usually used to find smaller image parts in a bigger one.

    Downsides: It only returns good results with identical images, same size & orientation.
    OpenCV method: matchTemplate()

  • Feature matching. Considered one of the most efficient ways to do image search. A number of features are extracted from an image, in a way that guarantees the same features will be recognized again even it is rotated/scaled/skewed. The features extracted this way can be matched against other image feature sets. Another image that has a high proportion of the features in the first one is most probably depicting the same object/scene.

    There are a number of OpenCV tutorials/samples on this, and a nice video here. A whole OpenCV module (features2d) is dedicated to it.
    Downsides: It may be slow. It is not perfect.

And here is a great answer on this topic: http://stackoverflow.com/questions/23931/what-algorithm-to-compare-two-images

[cross-posted from SO]