Page 1 of 1

png dither colors, odd artifacts?

Posted: 2012-11-12T03:32:46-07:00
by terry
First off, ImageMagick is awesome. Thanks to the people out there that put it together. Great work!

I'm trying to convert a png32 file down to 256 colours/png8, preserve transparency/alpha, and dither BUT I keep on getting some weird artifacts OR a black background.
The closest I could get to having 256 colours and dithering is example #7 - by separating the alpha channel and by using -ordered-dither on it beforehand. It looks kinda wonky @_@.
I'm relatively new to ImageMagick. So, I apologize if I'm doing something obviously stupid or if what I'm trying to do is just not possible...

I'm running...
WAMP 2.2
PHP 5.3
Win 7x64
ImageMagick 6.8.0 Q16

Here's some various sample code with img output results...

1.Original File
Image

2.

Code: Select all

exec('convert old.png -alpha off -dither FloydSteinberg -alpha on -colors 255 new.png');
Image

3.

Code: Select all

exec('convert old.png -alpha off -dither FloydSteinberg -colors 255 -alpha on new.png');
Image

4.

Code: Select all

exec('convert old.png -colors 255 -dither FloydSteinberg new.png');
Image

5.

Code: Select all

exec('convert old.png -dither FloydSteinberg -colors 255 new.png');
Image

6.

Code: Select all

exec('convert old.png -quantize transparent -dither floydSteinberg -colors 255 new.png');
Image

7.

Code: Select all

exec('convert old.png ( -channel A -ordered-dither 8x8  ) -dither FloydSteinberg -colors 255 new.png');
Image

8.hi-res - similiar to #2, #5
Image

Re: png dither colors, odd artifacts?

Posted: 2012-11-12T09:05:00-07:00
by glennrp
I verified the behavior you observed with IM-6.8.0-5, and also saw the same when I used txt as the output format, so this has nothing to do with PNG.
This doesn't look too bad to me:

Code: Select all

exec('convert old.png ( -channel A -threshold 60%  ) -dither FloydSteinberg -colors 255 new.png');
but that doesn't answer your question about the artifacts in the transparent area.

Re: png dither colors, odd artifacts?

Posted: 2012-11-12T12:16:03-07:00
by fmw42
Looks to me like alpha value is getting included in the dither to one of your selected number of colors unless you use -alpha off .... -alpha on

Re: png dither colors, odd artifacts?

Posted: 2012-11-12T19:28:10-07:00
by terry
Thanks Glen!
I appreciate the recommendation. It sucks that you could confirm the artifacts too, i was hoping that it was just me... Just in case it was just me I though I would post on the forum and perhaps resolve the issue but otherwise I'm not too worried. Would you know why this is happening?

Re: png dither colors, odd artifacts?

Posted: 2012-11-12T19:31:58-07:00
by terry
fmw42 i did tinker with -alpha off, -alpha on

#2

Code: Select all

exec('convert old.png -alpha off -dither FloydSteinberg -alpha on -colors 255 new.png');
#3

Code: Select all

exec('convert old.png -alpha off -dither FloydSteinberg -colors 255 -alpha on new.png');
Perhaps I implemented it in a incorrect way? Could you please elaborate, maybe with an example?

Re: png dither colors, odd artifacts?

Posted: 2012-11-12T19:39:51-07:00
by fmw42
This seems to work (better?).

imb convert original.png -alpha off -dither FloydSteinberg -colors 255 -alpha on PNG32:- | convert - PNG8:original_c255.png

Re: png dither colors, odd artifacts?

Posted: 2012-11-12T20:10:00-07:00
by terry
Cool, thanks fmw42. Your code gives similar results to Glen's recommendation.

Code: Select all

exec('convert old.png ( -channel A -threshold 60%  ) -dither FloydSteinberg -colors 255 new.png');
Both will suffice.

Also, just wanted to say that the ImageMagick team has done some really great work. Really appreciate what you guys have done!

Re: png dither colors, odd artifacts?

Posted: 2012-11-12T20:12:19-07:00
by fmw42
Glenn's code would appear to be more flexible as you have control over the threshold.

Re: png dither colors, odd artifacts?

Posted: 2012-12-17T18:05:42-07:00
by anthony
But are you actually getting png8 format output?

Note last I heard the quantization code generates 255 colors, but the dither code seems to ignore many of those colors and generate images with only about 64 colors. A color tree search problem.

As such some verification on exactly how many colors the final image is using should be looked at.

Dither in IM really needs a overhaul, especially to have it work better for <256 colors, using some new dithering techniques that is now available.

Actually can anyone see a point for dither with more than 256 colors. This was what the IM dither was designed to actually allow, and I think the reason why it is having problems.