Problem with Quantize function

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
fockjef

Problem with Quantize function

Post by fockjef »

I have found a bug when reducing the number of colors in an image and converting it to gray. The following code illustrates the problem:

Code: Select all

use strict;
use Image::Magick;

print "PERL: $^V\nIM: ", Image::Magick->new->Get('version'), "\n\n";

my $img = Image::Magick->new;
$img->Read('logo:');
$img->Quantize(colorspace=>'gray',colors=>10);
for( my $i = 0; $i < 10; $i++ ){
	print $i, "\t", $img->Get("colormap[$i]"),"\n";
}
Output:
PERL: v5.10.0
IM: ImageMagick 6.4.0 04/23/08 Q16 http://www.imagemagick.org

0 10536,10536,10536,0
1 20362,20362,20362,0
2 41849,41849,41849,0
3 65247,65247,65247,0
4 4179,5,267,256
5 20362,20362,20362,0
6 41849,41849,41849,0
7 65247,65247,65247,0
8 10536,10536,10536,0
9 20362,20362,20362,0
The colormap index 4 is not a grayscale color and if I try to set that particular index I get a fatal error. If I reduce the colors first and then convert to gray everything works as expected. However, converting to gray first and then reducing the colors still yields a bad colormap.
Post Reply