2

I am looking for a library that can measure the degree of similarity between 2 pictures.

If using hash, the picture must be exactly the same. Means that it only produce the result either TRUE or False. What I am looking for is something that can give metrics value of picture similarity.

Any command line tool, library for doing that? Any language is acceptable, preferably open source.

karikari
  • 6,359
  • 15
  • 61
  • 78

1 Answers1

3

The best approaches are SSIM and PSNR, they are used by, for example, x264 (I'm sure you've heard about it, but it's an open-source H.264 encoder that's used by guys like Google Video).

Here's a CLI video coparison tool for linux that implements both.

Here's a (image/video processing) language that you may be interested in.

Oh wait... ImageMagick does the job too and I'd go for it because it's an awesome tool.

By the way this question has multiple duplicates (1, 2, 3, 4, 5, 6, 7).

Community
  • 1
  • 1
Camilo Martin
  • 35,841
  • 20
  • 107
  • 152
  • I have tried the ImageMagick before. But a similar image with longer size will be flag as not similar. am looking for a tool that can give me metrics value, a degree of similarness. – karikari Dec 14 '10 at 00:55
  • how to compare images of different sizes? – karikari Dec 14 '10 at 01:58
  • The idea is not to compare a image of too big a size, but convert both to thumbnails! Think about it, if two images are equal, you can still see that visually on thumbnails (and it's faster to process these too). This is what many image comparison services do AFAIK. In order to know the right metric values (they're different for diffeent metrics, PSNR uses dBs) for your case, try with a few images. If you're looking for images that are supposed to be the same (even if they were heavily compressed) the similarity will be very high (as thumbnails). – Camilo Martin Dec 14 '10 at 02:52
  • does it means that, any pictures with different sizes can be thumbnail-ed into the same size and scale? – karikari Dec 17 '10 at 01:10
  • Yes, but of course if one is portrait-oriented and the other is landscape-oriented chances are they're not the same image anyway. But even if one of them was cropped a little or has a watermark still the similarity will be high enough to know they're probably the same image or a slight variation. Note that you could go a step further and apply [motion compensation](http://en.wikipedia.org/wiki/Motion_compensation) to be able to better match cropped or rotated images (if that's really necessary, but for most uses it isn't). – Camilo Martin Dec 17 '10 at 01:29
  • Basically the smaller the thumbnail the less sensible it is to small, unnecessary detail. So resizing both to something small like 32x32 could be enough to tell if they're similar but small enough as to discard noise and artifacts, plus it processes very fast that way. The idea is to find the sweet spot - the similarity value that gives the right results (i.e., a value that thresholded will either give the `true` or `false` you want). Try a bit and you'll find it. – Camilo Martin Dec 17 '10 at 01:36
  • To compare 2 pictures with different sizes try using [jpeg-compare](https://github.com/danielgtaylor/jpeg-archive#jpeg-compare) from jpeg-archive. `jpeg-compare --method fast` – Josh Dec 12 '14 at 02:53