0

When measuring color distance between two colors, there are plenty of methods. You can use the euclidean distance in the RGB space and you can do more sophisticated calculation such as the perceptual distance in the Lab space (deletE).

But I am asking if there exists any sort of distance that can be measured between a set of colors and another set of colors, which can be referred as palettes. In a first instance both sets could be of the same length, but ideally the set could contain any number of colors.

Eg.

set_1 = {(255, 0, 0), (200, 10, 10), (230, 20, 20)}
set_2 = {(255, 50, 50), (200, 50, 50)}
set_3 = {(0, 255, 0), (10, 255, 10)}

Intutively, the distance between set_1 and set_2 would be smaller than set_1 and set_3. But I do not know if any method exists to have a quantitive approach to this problem.

I have already tried measuring the distance of the main color of the palette, but I have not found a solution that takes into account all the colors from the sets.

adam
  • 94
  • 4
  • Technically speaking, how will you define if an approach is _"sophisticated"_ or not? What is the end goal you're trying to achieve by measuring this distance? – Abhinav Mathur Apr 05 '22 at 13:57
  • The end goal is that, having palette of colors as a query and a big set of other palettes, be able to sort them by distance, ranking the from the most similar to the most dissimilar. I will edit the "sophisticated" part since it is not very enlightning. – adam Apr 05 '22 at 14:03
  • There are many meaningful ways to define such a distance. But it's hard to suggest one if we don't know what properties you are after. Are you planning to apply this distance on a practical application? If so, what is the application and what are the properties you seek? – Berthur Apr 05 '22 at 14:57
  • I have a predefined dataset of color palettes (with varying number of colors per palette) and I would like to query a user-defined palette and retrieve the most similar-looking ones (in terms of human perception). It is a research project so I don't know which properties I am after yer, I would like to research for now. Could you reference some of these ways of defining that distance you mentioned? – adam Apr 05 '22 at 16:44

1 Answers1

0

It won't be trivial, even with palettes exactly the same size.

An approach would be to convert RGB colors to YUV (CIE94 would be even better...), then substract the second palette from the first to obtain a vector of distances.

Then, you can compute on this vector average value and the standard deviation: according to what you find, you will be able to say if palettes are "close" or "far" from each other.

This is already a lot of code to implement... But things become ugly with palettes of different sizes. How will you "extend" the shortest one to match the longest one's size?

A possibility could be to set a maximum palette size (let's say 256 colors), and to compute, for EACH compared palette, a 256-entries palettes computed as a regular and homogeneous gradient (compute it directly in YUV/CIE94, not in RGB).

You can then test the two extended palettes with the previous method. But you'll probably have a lot of false positives until you find correct parameters to "calibrate" your algorithm to expand palettes... Maybe go for even larger palettes (1024?) and shrink them with an "antialias" that will merge adjacent colors, once gradient is computed, to reduce rounding errors?

Wisblade
  • 1,483
  • 4
  • 13