6

two image side by side (please ignore the red line in between

I want to compare how close these two images are (red in similar area), but I can't go pixel by pixel because their color locations are not exactly the same. Anyone know what would be a good approach here?

Thanks,

Slater Victoroff
  • 21,376
  • 21
  • 85
  • 144
Kexin Xu
  • 691
  • 3
  • 10
  • 20
  • may be using OpenCV library look this tutorial http://www.pyimagesearch.com/2014/09/15/python-compare-two-images/ – efirvida Jun 26 '15 at 20:43
  • Why the locations are not the same? Would downsampling before comparing work well? Would registering the images before comparing allow pixel-by-pixel comparison? Please specify more details about your problem. – fferri Jun 26 '15 at 20:44
  • I started from there, but the two metrics are all based on pixel by pixel comparison. For me, I need some tolerance of similar but not exactly same location. – Kexin Xu Jun 26 '15 at 20:45
  • and using histogram comparations? – efirvida Jun 26 '15 at 20:49
  • so I get two images from two screenshots of the same area of a map from two providers, the underlying map are exactly the same, but the color for the same road may not have exactly same location. Not sure if it helps to define the problem here. – Kexin Xu Jun 26 '15 at 20:57

1 Answers1

1

I personally would advise using the indico image features API. Basically you pass in the image you're dealing with and get back a set of features that represent higher-level morphological-structures within that image.

If you compute cosine-similarity on top of those features you'll get a more intuitive similarity metric.

There's a great github link showing how to do exactly this with a front-end slapped on if that's what you're looking for here: https://github.com/IndicoDataSolutions/imagesimilarity

The code itself is pretty straightforward though:

from indicoio import image_features
from scipy import spatial

features_1 = image_features(<path_to_image>, <api_key>)
features_2 = image_features(<path_to_image>, <api_key>)
similarity = 1 - spatial.distance.cosine(dataSetI, dataSetII)  # This is what you want

The full docs are here

Full disclosure: I am the CEO of indico, so I'm biased, but I really do think it would help in this case.

Slater Victoroff
  • 21,376
  • 21
  • 85
  • 144
  • i am interested in trying it out but when I run image_features with array of image created by imread, it said invalid API key. I thought API key is only optional, do you know what's wrong here? – Kexin Xu Jun 29 '15 at 22:39
  • @KexinXu Sorry for that, the API key is not optional. Basically it allows us to debug problems much more effectively when they arise, so we've started requiring them. – Slater Victoroff Jun 29 '15 at 23:03