I need to select all pixels in a image that are similar in color to a given one.

My current approach is to get the hsv values for this pixel and calculate the distance to each pixel in the image being

distance = abs(ref.h-pix.h) + abs(ref.s-pix.s) + abs(ref.v-pix.v);

And select the pixels bellow certain distance.

Is there any other preferred method?

  • 1
    $\begingroup$ "Optimal" obviously demands you have a metric for goodness. So you probably want to define a measure for local and global "similarity" and use that. $\endgroup$ Mar 6, 2017 at 19:12
  • $\begingroup$ If you are interested in "colour" then you could apply the distance criterion to the RGB model directly. With the HSV, you can simply look at the H component to "guess" the colour and the S,V to judge if it is in the shadow or light areas of the image. $\endgroup$
    – A_A
    Mar 7, 2017 at 8:37

1 Answer 1


The Wikipedia page Color difference gives several formulas, the most advanced being CIEDE2000. They are all based on Euclidean distance $\Delta E$ (straight line distance) in the approximately perceptually uniform CIE Lab color space, with various corrections.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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