Page 2 of 2

Re: Centering Annotations within a Square/Rect.

Posted: 2009-06-01T23:35:44-07:00
by anthony
don wrote:Hi Anthony,

I see what you mean. With pixel.fcmp you can specify a pixel via the x/y and then see if it is whatever color(or nears the "fuzz" margin if specified). I can write a routine in my perl script that will pass the x/y on to a ruby script which performs the pixel.fcmp, and then returns true or false appropriately. Perl will keep querying the ruby script until it knows the borders of the north, south, east, and west points from the initial pixel that was specified. Then it will calculate the center pixel and size of each shape.
In perl the function to get a single pixel is... Get()

For example

Code: Select all

#!/usr/bin/perl
#
# You can grab and set pixels in PerlMagick, using methods like this.
#
use strict;
use Image::Magick;

# read image
my $im=Image::Magick->new();
$im->Read('logo:');

# get a single pixel
print "Skin Color = ", $im->Get('pixel[400,200]'), "\n";

# Or set a single pixel
$im->Set('pixel[0,0]'=>'0,0,0,0');
$im->Set('pixel[1,0]'=>'green');
$im->Set('pixel[2,0]'=>'rgb(255,0,255)');

# display the result (no save)
$im->Display();
The color values are from 0 to QuantiumRange whcih is dependant on the Quality of the IM
As such the first 'Set()' will also be in that same range, and thus is IM dependant.
The other two 'Set()' examples are quality independent.

I just happened to have this script squirrelled away.

An alternative is also shown in "pixel_fx.pl" script that should be installed in the docs area with PerlMagick.

Re: Centering Annotations within a Square/Rect.

Posted: 2009-06-02T05:54:46-07:00
by don
Hi Anthony and fmw42,

Thank you very much for the help. I misunderstood what Get() and GetPixel() did. I thought it was somewhat of a 'crop' for just the one pixel, but now everything makes perfect sense.

Everything is working great and now I can finally finish this script!

Thanks again for the help you guys provided.

Don