Page 1 of 1

Re: Dithering works not with posterize

Posted: 2012-11-12T11:59:25-07:00
by fmw42
Try putting -dither xxxx before -posterize.

Re: Dithering works not with posterize

Posted: 2012-11-14T07:14:46-07:00
by Petari
Folks, I really want this to be solved.

ImageMagick 6.8.0-4
OS: Windows XP

Command:
convert 1056.bmp -dither Riemersma -posterize 16 o.png
Dither does nothing.

While with:
convert 1056.bmp -dither Riemersma -colors 256 o.png
dithering works.

And it works for me under Linux on my second PC. Even works if put dither after posterize in command line. But I want to use it from Windows too - and guess that I'm not the only one .

Re: Dithering works not with posterize

Posted: 2012-11-14T08:08:21-07:00
by glennrp
Even

Code: Select all

convert logo: -posterize 16 o.png
does not work. The result has many more than 16 colors (the input has 255 colors and the output has 164)

Code: Select all

convert logo: -dither Riemersma -colors 16 o.png
works (output has 16 colors which is probably what you wanted).

Re: Dithering works not with posterize

Posted: 2012-11-14T09:08:40-07:00
by snibgo
Posterize "n" doesn't reduce the image to "n" colours. I think it does the same as Gimp (see http://docs.gimp.org/2.8/en/gimp-tool-posterize.html), yielding 2^n colours.

Re: Dithering works not with posterize

Posted: 2012-11-14T09:23:29-07:00
by Petari
glennrp wrote:Even

Code: Select all

convert logo: -posterize 16 o.png
does not work. The result has many more than 16 colors (the input has 255 colors and the output has 164)

Code: Select all

convert logo: -dither Riemersma -colors 16 o.png
works (output has 16 colors which is probably what you wanted).
Argument by posterize is number of color levels per channel - so by color images it is 16 power 3 = 4096 .

Re: Dithering works not with posterize

Posted: 2012-11-14T12:26:04-07:00
by glennrp
Argument by posterize is number of color levels per channel - so by color images it is 16 power 3 = 4096
Oh, OK. That wasn't obvious from the ImageMagick documentation; I'll fix that. It is clear in the comments in magick/quantize.c though, which also seem to indicate that dithering is always on for Posterize, but as you observed, dithering seems to have no effect.

Re: Dithering works not with posterize

Posted: 2012-12-06T23:24:31-07:00
by anthony
posterize used to be dithered. But that changed in one release over a year ago. I complained at the time. but to no avail.

Re: Dithering works not with posterize

Posted: 2012-12-07T12:11:35-07:00
by magick
Dithering occurs if the number of levels cubed exceed the colormap limits of ImageMagick (256 colors for Q8 or 65535 colors for Q16). For example, -posterize 7 dithers for the Q8 version of ImageMagick because 7*7*7 is 343 which exceeds the 256 color limit. Otherwise it does not make sense to dither because the number of levels can be represented by the image (e.g. -posterize 6 is 216 colors, there is no errors so dithering is meaningless).

Re: Dithering works not with posterize

Posted: 2012-12-09T19:30:06-07:00
by anthony
But it can be useful to posterize dither with just two colors! And that was the old behaviour (according to the dither setting).

Re: Dithering works not with posterize

Posted: 2013-03-21T04:31:34-07:00
by markshep
magick wrote:Dithering occurs if the number of levels cubed exceed the colormap limits of ImageMagick (256 colors for Q8 or 65535 colors for Q16). For example, -posterize 7 dithers for the Q8 version of ImageMagick because 7*7*7 is 343 which exceeds the 256 color limit. Otherwise it does not make sense to dither because the number of levels can be represented by the image (e.g. -posterize 6 is 216 colors, there is no errors so dithering is meaningless).
For me it makes sense to always allow dithering to be used with posterization. The way I'm using posterize is to reduce an image's colorspace from 32 bits to 16 bits (RGBA8888 -> RGBA4444). This is to prepare textures in an asset pipeline for an iOS game so as to halve the memory used. I'd like to enable error dithering to make the textures look as much like the original as possible, but that doesn't seem to be possible, i.e. when using "-posterize 16 -dither Riemersma" or "-posterize 16 -dither FloydSteinberg" the dither option is ignored.

However I can use ordered dithering and posterize together, for example "-ordered-dither checks,16,16,16,16" works. So there seems to be a slight inconsistency here in that ordered dithering works with posterization, but not error dithering. I've managed to work round this by creating an RGBA4444 colormap (using "-channel" and "-fx" options), then using "-remap" and "-dither" together. So I have achieved what I want, but have had to jump through an extra hoop to get there.

Also I was wondering if there any plans to make the "-posterize" command take per-channel arguments like "-ordered-dither" can? I'm also doing some conversions to RGB565 colorspace for which this would be useful. Currently I have to use the colormap and "-remap" method just to do a straight conversion to that colorspace without dithering.

Re: Dithering works not with posterize

Posted: 2013-03-21T10:18:29-07:00
by snibgo
I've managed to work round this by creating an RGBA4444 colormap (using "-channel" and "-fx" options), then using "-remap" and "-dither" together.
Another way to get posterize to dither is to use unique-colors, then remap:

Code: Select all

convert in.png ^
  ( +clone -posterize 3 -unique-colors -write temp.mpr +delete ) ^
  -remap temp.mpr ^
  post.png
It wastes resources, but it works.

Re: Dithering works not with posterize

Posted: 2013-03-21T17:21:14-07:00
by anthony
You do not need the unique-colors in the colormap for dithering, that will happen automatically when it reads a colormap image. However it does make the save image a lot smaller and makes it obvious the image is a colormap and not a real image.

Also the above method also may not generate all the colors a posterizaion many need to generate a good dither. The input image may not for example cover 'blues', or extremes, like white, red, black.

The real problem with color reduction (quantization) is they generally don't generate 'outliner' colors, that an e-dither needs to prevent dither errors drifting beyond the images normal color ranges, and becomming extreme. This is the cause of dither 'speckling', when a extra (very different) color is also introduced. (a color way beyond the images normal color range).
For examples see... E-Dither Pixel Speckling
http://www.imagemagick.org/Usage/quanti ... er_speckle

As such if you do not have a complete posterization colormap (and even if you do) you can have problems with speckling, due to a lack of good 'outliner' colors just on the edge of the color zones the image needs.

As an alternative, you can also generate power of two posterization colormaps, by directly using "HALD:" images, as color maps. For example a HALD:4 is the same colors as a 16x16x16 colorcube. The IM Hald image coder was added long afetr I wrote the dither examples section, and probably should be added to that section.


PS: There has been some discussion about using srgb colormaps, converted to linrar RGB space for the disther, and then the result back to sRGB. I have no experimented with this, but it seems like a fairly good idea.


PPS: I am wanting to actually separate the 'quantization colormap' generation aspect from the 'dithering' aspect of the -color operator.
Especially as this will allow for 'user adjustments' of the colormap between the two steps, such as spreading the colors to generate 'outliners', and for ways of determining 'common colors' of an image.

NOTE: just because the quantization step generated N colors, does not mean dither actually uses all N colors! This aspect is another problem with the dithering step.

And Finally (I promise).... Dithering with fewer colors can provide opportunities or other dithering methods that is not possible when lots of colors are involved (more than 256). For example... ordered dithers using user provided colormaps, (which requires generating 'psuedo-colors' to do the ordered dither threshold maps. This should make ordered dithers even better!
See... Arbitrary-palette positional dithering algorithm
http://bisqwit.iki.fi/story/howto/dither/jy/

Re: Dithering works not with posterize

Posted: 2013-03-21T18:43:02-07:00
by snibgo
anthony wrote:You do not need the unique-colors in the colormap for dithering, ...
True. I generally create one colormap for a large number of images, and a smaller map saves a lot of time re-reading it.
anthony wrote:PS: There has been some discussion about using srgb colormaps, converted to linrar RGB space for the disther, and then the result back to sRGB. I have no experimented with this, but it seems like a fairly good idea.
For photos and video, I've experimented with posterisation etc, with and without dithering, in various colorspaces: RGB, sRGB, CIELab, OHTA, HSL and so on. I don't consistently prefer one colorspace over another; it all depends on the image. Modifying the image very slightly can make a big difference to which colorspace I prefer.

However, I have found a close correlation between my preferred colorspace and the RMSE difference between the original and posterized version. The closer the images are (i.e. the lower RMSE value), the more I prefer the colorspace.

Some examples on http://www.youtube.com/watch?feature=pl ... YwhjiUsVsM

Re: Dithering works not with posterize

Posted: 2013-03-21T19:21:05-07:00
by anthony
very interesting video... could use some description and maybe sub-titles defining the effect being using in each scene.