pg has asked for the wisdom of the Perl Monks concerning the following question:
For a project I am working on, I need to figure out the outline (boundary) of each subject on a photo. One way to do this is, for each pixel, to calculate the difference between its color and the color of surrounding pixels. (Assume the picture is reasonably clear, I am not interested in background noise at this point.)
The first thing I tried was to calculate the difference base on RGB:
$diff = abs($r1 - $r2) + abs($g1 - $g2) + abs($b1 - $b2);
Or I can do something like:
$diff = ($r1 - $r2) ** 2 + ($g1 - $g2) ** 2 + ($b1 - $b2) ** 2; (or I can make this more std like)
Whether to use abs() or **2 does not seem to be important at this point.
At this point, I compare each point with all 8 surrounding pixels, and pick the largest difference as the difference between this pixel and its surrounding. (obviously I can compare with more surrounding pixels, or give different weight to pixels base on their distance to this pixel.)
This actually works for me to a level.
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.
Again this worked to a level.
There must be more alternative ways, and I am interested in hearing them and trying them out, and see what the best way is, or best ways are. Thanks.
|
|---|