Page 1 of 2

Ordered dithering with a set amount of colors?

Posted: 2017-02-25T04:30:15-07:00
by plshelpx_x
I'm aware that I can use "+dither -colors x" and get an image with x colors that is as close to the original image's colors as possible. But I can't, for example, use "-ordered-dither o8x8 -colors x" and achieve the same effects. It appears to me that "-ordered-dither" use 'posterized' color maps, and does not take account in the original image's palette, and while I can change the posterize level, I can't create an ordered dither that picks colors based on the current image contents.

If there's any way to achieve my goal please tell me, that would be extremely helpful.

*Edit: On that note, can I also ask why "-quantize transparent" doesn't work anymore? And how can I replicate its effect using a different set of commands?

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T12:25:20-07:00
by fmw42
plshelpx_x wrote: 2017-02-25T04:30:15-07:00 *Edit: On that note, can I also ask why "-quantize transparent" doesn't work anymore? And how can I replicate its effect using a different set of commands?
I posted a bug report on this.

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T12:52:45-07:00
by plshelpx_x
That's great to hear! I was hoping for a work around for the time being, however.

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T12:56:03-07:00
by fmw42
Does this do what you want? Example from Anthony's pages on Usage.

Code: Select all

convert alpha_gradient.png -alpha off +dither -colors 15 -alpha on alpha_colors_15qt.tif

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T13:03:56-07:00
by plshelpx_x
No unfortunately. The "-alpha on" at the end doesn't seem to do anything, but thanks for trying!

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T13:10:43-07:00
by fmw42
try this

Unix syntax

Code: Select all

convert alpha_gradient.png \
\( -clone 0 -alpha extract \) \
\( -clone 0 -alpha off +dither -colors 15 \) \
-delete 0 +swap -alpha off -compose copy_opacity -composite \
alpha_colors_15qt.png
Windows syntax

Code: Select all

convert alpha_gradient.png ^
( -clone 0 -alpha extract ) ^
( -clone 0 -alpha off +dither -colors 15 ) ^
-delete 0 +swap -alpha off -compose copy_opacity -composite ^
alpha_colors_15qt.png

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T13:14:17-07:00
by fmw42
Or this (Unix syntax)

Code: Select all

convert alpha_gradient.png -write mpr:img +delete \
\( mpr:img -alpha off +dither -colors 15 \) \
\( mpr:img -alpha extract \) \
-alpha off -compose copy_opacity -composite \
alpha_colors_15qt.png
For Windows change the line ending \ to ^ and replace \( ... \) with ( ... )

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T13:22:49-07:00
by plshelpx_x
That does the trick! Thank you!
Please tell me dithering is still something that's being worked on, though. I understand it's very niche but it was what brought me to IM and I've since found IM to be extremely useful!

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T14:18:13-07:00
by snibgo
plshelpx_x wrote:It appears to me that "-ordered-dither" use 'posterized' color maps, ...
That is correct. Each channel is treated separately. The output channel value is one of a number of levels, according to the threshold map and the (x,y) coordinate. The code in OrderedPosterizeImageChannel() is fairly simple, merely calculating the output value.

I can't see how an ordered dither would work with a pre-built palette of colours, such as the N "best" colours.

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T14:26:03-07:00
by plshelpx_x
That is a huge bummer. But I guess it's just me being ignorant of how it works internally.

If there is even a slightest chance of "an ordered dither with a pre-built palette of colours" being realized, do you have any suggestions of how it might be done?

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T15:05:19-07:00
by snibgo
Well, I don't know what the output would be. I don't even know how the ordered dither map might be specified.

Dither maps are currently specified (in thresholds.xml) as levels, ie each pixel in the map has a one-dimensional threshold, a single number. This is applied to each channel in turn.

I can't see how those one-dimensional levels might apply to palette of colours that are each three-dimensional.

Perhaps you can describe exactly what you want, or something.

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T15:18:41-07:00
by fmw42
I do not know if this is meaningful, but you could do the ordered dither, then -remap with fixed set of colors. Or the other way around?

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T19:09:27-07:00
by snibgo
There are many possibilities. For example, ordered dither, and remap either to a small a "-colors N" selection or the unique colours from the input image. Windows BAT syntax:

Input: toes.jpg
Image

Code: Select all

%IM%convert ^
  toes.jpg ^
  ( +clone +dither -colors 5 -unique-colors ^
    +write mpr:MAP +delete ^
  ) ^
  -ordered-dither o8x8,3 -remap mpr:MAP ^
  orddith1.jpg
orddith1.jpg:
Image

Code: Select all

%IM%convert ^
  toes.jpg ^
  ( +clone +dither -unique-colors ^
    +write mpr:MAP +delete ^
  ) ^
  -ordered-dither o8x8,3 -remap mpr:MAP ^
  orddith2.jpg
orddith2.jpg:
Image

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T20:33:41-07:00
by plshelpx_x
snibgo wrote: 2017-02-25T15:05:19-07:00 Perhaps you can describe exactly what you want, or something.
I do not know what I want now, after realizing it's been math all along and not some black magic that turns colors into a fun looking dots pattern. I just thought -dither and -ordered-dither are similar at the core and are only different in executions, like -dither none and -dither Riemersma, but turns out they are different beasts altogether.
fmw42 wrote: 2017-02-25T15:18:41-07:00 I do not know if this is meaningful, but you could do the ordered dither, then -remap with fixed set of colors. Or the other way around?
But -remap basically means -dither Riemersma -remap, right? And -ordered-dither means -ordered-dither -posterize 2 (unless the posterize level is specified otherwise). So by using them in conjunction with one another I'm dithering twice, or changing the existing colors with a different set, which shouldn't give me a satisfactory result.

I guess what I want is the math behind -dither, but executed like an -ordered-dither? But I can't imagine it'd be able to work now that I've been explained by snibgo that it just does not roll that way.

Re: Ordered dithering with a set amount of colors?

Posted: 2017-02-25T21:10:21-07:00
by fmw42
-remap can use -dither none, so that it adds no new dithering. Thus do something like snibgo suggested but use remap to limit the number of colors to those in the remap colortable image

see http://www.imagemagick.org/Usage/quantize/#remap