What the hell even is dithering?
At it’s heart, dithering is a technique employ in CG to simulate a broader spectrum of colors within a limited palette. Esssentially, it approximates unavailable colors by strategically dispersing pixels from the existing palette. The human eye then finishes the job by blending these pixels and in process perceiving a richer, more continuous range of hues/values.
There are a bunch of different ways to do this. Some common ones include:
- Ordered Dithering: Uses a pre-defined pattern to decide where the dots go
- Error Diffusion Dithering: Spreads out the “error” from rounding a pixels color
to the available palette, making the overall image smoother
- Floyd-Steinberg: Distibutes error to neighbors using a fixed, weighted pattern
- Atkinson: Another version using a simplified error distribution.
- Riemersma: Aims for reduced grain through a more spread-out error diffusion.
- Blue Noise Dithering: A more naturalistic looking one
- Random Dithering: Just throw noise at the image, fuck it, we ball
Patterns make perfect
Ordered dithering is all about using a pre-defined pattern, called a threshold matrix, to decide how to dither your image. The most famous of those being the Bayer matrix, named after Bryce Bayer.
A 2x2
matrix looks like this:
And we can generate these recursively:
To dither a grayscale image, you compare each pixel’s value to the corresponding value in the Bayer matrix. If the pixel’s value is larger we make that pixel white, else black.
Sharing the load
Floyd-Steinberg is a type of error diffusion dithering. The basic idea is this: when you force a pixel to be, say, black what it should have been a dark gray, you’ve introduced an “error”. This alogirhtm takes that error and distributes it to neighboring pixels that haven’t been visited yet using a specific set of weight.
The standard weights look like this:
In grayscale images this is a simple thresholding operation.
This process happens sequentially, from top-left to bottom-right. Becvause the error is diffused, you tend to get a smoother, more organic-looking result than with ordered dithering, especially in subtly gradients.
Nat 20
You can always just throw some random noise to the problem. Is this useful to anyone? Who knows..
BEYOND
There’s a whole world of dithering out there. Tons of algorithms to explore (like Jarvis-Judice-Ninke, Atkinson, Blue Noise etc).
If you want to try some of them (how accurate some of the implementations are is debetable) on your own images, here’s a small demo.
Read more: