Color reduction bug with dithering

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Orphis

Color reduction bug with dithering

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Color reduction bug with dithering

Post by magick »

Use
  • convert orig.png +dither -colors 256 orig256.png
Orphis

Re: Color reduction bug with dithering

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color reduction bug with dithering

Post 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
Orphis

Re: Color reduction bug with dithering

Post 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...
Orphis

Re: Color reduction bug with dithering

Post 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...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color reduction bug with dithering

Post by fmw42 »

try

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