Page 1 of 1

Color reduction bug with dithering

Posted: 2009-06-22T09:43:32-07:00
by Orphis
Hi,

I'm trying to use Imagemagick to convert some textures for some game to 256 colors automatically. So I've taken imagemagick for the job since I've heard lots of good things from it. Unfortunatly, I'm often hiting problems with it related to quality or non standard work I'm asking it to do (color reduction on a picture with semi transparent pixels). Okay, I can work with bad quality as long as the game runs now and I know the artists will do it later by hand with I hope better quality for certain pictures.

But the last problem I'm having is really weird and I guess it's worth a bug report.

I'm trying to convert this picture here
It contains semi transparent pixels, some fully transparent and represent two crappy arts of a background with progressively faded edges.

Running : "convert orig.png -colors 256 orig256.png" or "convert orig.png -dither riemersma -colors 256 orig256riemersma.png" gives me this
Running : "convert orig.png -dither floydSteinberg -colors 256 orig256floyd.png" gives this

Oddly, if I apply the "posterize 8" option, I get acceptable results. There are still little "white" holes in the picture as I often get with other converted pictures (I can send some samples later if you want for this).

I'm running ImageMagick 6.5.3-2 2009-06-01 Q16 OpenMP on Windows XP. I can upgrade to check the latest revision, but the changelog hasn't reported anything I suspect to be linked to this problem.

Best regards,

Orphis

Re: Color reduction bug with dithering

Posted: 2009-06-22T09:58:45-07:00
by magick
Use
  • convert orig.png +dither -colors 256 orig256.png

Re: Color reduction bug with dithering

Posted: 2009-06-22T10:13:23-07:00
by Orphis
This is what I've ended up using. But I'd like to have some dithering, I have lots of real complex backgrounds too.
Anyway, the above results aren't really what you intended doing or anywhere close what the algorithm the dithering method should do.

Re: Color reduction bug with dithering

Posted: 2009-06-22T10:21:36-07:00
by fmw42
try disabling the alpha, dither, then re-enable the alpha

convert orig.png -alpha off -colors 256 -alpha on orig256.png

convert orig.png -alpha off -dither floydSteinberg -colors 256 -alpha on orig256floyd.png

And if you don't want the alpha at the end, you can flatten the image:

convert orig.png -alpha off -colors 256 -alpha on -flatten orig256flat.png

Re: Color reduction bug with dithering

Posted: 2009-06-22T10:41:45-07:00
by Orphis
This is giving acceptable result with all the graphics : convert orig.png -alpha off -dither floydSteinberg -colors 256 -alpha on orig256floyd.png
Thanks a lot !

In any case, even with alpha on, it should not give such results...

Re: Color reduction bug with dithering

Posted: 2009-06-24T05:29:06-07:00
by Orphis
After some more checks, it appears that reenabling the alpha layer after reducing the color number is indeed still producing a 32bit picture with 256 colors for the RGB channels combined with a full alpha channel.

I need paletized images with alpha and thus it doesn't work well.

So I'm back to "convert ... +dither -colors 256 ..." which doesn't really do any dithering...

Re: Color reduction bug with dithering

Posted: 2009-06-24T07:53:51-07:00
by fmw42
try

convert orig.png -alpha off -dither floydSteinberg -colors 256 -alpha on -type palettematte orig256floyd.png