2
$\begingroup$

I have two images/heatmaps (2d matrix) of identical size. I need to statistically compare the similarity between the two. With 'similarity', I mean that high and low values of one image appear in similar areas in the other image.

Does anyone have an idea on how to do this? (I am using Python.)

$\endgroup$
2
$\begingroup$

You are comparing distributions over a two-dimensional grid. A very common way to do this is the Earth mover's distance, also known as the Wasserstein metric. (You may need to normalize your images first.)

In looking for an implementation, you need to make sure it works with two dimensional data - many are restricted to one dimensional histograms. However, there seem to be multiple Python implementations you could use.

$\endgroup$
  • $\begingroup$ A number by itself is not useful. Are two objects whose height differs by 1cm similarly high? If the objects are skyscrapers or humans, then yes. If the objects are bees or caterpillars, then no. Look at EMDs between similar and dissimilar images that are similar to yours, to get an idea of what EMD values indicate similarity and which ones don't in your context. $\endgroup$ – Stephan Kolassa Apr 23 at 12:45
  • $\begingroup$ Thanks for your reply. I computed the wasserstein metric for the two images which results in a very small number (i.e. 0.0005). So according to this metric, the images are similar. However, when I look at the two different images, they do not look similar. Can you tell me why this is? I will upload the images below. $\endgroup$ – LVDW Apr 23 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.