Java library to compare image similarity

F.P picture F.P · Dec 27, 2011 · Viewed 75.4k times · Source

I spent quite some time researching for a library that allows me to compare images to one another in Java.

I didn't really find anything useful, maybe my GoogleSearch-skill isn't high enough so I thought I'd ask you guys if you could point me into a direction of where I could find something like this.

Basically what I want to do is to compare two images with each other and get a value of how much the two are similar. Like a percentage or so.

I hope you guys have something I can use, I wouldn't know how to write something like that myself...

PS: It doesn't necessarily has to be in Java, that's just the environment my app will be running.

Answer

G. Bach picture G. Bach · Dec 27, 2011

You could take a look at two answers on SO itself: this one is about image comparison itself, offering links to stuff in C++ (if I read correctly) while this one offers links to broader approaches, one being in C.

I would suggest starting with the second link since there's links on that discussion that'll lead to implementation code of some relevant techniques which you might be able to "translate" into Java yourself.

That's the best my google skills could do, no Java though - sorry. I hope it's a good starting point!

EDIT: Here's someone with your problem who wrote his own comparison class in Java. I didn't read the source code though. He expressly states that he couldn't find Java libraries for that purpose either, so that's why he wrote it himself.

Oh, and this question on SO has probably the best links on this, all regarding Java libraries of image processing. Hopefully there's one amongst them that can compare images for similarity.

Ok, last edit: The Java Image Processing Cookbook shows a Java implementation of a basic algorithm to determine the difference between two pictures. It also has an email to contact the guy who wrote it as well as a host of references. No library though.

EDIT after reading your comment to your question: Unless you've already checked all of the above links, since what you want seems to be checking whether two images are equal, I would suggest starting with the Java Image Processing Cookbook (since that has an implementation of an algorithm in Java to check for equal images) and the last link to an SO question. Also, check PerceptualImageDiff and the source code of that project (C++); it sounds really nifty - it's apparently supposed to check whether two images look equal to the human visual system.