Skip to main content
GameDev.net gamedev.net
🔒 Locked

Compare two images

Started by proglore Jul 7, 2006 at 4:36 AM 6 replies 1k views
Original Post
proglore
proglore
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]
JY
JY
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.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
Trap
Trap
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.
frob
frob
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.

Good luck on your project.
StarikKalachnikov
StarikKalachnikov
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

Google discussion (opencv answer):
Link

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
Next time I give my advice, I'll buy some bubblegum so I won't your kick ass!
frob
frob
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?
proglore
proglore
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.



Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.