There is an interesting article on this issue:
A new perception of a uniform color space with an appropriate criterion for color similarity for the content image and video of M. Sarifuddin and Rokia Missaui
You can easily find this using Google or, in particular, Google Scholar.
To summarize, some color spaces (e.g. RGB, HSV, Lab) and distance measurements (e.g. geometric mean and Euclidean distance) are better representations of human perception of color similarity than others. The document talks about a new color space that is better than the rest, but it also provides a good comparison of common existing color spaces and distance measures. Qualitatively *, it seems, the best measure for perceiving distance using commonly available color spaces is: HSV color space and cylindrical distance measure.
* At least as shown in Figure 15 in the reference article.
Cylindrical distance measure (in latex notation):
D_ {cyl} = \ sqrt {\ Delta V ^ {2} + S_1 ^ {2} + S_2 ^ {2} -2S_1S_2cos (\ Delta H)}
Also pay attention to some similar questions that address the same issue:
search for similar colors programmatically
The "distance" between colors in PHP
Finally, in Java there is an easy way to convert from RGB values to other color spaces:
ColorSpace.fromRGB
source share