Centering Annotations within a Square/Rect.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Centering Annotations within a Square/Rect.

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
don

Re: Centering Annotations within a Square/Rect.

Post 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
Post Reply