To get a boundary, image processing folks use a technique called Sobel filtering. The basic idea is to create an isotropic version of a gradient. First, convolve each pixel with the matrices
Vertical Kernel: -1 -2 -1 0 0 0 +1 +2 +1 Horizontal kernel: -1 0 +1 -2 0 +2 -1 0 +1
Take the results of the two convolutions, square them and add them. If the result is greater than a user-determined threshold, set the pixel black, otherwise white.

This works for 1-D, e.g., grayscale images. For color images, decide what you want to be the boundary: Brightness? Hue? Saturation? Then segnemt according to that property, Just taking the 3-D RGB vector distance isn't the greatest idea, because humans don't differentiate colors according to that metric. All other things being the same, I'd probably try the grayscale (brightness) metric first.

Update: I concur with blokhead that there are many edge detection algorithms, none unviersally applicable. The Sobel algorithm is fairly good on a wide range of images, so is worth a try.

-Mark


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