Calculating the Euclidean distance between two pixels taking in to account the RGB values

post removed

Answers

  • The second one would give a more meaningful measure when considering the distance between two colours.

    In the first measure the ED between
    [255, 0, 0] -> [128, 127,0] (bright red -> dark yellow)
    would have the same result as
    [0, 255, 0] -> [0, 0, 255] (bright green -> bright blue)

    If fact the ED (using the first formula) for both examples would be 0 (zero) which makes no sense at all.

  • you can use dist() for this, dist(r1, g1, b1, r2, g2, b2);

    https://processing.org/reference/dist_.html

  • edited January 2018

    As suggested by koogs, dist() is the proper way to do it as it is based in your second formula: ED=sqrt(sq(TargetRed-TestRed)+sq(TargetBlue-TestBlue)+sq(TargetGreen-TestGreen));

    The first formula can be interpret as

    Color difference=dist(0,0,0,r1,g1,b1) - dist(0,0,0,r2,g2,b2)

    If we think in 2D, the first formula gives you the radius of each color wrt the black color (0,0,0) and then you calculate the difference of those radii. This has applications in some cases but I do not think it is what you are going after.

    Kf

  • Not sure that second thing is correct...

    Sq (r + g + b) != Sq(r) + sq(g) + sq(b)

    The first is as per original post, the second is dist (0, 0, 0, r, g, b)

  • But, yes, it doesn't have much use

  • You are right @koogs, my mistake. The sqrt was enclosing the whole thing so half of my comment was simply wrong. So the first formula does not make much sense... RGB components should be treated as vectorial components. The root of the difference of the sum of the vectorial components is not proper for this calculation. In fact, I don't think it provides any meaningful information...

    Kf

Sign In or Register to comment.