Edge detection is not a trivial task. Just google for edge detection and see the many varied techniques. Instead of doing this yourself, why aren't you delegating out to ImageMagick or Gimp (both have edge-detection filters)? You get the advantage of having adjustable parameters so you can tune things for your data. You will still probably have to get the locations of the edges into Perl by looking at the pixels by hand, but it's much easier from the output of the edge-detection algorithm -- the result will be grayscale and the edges will correspond to very clear jumps in intensity that are easy to notice.

If you're hell-bent on doing this by hand the way you've suggested, I'd look to see how programs like Gimp calculate deltas between pixels. For instance, Gimp's Selective Gaussian Blur will blur pixels only within a certain delta "difference" and it seems to do a good job. From the source code, it's not clear how this is calculated, but it probably relies on Gimp's internal colorspace. Maybe there is an Gimp IRC channel you could consult to get pointers to the math they use.

In any case, just using luminosity (as in your last example) won't find many types of boundaries in between solid colors. The two 3-dimensional RGB metrics you use are probably better (and probably not too different from each other).

blokhead


In reply to Re: the difference between two colors, and how to describe a color by blokhead
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.