Kexin Xu
Kexin Xu

Reputation: 701

how to compare similarity between two color images?

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,

Upvotes: 6

Views: 6954

Answers (1)

Slater Victoroff
Slater Victoroff

Reputation: 21934

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.

Upvotes: 1

Related Questions