Ask Your Question
1

image comparison

asked 2013-03-05 04:26:40 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

I am trying to set up a database of images that can be used to compare to a current image (So if the current image is equal, or almost equal to the one being compared it'll give a match)

However to start this project off I want to just compare 2 images using OpenCV 2.4.0 to see how the process works.

Does anyone know how I might compare say image1.jpg and image2.jpg to see how closely related to each other they are? So basically if I was to compare image1.jpg and image1.jpg the relationship should be 100%, but comparing 2 different images might give me quite a close relationship.

I hope that makes some sense!!!

Thanks,

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-03-05 08:01:49 -0500

sammy gravatar image

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]

edit flag offensive delete link more

Comments

i have tried histogram matching its good but its giving same values for diff images...dnt knw how to solve please help..

thaha gravatar imagethaha ( 2013-03-06 04:18:30 -0500 )edit

I have outlined two other methods. Please make sure you read the whole post before asking new questions

sammy gravatar imagesammy ( 2013-03-06 12:51:01 -0500 )edit

The posts and suggestions on the stackoverflow page you linked (the second link) are really awful. A lot of thoughts from different users which are way to vague and without further directions... The devil is in the details, a beginner will not benefit from the suggestions there.

SR gravatar imageSR ( 2013-03-07 17:55:12 -0500 )edit
1

answered 2013-03-05 06:25:16 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

you can use a histogram comparison: http://docs.opencv.org/doc/tutorials/imgproc/histograms/histogram_comparison/histogram_comparison.html

or PSNR/MSSIM: http://docs.opencv.org/doc/tutorials/highgui/video-input-psnr-ssim/video-input-psnr-ssim.html

or you can detect keypoints from both images, compare them and count the number of "good" matches, if the number is high enough it is probably a match

edit flag offensive delete link more

Comments

Hi after detecting an object from video using a spefic color, i want to recognize this object from images, so i use compare histogram but it gives me double d = 1.0 for all images ? then i try to use detect feature (ORB,FAST,SIFT) then i count the good matching and retrieve the image who had the biggest length of good_matching but it return me the false image.

Marwen Z gravatar imageMarwen Z ( 2013-04-16 04:46:09 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-03-05 04:26:40 -0500

Seen: 8,270 times

Last updated: Mar 05 '13