Then I started to think whether RGB is indeed the right way to describe color for what I am doing, so the next thing I tried is to use
my $ll = 0.212671 * $r + 0.715160 * $g + 0.072169 * $b;
as the "color", and calculate the difference.
That seems like a way to calculate the graylevel of a color, as being used in color TV transmission (at least for PAL), and which is responsible for the fact that a B&W TV can show a color TV signal rather well (that as an aside, for the curious). I'm not exactly sure on the weights, I thought the value for blue was closer to 0.11. And indeed, looking at 3.3.3. Color Models in Video - YUV Color Model, I see:
Y = 0.299R + 0.587G + 0.114B

But why are you throwing away the other 2 values? You could use the whole of YUV, where Y is your above gray value, and U and V are the two other color components. Surely, a change in color tint is as important as a change in brightness.

And then there is HSV, another somewhat similar color value triplet.


In reply to Re: the difference between two colors, and how to describe a color by bart
in thread the difference between two colors, and how to describe a color by pg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.