Ordered dithering with a set amount of colors?
-
- Posts: 7
- Joined: 2017-02-12T08:57:40-07:00
- Authentication code: 1151
Ordered dithering with a set amount of colors?
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?
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?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Ordered dithering with a set amount of colors?
I posted a bug report on this.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?
-
- Posts: 7
- Joined: 2017-02-12T08:57:40-07:00
- Authentication code: 1151
Re: Ordered dithering with a set amount of colors?
That's great to hear! I was hoping for a work around for the time being, however.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Ordered dithering with a set amount of colors?
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
-
- Posts: 7
- Joined: 2017-02-12T08:57:40-07:00
- Authentication code: 1151
Re: Ordered dithering with a set amount of colors?
No unfortunately. The "-alpha on" at the end doesn't seem to do anything, but thanks for trying!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Ordered dithering with a set amount of colors?
try this
Unix syntax
Windows syntax
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Ordered dithering with a set amount of colors?
Or this (Unix syntax)
For Windows change the line ending \ to ^ and replace \( ... \) with ( ... )
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
-
- Posts: 7
- Joined: 2017-02-12T08:57:40-07:00
- Authentication code: 1151
Re: Ordered dithering with a set amount of colors?
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!
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!
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Ordered dithering with a set amount of colors?
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.plshelpx_x wrote:It appears to me that "-ordered-dither" use 'posterized' color maps, ...
I can't see how an ordered dither would work with a pre-built palette of colours, such as the N "best" colours.
snibgo's IM pages: im.snibgo.com
-
- Posts: 7
- Joined: 2017-02-12T08:57:40-07:00
- Authentication code: 1151
Re: Ordered dithering with a set amount of colors?
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?
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?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Ordered dithering with a set amount of colors?
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.
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.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Ordered dithering with a set amount of colors?
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?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Ordered dithering with a set amount of colors?
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
orddith1.jpg:
orddith2.jpg:
Input: toes.jpg
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
Code: Select all
%IM%convert ^
toes.jpg ^
( +clone +dither -unique-colors ^
+write mpr:MAP +delete ^
) ^
-ordered-dither o8x8,3 -remap mpr:MAP ^
orddith2.jpg
snibgo's IM pages: im.snibgo.com
-
- Posts: 7
- Joined: 2017-02-12T08:57:40-07:00
- Authentication code: 1151
Re: Ordered dithering with a set amount of colors?
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Ordered dithering with a set amount of colors?
-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
see http://www.imagemagick.org/Usage/quantize/#remap