GetPixel failing

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
magiotrope
Posts: 11
Joined: 2012-03-19T06:05:50-07:00
Authentication code: 8675308

GetPixel failing

Post by magiotrope » 2012-04-30T03:09:10-07:00

I'm really puzzled

the "identify" command returns " JPEG 205x154 205x154+0+0 8-bit DirectClass 48KiB 0.000u 0:00.000" on the image, and it is a color photo I can see with lots of multicolored flowers.

when I read it into PerlMagick and iterate over every pixel, like this...

Code: Select all

for(my $i=1; $i<=$width; $i++) {
    for(my $j=1; $j<=$height; $j++) {
        my @rgb=$image->GetPixel($i,$j);
        $colors{join(',', @rgb)}++;
    }
}

print "\n unique colors : \n";

foreach $k (keys %colors) {
    print "\n $k : ", $colors{$k};
}
I get:
unique colors :
0.141176470588235,0.152941176470588,0.211764705882353 : 31570

for a black & white tiff I get only "1,1,1" (white)

What am I doing wrong?
thanks

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GetPixel failing

Post by anthony » 2012-05-10T23:59:37-07:00

The color values are normalized. That is they are floating point numbers in a 0 to 1 range. That is all.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply