Page 1 of 1

Color Quantization Not Reducing To Proper Amount

Posted: 2019-02-10T22:18:34-07:00
by P-Tux7
Hello, I use on this image:
Image
This code:

Code: Select all

magick convert ganondorfcolors.png -quantize XYZ +dither -colors 15 -posterize 15 ganondorfcolors2.png
This is meant to result in that it gets quantized to 15 colors, using no dither, and using XYZ colorspace as the basis for quantizing.
Here is the result:
Image
However, you can count that there are only 11 unique colors in this image. Did I do something wrong? Because if not, this seems like a bug since this image had 22 colors, so it should have been possible to reduce it to 15 colors.

Re: Color Quantization Not Reducing To Proper Amount

Posted: 2019-02-10T23:32:15-07:00
by fmw42
-colors will quantize to at most the number of colors you request. But it may be less. See https://imagemagick.org/script/command- ... php#colors

Re: Color Quantization Not Reducing To Proper Amount

Posted: 2019-02-11T00:39:34-07:00
by P-Tux7
fmw42 wrote: 2019-02-10T23:32:15-07:00 -colors will quantize to at most the number of colors you request. But it may be less. See https://imagemagick.org/script/command- ... php#colors
Ah, thank you. I guess a mod can move this to some better forum since this isn't a bug. Is there a way to get it to use that exact amount of colors for maximum detail within the quantized set of colors? I tried adding -treedepth 2 or -treedepth 8 to the command, but the result is not better.

Re: Color Quantization Not Reducing To Proper Amount

Posted: 2019-02-11T07:52:59-07:00
by snibgo
P-Tux7 wrote:Is there a way to get it to use that exact amount of colors for maximum detail within the quantized set of colors?
No.

You can script a loop to vary N in "-colors N", and find the actual number of unique colours. For example, "-colors 21" will return 13 unique colours, but "-colors 22" returns 22 colours.

Re: Color Quantization Not Reducing To Proper Amount

Posted: 2019-02-11T11:11:02-07:00
by fmw42
You can try a kmeans type solution with seed colors. I have one for bash unix shell script at my line below and user snibgo has one for Windows at his web site shown below his post.