Computing Image Similarity based on Color Distribution

Image Similarity based on Color Palette Distribution

I am trying to compute similarity between two images based on their color palette distribution, let's say I have two sets of key value pairs as follows,

Img1: {'Brown': 14, 'White': 13, 'Black': 40, 'Gray': 31}

Img2: {'Pink': 82, 'Brown': 8, 'White': 7}

Where the numbers denote the % of that color present in the image. What would be the best way to compute similarity on a scale of 0-100 between the two images?

• Jul 28, 2014 at 8:50
• This is a fairly active field of research. One approach defines a family of hashing functions and computes a locality-sensitive hash of the images. There are many, many variations on this idea.
– Sycorax
Aug 9, 2016 at 18:25
• You can check some of image similarity metrics I used here: github.com/alexeygrigorev/avito-duplicates-kaggle Sep 21, 2016 at 19:22

Ya, pretty much agree with everyone here. The first thing you're going to want to do is transform to a perceptually uniform color space; for me, either HSL or LAB have worked the best, depending on the application.

From there, creating a color histogram for each image and comparing the histograms is probably the best way to go. Here's an interesting post on different methods for doing this: http://www.pyimagesearch.com/2014/07/14/3-ways-compare-histograms-using-opencv-python/

You're probably best off treating the color palettes as ordinary numerical vectors and using any one of the popular distance metrics for vector spaces, i.e. euclidean distance, cosine distance or mahalanobis distance.

The only reason I wouldn't do this is if there is some way you want to incorporate the similarity of non-identical colors in your comparison. For example should the distance between {'Pink' : 100} and {'Purple' : 100} be different than the distance between {'Black' : 100} and {'White' : 100}. If so, then you might want to look at different color spaces for representing your vectors but it depends on what you're trying to achieve.

The problem's a bit more complicated than you think. If you want to compute the perceived similarity when viewed, you're going to have to aren't going to be able to just work with pixel values as they are contained in an image file. The first thing you'll have to do is a gamma adjustment (http://www.poynton.com/GammaFAQ.html), and although I'm a bit rusty on this stuff, I think you'll need to then convert to a perceptually uniform color space.

Hopefully someone on this forum will know more.

Thanks a lot for the insights, I have decided to start with weighted Jaccard similarity first as defined below.

Then maybe I will look into some histogram comparing approaches as described here, https://stackoverflow.com/questions/6499491/comparing-two-histograms