I read an example of using cosine distance in RGB space, and it pointed out that (eg.) dark red and light red have a cosine distance (CD) of zero because CD only gives you the angle between vectors and doesn't consider length. Fair enough. I wondered if a way to fix this was by making it a four dimensional problem by adding the vector length VL, calculated in the normal Euclidean way way.

But this seems to be cheating because the R,G,B components are independent of each other whereas the length component VL is clearly a function of R, G and B. In some sense I'm not adding new information (or am I?)

I can't help feeling this shouldn't work, but it seems to as far as I can tell. Am I mistaken?

This is not about Cosine Vs. Euclidean distance but what the implications are of adding the latter to the former.

(I'm starting to wonder if, as CD is blind to vector length VL, I'm simply making VL visible to it by explicitly adding it back in as an extra dimension. That said, VL is entirely a function of the other dimensions so something doesn't feel right).

  • 1
    $\begingroup$ I doubt the question is answerable on the information provided. How would you define whether this "works"? I don't see any requirements or metrics for evaluating whether it is satisfactory. P.S. Have you considered L2 distance? P.S. Are you familiar with perceptual distance and other colorspaces? Simple distance measures on RGB probably don't correspond very well to human perception of similarity of colors. $\endgroup$
    – D.W.
    May 20, 2022 at 7:04
  • $\begingroup$ RGB was just used as an example space. I've removed it from the heading, sorry for the confusion. As for whether it's answerable, I can't understand how you can't understand it, so I don't know how to clarify, sorry :-) (will look at L2 distance, never heard of it, ta - hang on, L2 is euclidean says wiki, which is used in my question??) $\endgroup$ May 20, 2022 at 7:11
  • $\begingroup$ You should only use cosine distance if you want to ignore the vector length. Ignoring the length is the point of it, not a problem that needs fixing. If you don't want that property then you should use a metric, such as Euclidean distance, that fits your objective better. What is your objective? $\endgroup$
    – benrg
    May 21, 2022 at 16:42
  • $\begingroup$ I've learnt some useful things here but I can't accept any answers because they aren't relevant to my question. It may not be answerable as-is. I guess my question was a poor one, as D.W. initially said, so that's on me. $\endgroup$ Jun 8, 2022 at 9:31

1 Answer 1


To compare colors, the cosine distance is interesting as it cancels the effect of light intensity (so yes, dark red and light red are both two reds).

If you don't want this effect, the Euclidean distance (in RGB space) is fine.

  • $\begingroup$ Thanks but my question is not about cosine vs euclidean but about the effect of augmenting the former with the latter. $\endgroup$ May 20, 2022 at 9:44
  • 1
    $\begingroup$ @user3779002: my answer goes in the way of "don't do that". $\endgroup$
    – user16034
    May 20, 2022 at 10:33
  • $\begingroup$ "don't do that" - quite probably, but WHY not? $\endgroup$ May 21, 2022 at 6:19
  • $\begingroup$ @user3779002: because Euclidean distance suffices and is better understood. $\endgroup$
    – user16034
    May 21, 2022 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.