# Compare two images

This topic is 4248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, This is the problem: I have a list of images and I must find which of these images match another image or is the most similar. I tried to find a library to compare two images without results. Maybe one of you can help me. Thanks. [Edited by - proglore on July 7, 2006 5:14:22 AM]

##### Share on other sites
I seem to remember something called xdelta which does binary comparison of files. You could get the output from that to find out which files are most/least different.

xdelta is open source though so you would of course have to open your entire program.

A possibly slow option is to subtract one image from another. The one that results in an image closest to black would be the closest match.

##### Share on other sites
Use self-organizing maps, such as Kohonen maps. An overview / example of the process can be found here: http://www.generation5.org/content/2004/aiSomPic.asp
When implemented correctly, this approach usually provides excellent results.

There's plenty of material online, documenting the properties and use of SOMs, so look that stuff up in your favourite search engine...

##### Share on other sites
You need to consider a lot of other transformations to get reasonably close to the usual meaning of "similar" wrt images.

Rotation, translation, cropping, scaling result in similar images most of the time, but a simple delta always classifies them as very different.

##### Share on other sites
The various definitions of "similar" images can mean different things.

Finding the similarity of images is a very hard problem for computers, with a lot of active research. Right now, that research makes a good masters or Ph.D. thesis.

As a simple example, imagine the Cornell Box (good example) of a square room, a light on the ceiling, and two objects -- each can be a box or a sphere.

Would you consider the image 'similar' if the lighting levels are different? Are they similar if the color is different? Are they similar if an object is moved a little bit? Are they similar if the scene is rotated? Are they similar if the rendering algorithms are changed so they produce different inter-object lighting effects or adding soft shadows? Are they similar if the sphere is made out of different materials, such as refractive glass, reflective steel, or a matte texture? Are they similar if the image has been processed by a simple convolution filter? Are they similar if they are rendered as a pen-and-ink drawing?

More complicated definitions of 'similar' can involve the incredibly difficult problems of object recognition, feature tracking, feature extraction, and image registration, just to name a few.

##### Share on other sites
Hi, I'd recommend the opensource OpenCV library, which stands for Computer Vision.

It's a full-blown library which I used for a facial recognition app.

Site:
OpenCV

I admit it's probably to much for your needs, but it's capable of comparing two images using the following code:

CvArr* result = cvCreateImage(cvSize(1, 1), IPL_DEPTH_32F, 1); cvMatchTemplate(img, img, result, CV_TM_CCORR_NORMED); fprintf(stderr,"\n result: %lf \n", cvGetReal1D(result, 0));

I guess you should have no difficulty adjusting it for multiple images.

Greetings,

Starik

##### Share on other sites
Quote:
 cvMatchTemplate(...CV_TM_CCORR_NORMED);

Nope. It would fail for the examples I gave above, unless you could take steps to identify a suitable template region. It would also fail when the template region (even though it is color-normalized) and all parts of the compared image are substantially different in terms of rendered elements.

What might work with intel's library would be an attempt to back-project in order to regenerate the object, but that goes back to an object recognition system.

Without a precise definition of "similar", everything we mention is a wild guess anyway.

Besides, what does "most similar" to a reference image really mean? If we changed a matte black sphere to each of a horizontally striped texture, a vertically striped texture, and a diagonally striped texture, which is most similar?

##### Share on other sites
Thanks to all for the replies.

I only know that the program must compare a image with a list of images and find which have the same shape but I don't know the complexity of the shape, only the next week I will have more information about the problem. Before the meeting I'd like to study the argument and with your advice I have a good point to start.

Sorry for my poor English. I must also study English.

Thanks again.
Lorenzo.