I have several images that I'm processing with ImageMagick. In this case, I'm converting an RGBA PNG into an indexed PNG. If I use the convert
tool, I have reasonable control over the number of colors in the indexed PNG:
$ convert infile.png -colors 128 outfile.png
$ identify outfile.png
outfile.png PNG 77x77 77x77+0+0 8-bit PseudoClass 91c 3.03KiB 0.000u 0:00.000
It seems to reduce the color count substantially (91 < 128) I am trying to do the same conversion with MagickWand's MagickQuantizeImage(wand, 128, RGBColorspace, tree_depth=1, 0, 0)
. The signature of the function is
MagickBooleanType MagickQuantizeImage(
MagickWand *wand,
const size_t number_colors,
ColorspaceType colorspace,
const size_t treedepth,
const MagickBooleanType dither,
const MagickBooleanType measure_error)
The end result is an image with too few colors (only 11!):
$ identify wandoutfile.png
wandoutfile.png PNG 77x77 77x77+0+0 8-bit PseudoClass 11c 1.31KiB 0.000u 0:00.000
Does anyone know how to accomplish a reduction of colors using MagickWand (without destroying the image in the process?)
Thanks!
Use treedepth=8, measure_error=1
. See the documentation for details.
You might also consider using the YIQ colorspace as suggested here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With