Page 1 of 1

MagickQuantizeImage behaviour, feature or bug?

Posted: 2015-01-03T17:06:25-07:00
by Danack
When you call MagickQuantizeImage with the maximum number of colors equal to or larger than the number of pixels in the image, and using the gray color-space, the image remains unchanged as a color image.

This seems to only happen when calling ImageMagick through C code - I was unable to replicate the problem with the same image through the command line convert utility.

A user of PHP Imagick reported this issue. They expected the image to be changed to gray colorspace, but it's not entirely obvious what the correct behaviour should be to me.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <wand/MagickWand.h>
    

int main(int argc,char **argv) {
	MagickWand *magick_wand;
	MagickBooleanType status;

	MagickWandGenesis();
	magick_wand = NewMagickWand();

	//This is a color image
	status = MagickReadImage(magick_wand, "./Biter_500.jpg");

	MagickScaleImage(magick_wand, 16, 16);

	MagickQuantizeImage(
		magick_wand,
		//Changing to 255 makes the image change to grayscale
		256,
		GRAYColorspace,
		0,
		0,
		0
	);

	status = MagickWriteImages(magick_wand, "./67258.jpg", MagickTrue);
	MagickWandTerminus();
 
    return(0);
}


Re: MagickQuantizeImage behaviour, feature or bug?

Posted: 2015-01-04T13:31:51-07:00
by dlemstra
The code currently does not change the colorspace when the number of requested colors is more than the number of colors in the image. But we think that it is correct to assume that the colorspace will be changed. We added a patch in ImageMagick 6.9.0-4 Beta, available by sometime tomorrow.