# image comparison with a database

Im not yet an Open CV user, Ive been using Matlab but Ive kept an eye in OpenCV for a while already. That being said, I would like to know if its even possible to implement one idea I had for a pet project of mine, before delving deep into openCV and really learning the language.

My goal is to compare images (They`re going to have noise) with a database of images, and tell me if it finds a match. For instance:img1 img2

How would I even tell they're both similar? Are there algorithms I can implement to tell me that?

I suppose I should use some sort of noise reduction/edge detection first (I already tried some and had success with edge detection, actually). So, assuming I have a decent edge detection, how could I compare them?

edit retag close merge delete

Sort by » oldest newest most voted

I assume your are looking to get similar images. Hereby, I would not go into edge-detection for image similarities. Imho the typical approach would be a kind of "Bag (visual) of Words (BoW)" approach. It works as follows:

1. You compute features at keypoints of your image-database.
2. Cluster them ( i.e. build your vocabulary )
3. Compute for each image a histogram of features ( i.e. compute nearest match to the vocabulary for each descriptor and count them ). This is your descriptor for an image
4. The original approach would be learning based: Assign labels to your images and train a classifier with your labels and your descriptors. However, in your case this step could be simplified by just taking the nearest neighbors. So you'd match the descriptors of step 3 and take let's say the 10 nearest image-descriptors.

OpenCV provides a BoW class which basically does step 1-3 (you only need to chose which keypoint-detector and descriptor and matcher you need). If you are more interested why and how BoW works in detail, see for example http://people.csail.mit.edu/fergus/iccv2005/bagwords.html . If you google around you will probably also find examples for the complete realization with OpenCV.

Another approach which covers step 1-3 is to compute immediatly an image-descriptor without computing local features and cluster them. Maybe the GIST-Descriptor is worth looking into it: http://people.csail.mit.edu/torralba/code/spatialenvelope/ . Good luck!

more

Thanks a LOT, you actually gave me some hope with this message! I had almost given up already, a learning based approach is EXACTLY what I want. Both links you sent me are done in MatLab (Which I'm familiar with, so that's actually good!), that being said do you recommend simply continuing with Matlab or actually swtiching to OpenCV? for performance purposes, that is.

( 2013-03-07 07:41:39 -0500 )edit
2

That is a difficult question and depends on many factors: 1. The keypoint/descriptor/matchers/classifier you are chosing. Some may be definitly faster using OpenCV since many algorithms are parallelized. This brings me to point 2: The system you use or on which the software is intended to be used. Maybe youn could use algorithms from the GPU or OCL module which would give you a huge gain speed. 3. However all these things don't really matter if you can do your job in much faster time in matlab than coding it in a different language. Note: maybe the shift from Matlab to Python is less difficult than from Matlab to C++ and still is fast enough for your purpose, but think over it thoroughly.

( 2013-03-07 08:24:17 -0500 )edit

@simba1382 and @Guanta Did you implemented this by using bagofwords_classification.cpp from opencv version 2.4.x In case you did then plz help me in the changes that we are required to make in this .cpp files for proper working of code.. I am new to opencv and still trying sample code.

How and where to add the Feature detector,descriptor extractor, descriptor matcher ?? in that .cpp code

( 2013-04-27 11:38:43 -0500 )edit

@zits: No I have used the official OpenCV classes documented here: http://docs.opencv.org/modules/features2d/doc/object_categorization.html?highlight=bowtrainer#object-categorization and I can only recommend to use them.

The example in bagofwords_classification.cpp seems a little bit overloaded and configured for a specific dataset, however maybe you can adapt it to your needs. If you are experienced (or get more experienced), you can also try a more advanced module which was integrated recently: OpenFABMap, see here: http://docs.opencv.org/modules/contrib/doc/openfabmap.html?highlight=bowtrainer#openfabmap (note there exist also an example: opencv-dir/samples/cpp/fabmap_sample.cpp)

( 2013-04-27 18:00:26 -0500 )edit

Ok thanks a lot @Guanta

( 2013-04-28 04:27:30 -0500 )edit

more

If you don't want to train, then search for the nearest neighbors of each image descriptor, e.g. by BFMatcher.

( 2014-09-22 04:41:50 -0500 )edit

Official site

GitHub

Wiki

Documentation