Skip to content

Dithering algorithms

Sweetcorn supports two main types of dithering algorithms: threshold maps and error diffusion.

This page includes examples of all the built-in dithering algorithms accompanied by a demonstration image dithered by the algorithm:

Threshold maps apply a fixed pattern to the image to determine which pixels should be turned on or off. These algorithms are faster to compute than error diffusion algorithms. They can produce noticeable repeating patterns in the output image.

Sweetcorn provides the following threshold map algorithms:

  • threshold
  • bayer-2
  • bayer-4
  • bayer-8
  • bayer-16
  • dot-4
  • dot-6
  • dot-diagonal-6
  • dot-8
  • dot-diagonal-8
  • dot-diagonal-10
  • dot-diagonal-16
  • dot-horizontal-6
  • dot-vertical-6
  • dot-vertical-5x3
  • dot-horizontal-3x5
  • blue-noise
  • white-noise

Error diffusion algorithms work by spreading the quantization error of a pixel to its neighboring pixels. This can result in a softer, less structured dithering effect, but it is more expensive, computing multiple values for each pixel of an image. Because of how errors are propagated, diffusion algorithms can also create artifacts in some images.

Sweetcorn provides the following error diffusion algorithms:

  • simple-diffusion
  • floyd-steinberg
  • false-floyd-steinberg
  • jarvis-judice-ninke
  • stucki
  • burkes
  • atkinson
  • pigeon
  • sierra
  • sierra-two-row
  • sierra-lite

It’s up to you!

Choose an algorithm you like visually. Often the best choice depends on your specific image and taste, but here are a few rules of thumb:

  • For speed, choose a threshold map algorithm.
  • blue-noise dithering is a good general-purpose choice.
  • The bayer-8 and bayer-16 algorithms dither using a recognisable retro pattern.
  • The floyd-steinberg algorithm is one of the most widely used error diffusion algorithms and is quite efficient.
  • The atkinson algorithm was first used on Apple computers in the 1980s, so also has a retro feel.
  • There are no wrong answers — have fun and choose one you like!