Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the MagickWand equivalent of the "-colors" option?

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!

like image 537
Troy J. Farrell Avatar asked Apr 12 '11 23:04

Troy J. Farrell


1 Answers

Use treedepth=8, measure_error=1. See the documentation for details.

You might also consider using the YIQ colorspace as suggested here.

like image 160
Old Pro Avatar answered Sep 22 '22 06:09

Old Pro