Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Comparison Techniques with Java

I'm looking for several methods to compare two images to see how similar they are. Currently I plan to have percentages as the 'similarity index' end-result. My program outline is something like this:

  1. User selects 2 images to compare.
  2. With a button, the images are compared using several different methods.
  3. At the end, each method will have a percentage next to it indicating how similar the images are based on that method.

I've done a lot of reading lately and some of the stuff I've read seems to be incredibly complex and advanced and not for someone like me with only about a year's worth of Java experience. So far I've read about:

  • The Fourier Transform - im finding this rather confusing to implement in Java, but apparently the Java Advanced Imaging API has a class for it. Though I'm not sure how to convert the output to an actual result

  • SIFT algorithm - seems incredibly complex

  • Histograms - probably the easiest out of all mentioned so far

  • Pixel grabbing - seems viable but if theres a considerable amount of variation between the two images it doesn't look like it's going to produce any sort of accurate result. I might be wrong?

I also have the idea of pre-processing an image using a Sobel filter first, then comparing it. Problem is the actual comparing part.

So yeah I'm looking to see if anyone has ideas for comparing images in Java. Hoping that there are people here that have done similar projects before. I just want to get some input on viable comparison techniques that arent too hard to implement in Java.

Thanks in advance

like image 353
Flynn Avatar asked Dec 01 '10 19:12

Flynn


2 Answers

  • Fourier Transform - This can be used to efficiently can compute the cross-correlation, which will tell you how to align the two images and how similar they are, when they are optimally aligned.
  • Sift descriptors - These can be used to compare local features. They are often used for correspondence analysis and object recognition. (See also SURF)
  • Histograms - The normalized cross-correlation often yields good results for comparing images on a global level. But since you are just comparing color distributions you could end up declaring an outdoor scene with lots of snow as similar to an indoor scene with lots of white wallpaper...
  • Pixel grabbing - No idea what this is...

You can get a good overview from this paper. Another field you might to look into is content based image retrieval (CBIR).

Sorry for not being Java specific. HTH.

like image 72
bjoernz Avatar answered Sep 28 '22 11:09

bjoernz


As a better alternative to simple pixel grabbing, try SSIM. It does require that your images are essentially of the same object from the same angle, however. It's useful if you're comparing images that have been compressed with different algorithms, for example (e.g. JPEG vs JPEG2000). Also, it's a fairly simple approach that you should be able to implement reasonably quickly to see some results.

I don't know of a Java implementation, but there's a C++ implementation using OpenCV. You could try to re-use that (through something like javacv) or just write it from scratch. The algorithm itself isn't that complicated anyway, so you should be able to implement it directly.

like image 44
mpenkov Avatar answered Sep 28 '22 13:09

mpenkov