Idea for a new dt module - Posterize

You can “get to the bottom” of it by reading the manual or just playing with the modules :person_shrugging:

1 Like

Various blend modes would help you achieve a lot of these effects.

While strictly speaking it is not equivalent to transforming in some given space different from linear RGB, given that it is an artistic transformation that may not matter much.

That said, some users may find automated posterization algorithms (take a color space, divide it to n bins, do the binning) inflexible. Emphasizing various features would require some tweaking, so doing it manually might be the best option. It is not that tedious, and one can use presets as a starting point.

@Tamas_Papp , hi, yes I’m sure you can do a lot of pleasing stuff with blending, my impression is it’s powerful when you really understand what the various modes can do to a picture. But the directness and simplicity of posterization is something else; albeit just another tool. And of course it is inflexible in the sense it’s doing what it says on the tin, dividing something continuous into discrete values. (Though the way I described it originally, above, contains quite a lot of flexibility within posterization itself). For the foreseeable, I can see presets in Tone Curve could be useful, but this module only works on certain spaces/channels, e.g. working on an individual channel is only possible in Lab. The seaside example I posted above uses Lab in Tone Curve.

@anon41087856 , is it feasible to extend Tone Curve to other spaces and channels for creative purposes? E.g. draw a hue curve mapping degrees to degrees. E.g. saturation curve.

Precisely. Darktable is powerful because it gives you a (relatively) small number of generic, composable tools, from which you can build flexible solutions.

If feasible, I think it is better to have tool that provides posterization as a special case, instead of a dedicated module. Eg what used to be a vibrance module is now part of color balance RGB, instead of vignetting you should just use exposure with a mask, tone equalizer contains the old zone system as a special case, etc.

Can we please stop hastily jumping on implementation specifics and focus on the high-level goal in terms of expected image results ? Because, yes, we can also hack Microsoft Excel into doing SQL database, but being able to do it does not imply it’s reasonable, nor sane, nor the best option.

Tone curve is not suitable for unbounded HDR signal and certainly not for hue manipulation since hue is an angle and, as far as angles are concerned, 0°=360°, so no 2D curve in (x, y) cartesian space will allow to enforce that periodic boundary condition.

Now, what is it that you want to achieve ?

2 Likes

I’ll try to define some goals/requirements tonight.

1 Like

Here is what I’ve produced -
Posterize Reqs V5.pdf (14.3 MB)

It’s called “posterize” because historically, posters were printed with a very limited number of colors (at least before Jules Chéret).

So “posterizing” usually maps colors (in whatever color space) to a small number of output colors. Ideally the mapping is monotone according to some metric, and also selects the “closest” color in some space.

Thus, the way I would design a posterizing algorithm is

  1. select the number N of output colors, and then generate an initial choice for the user based on some quick heuristic, eg grid-based clustering,
  2. allow the user to adjust these colors c_i, i = 1, \dots, N (eg with the color picker),
  3. allow the user to pick the distance metric d (Euclidean, etc)

Then for each pixel with color x, map to y such that

y = \arg\min_i d(c_i, x)

This would provide a

  1. a simple interface,
  2. fast mapping and an initial choice,
  3. lot of artistic freedom, especially with the already available blend modes and masks.
1 Like

@Tamas_Papp , hi, thanks for the comments.
Overall I’d say your design is pretty much in line with what I have in the PDF re. Hue.

I don’t want to pursue posterization based on any historical way of printing etc., rather let it be a modern tool based on quantisation.

Your post is a bit mathematical! - I’d say leave the calcs to the dev!

It’s not just about colour in my opinion - brightness is very much part of this - pls see section 1 of the PDF. And saturation manipulation has a lot to offer I think.

Your item 1 is my R110. Item 2 is R160. I suggested the output could be the most anticlockwise colour (R130), however your suggestion to generate it with a “quick heuristic” is good, I’ll probably put that in the PDF.

At the end you mention artistic freedom with blend modes and masks. If I understand ok, these two are part of dt “infrastructure”, so if posterize got implemented as a new module, these would presumably be available.

My suggestion has no proposal for the actual calculation, it is just notation.

Basically, my proposal is:

  1. select a bunch of colors, allowing the user to modify them,
  2. map each color to the closest.

That’s all.

I don’t think so (sorry if I misunderstood something in yours). What I am proposing is to find the nearest point according to some metric in the whole color space, not quantization along some channel of a color space (which is how I understand your proposal).

Yes, you would get them automatically.

This seems like a very valid way of working; you already have a colour scheme in mind, and now you want to posterize to those colours. I think the PDF supports that. If 3 colours say, then set 3 regions and set up the 3 output hues you want. Now adjust the region boundaries until you get the optimum effect. You could automatically map each pixel to the nearest, but maybe it’s better to have the flexibility to adjust the boundaries yourself. E.g. green foliage, separating fairly close hues.

Oops, I’ve accidentally omitted that from the PDF. I am proposing individual channels, as I’ve said above. Certainly individual RGB channel quantisation, for maximum flexibility and creativity. Then I think it’s all covered except for “a” and “b” in Lab, and perhaps they are a bit weird for posterizing individually.

Revised PDF with changes highlighted -
Posterize Reqs V6.pdf (14.3 MB)

A feature that some of us use when “posterizing” (ie reducing a roughly infinite continuous range of colours to a small discrete number of sample colours) is dithering, which diffuses the error at indvidual pixels, creating a result that appears closer to the input.

No dithering:
t_no_dith

With dithering:
t_dith

Interesting. I’ve come across dithering when truncating the bit depth of samples in an audio stream, I think you add a random bit off the end just before truncating.
I was thinking how this might apply to posterize, where as I see it, the core of it is seeing if a value is > A and < B and if so, calling the value C, i.e. (A, B) is a region with output C. I suppose a small random value could be added/subtracted to the value before comparing and that would soften the transition. I suggested some smoothing in my original post to take the sharp corners off the staircase, that might be an alternative.
You mention a result that’s closer to the input - but perhaps the extra detail is not desirable for posterize?, I’m not sure either way.
I had a quick search and as you probably know, dithering is a whole topic of its own, here’s an article -

Perhaps there should be a dithering module in dt !

Thanks for the link. In my view, any software that has a colour-reduction process should include an option for dithering, because dithering can reveal detail that would otherwise be removed.

In my example above, which reduces to five colours in CIELab space, a shadow lies on the boundary between the two largest toes. The “no-dither” version removes the shadow because one of the five colours is the closest to all the pixels in the toe, including the shadow. In the dither version, the software recognises that one pixel has become too light, so it diffuses the error to other pixels, darkening them, which makes some dark enough for the closest of the five colours to be a darker colour.

Adding a random positive or negative value to each pixel before finding the closest of the five colours is a form of dithering, but not error-diffusion dithering.

I offer no opinion about whether whether darktable should include a colour-reduction module. But if it does, I suggest that it should include option(s) for dithering.

There already is : dithering

1 random (+ a dampening option) and 5 floyd-steinberg based presets to choose from.

I’m not at all able to determine if this module and its options is any good, though. It does seem that floyd-steinberg is rather good if I follow the link you supplied.

1 Like

Thanks @Jade_NL , I hadn’t noticed it :face_with_hand_over_mouth:
Random with 10dB damping is quite nice -


It doesn’t seem to do the graphics/arty stuff though.

And that led me to this -

Good news! - work has been done on posterization - see here

My quick test of the new option. I took a random image to try.

It required some tweaking with exposure, filmic contrast, and CC four way to find tune the cutoff point