Color Quantization Not Reducing To Proper Amount

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
P-Tux7
Posts: 2
Joined: 2019-02-10T22:14:19-07:00
Authentication code: 1152

Color Quantization Not Reducing To Proper Amount

Post by P-Tux7 » 2019-02-10T22:18:34-07:00

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.

User avatar
fmw42
Posts: 24937
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color Quantization Not Reducing To Proper Amount

Post by fmw42 » 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

P-Tux7
Posts: 2
Joined: 2019-02-10T22:14:19-07:00
Authentication code: 1152

Re: Color Quantization Not Reducing To Proper Amount

Post by P-Tux7 » 2019-02-11T00:39:34-07:00

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.

snibgo
Posts: 11597
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Color Quantization Not Reducing To Proper Amount

Post by snibgo » 2019-02-11T07:52:59-07:00

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.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 24937
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color Quantization Not Reducing To Proper Amount

Post by fmw42 » 2019-02-11T11:11:02-07:00

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.

Post Reply