Java library to compare image similarity

JavaImageComparisonSimilarity

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

Just off the top of my head, OpenCV is a great image processing library, but it might be overkill if you just want to compare images. If that's the case, I'd go with ImageJ.

Someone already asked how to do this using OpenCV here.

I'd use C++ for this, but if you must use Java, there is a project which made a Java wrapper for OpenCV, here.

Solution 3 - Java

I used the class in this link to compare two product images, and the results were cool. It's not very hard to implement it just to be used for comparing two images, you just need to delete the lines of JAI and Swing and such. It resizes images to 300x300 and returns a difference value such as "1234". The maximum difference value is near "11041", it's stated in the link. Doing a division, you can simply get the percentage. If interested I can post the modified code here later.

The results were cool, but I still got "digital camera photos", detected to be similar to "TV photos". So, I used ImageJ to detect edges in the picture. Using the detect edges operation, ImageJ converts the image into a edge detected greyform image. Than I put the two edge-detected images in the same comparator and multiplied the both values. The results got even more accurate.

Getting the edge-detected form of the images

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionF.PView Question on Stackoverflow
Solution 1 - JavaG. BachView Answer on Stackoverflow
Solution 2 - Javadario_ramosView Answer on Stackoverflow
Solution 3 - Javaİsmet AlkanView Answer on Stackoverflow