Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I measure the similarity between two images? [closed]

I would like to compare a screenshot of one application (could be a Web page) with a previously taken screenshot to determine whether the application is displaying itself correctly. I don't want an exact match comparison, because the aspect could be slightly different (in the case of a Web app, depending on the browser, some element could be at a slightly different location). It should give a measure of how similar are the screenshots.

Is there a library / tool that already does that? How would you implement it?

like image 1000
Antoine Aubry Avatar asked Aug 25 '08 12:08

Antoine Aubry


People also ask

How do you find the similarity between two objects?

Common Properties of Similarity Measuress(p, q) = 1 (or maximum similarity) only if p = q, s(p, q) = s(q, p) for all p and q, where s(p, q) is the similarity between data objects, p and q.

Which method is used to measure the similarity?

The Sørensen–Dice distance is a statistical metric used to measure the similarity between sets of data. It is defined as two times the size of the intersection of P and Q, divided by the sum of elements in each data set P and Q.

How do you find the similarity measure between two sets?

Typically, the Jaccard similarity coefficient (or index) is used to compare the similarity between two sets. For two sets, A and B , the Jaccard index is defined to be the ratio of the size of their intersection and the size of their union: J(A,B) = (A ∩ B) / (A ∪ B)

What is similarity measure in image processing?

These measure provide a quantitative measure of the degree of match between two images, or image patches, A and B. Image similarity measures play an important role in many image fusion algorithms and applications including retrieval, classification, change detection, quality evaluation and registration.


2 Answers

This depends entirely on how smart you want the algorithm to be.

For instance, here are some issues:

  • cropped images vs. an uncropped image
  • images with a text added vs. another without
  • mirrored images

The easiest and simplest algorithm I've seen for this is just to do the following steps to each image:

  1. scale to something small, like 64x64 or 32x32, disregard aspect ratio, use a combining scaling algorithm instead of nearest pixel
  2. scale the color ranges so that the darkest is black and lightest is white
  3. rotate and flip the image so that the lighest color is top left, and then top-right is next darker, bottom-left is next darker (as far as possible of course)

Edit A combining scaling algorithm is one that when scaling 10 pixels down to one will do it using a function that takes the color of all those 10 pixels and combines them into one. Can be done with algorithms like averaging, mean-value, or more complex ones like bicubic splines.

Then calculate the mean distance pixel-by-pixel between the two images.

To look up a possible match in a database, store the pixel colors as individual columns in the database, index a bunch of them (but not all, unless you use a very small image), and do a query that uses a range for each pixel value, ie. every image where the pixel in the small image is between -5 and +5 of the image you want to look up.

This is easy to implement, and fairly fast to run, but of course won't handle most advanced differences. For that you need much more advanced algorithms.

like image 115
Lasse V. Karlsen Avatar answered Sep 25 '22 11:09

Lasse V. Karlsen


The 'classic' way of measuring this is to break the image up into some canonical number of sections (say a 10x10 grid) and then computing a histogram of RGB values inside of each cell and compare corresponding histograms. This type of algorithm is preferred because of both its simplicity and it's invariance to scaling and (small!) translation.

like image 30
Louis Brandy Avatar answered Sep 24 '22 11:09

Louis Brandy