Page 1 of 1

Color reduction doesn't work well with alpha PNGs

Posted: 2013-04-05T09:02:19-07:00
by jhuckaby
Consider this sample 32-bit alpha PNG image:
Image

When converted to 256 colors, ImageMagick 6.3 does a fantastic job:

Code: Select all

convert alpha-source.png -dither None -colors 256 alpha-256-im63.png
ImageMagick 6.3 Output: Image

However, the image looks considerably worse when I use ImageMagick 6.8:

Code: Select all

convert alpha-source.png -dither None -colors 256 alpha-256-im68.png
ImageMagick 6.8 Output: Image

As you can see, the IM 6.8 image has strange artifacts and what appear to be palette errors.

Here is another example from ImageMagick's own Quantize Page (http://www.imagemagick.org/Usage/quantize/):

Source Image: Image

Code: Select all

convert alpha_gradient.png -dither None -colors 256 alpha_gradient-256-im63.png
ImageMagick 6.3 Output: Image

Code: Select all

convert alpha_gradient.png -dither None -colors 256 alpha_gradient-256-im68.png
ImageMagick 6.8 Output: Image

As you can see, the ImageMagick 6.3 version looks considerably better.

Did something change in the ImageMagick color reduction algorithms?

I am using:

Version: ImageMagick 6.8.4-6 2013-04-04 Q8 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC
Delegates: bzlib freetype jng jpeg lcms png tiff xml zlib
OS: Linux 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux (64-bit CentOS 6.2)

- Joe

Re: Color reduction doesn't work well with alpha PNGs

Posted: 2013-04-05T12:30:46-07:00
by snibgo
Try ...

Code: Select all

"%IMG6846%convert" alpha-gradient.png  -quantize RGB -alpha off -dither None -colors 256 -alpha on a8.png
... which gives a similar result to that old IM version but (I would argue) even more fantastic.

Re: Color reduction doesn't work well with alpha PNGs

Posted: 2013-04-05T15:23:24-07:00
by jhuckaby
Hey snibgo,

Thanks! I did see that command-line trick in the ImageMagick Quantize docs, however, it produces a much larger file size:

Original 32-bit PNG: 10.6K
Converted 8-bit PNG: 5.4K
With the -alpha off -alpha on thing: 7.8K

I was hoping to keep the size down, but the quality up, like ImageMagick 6.3 does. Also, there is no way to do this in PerlMagick (no "alpha" option in the Quantize filter). Sigh.

Re: Color reduction doesn't work well with alpha PNGs

Posted: 2013-04-05T16:02:09-07:00
by snibgo
Sorry, I don't speak Perl.

I forgot to mention: I use Q16 IM, which will give different results to your Q8.

Re: Color reduction doesn't work well with alpha PNGs

Posted: 2013-04-05T16:06:50-07:00
by fmw42
jhuckaby wrote:Also, there is no way to do this in PerlMagick (no "alpha" option in the Quantize filter). Sigh.
I don't use Perlmagick either, but looking at the docs, see http://www.imagemagick.org/script/perl- ... -attribute

"alpha {On, Off, Opaque, Transparent, Copy, Extract, Set} control of and special operations involving the alpha/matte channel"

Re: Color reduction doesn't work well with alpha PNGs

Posted: 2013-04-05T16:14:17-07:00
by jhuckaby
Ah, thank you fmw42, I did not know that could be used with the 'Quantize' filter. I'll play around with it.

Re: Color reduction doesn't work well with alpha PNGs

Posted: 2013-04-05T16:35:43-07:00
by fmw42
It is a setting that you use before and/or after some processing to enable or disable the alpha channel. It is not specific to any one method.