MagickQuantizeImage behaviour, feature or bug?

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
Danack
Posts: 73
Joined: 2013-10-14T10:00:25-07:00
Authentication code: 6789

MagickQuantizeImage behaviour, feature or bug?

Post 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);
}

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: MagickQuantizeImage behaviour, feature or bug?

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply