FilterPictureA PictureEditor.com tool

Error diffusion versus ordered dither

Both families answer the same question and get incompatible answers. Knowing which artefact each is prone to is more useful than knowing which is better, because neither is.

The same question, two answers

You have a pixel that wants to be a mid-grey and a palette containing black and white. Whichever you choose, you are wrong by about half. The only question in dithering is what to do with that half.

Error diffusion passes it on. Round the pixel, measure how far off you were, and add fractions of that error to the neighbours you have not reached yet. The next pixel now wants to be slightly darker than it really is, so it rounds the other way, and over any patch the count of black and white comes out to exactly the grey you started with. Nothing is discarded, only moved.

Ordered dithering decides in advance. A small matrix of thresholds tiles across the whole picture, and each pixel is compared with whichever threshold it happens to land on. A mid-grey region falls above half the thresholds and below the other half, so it comes out as a regular checker whose density is right on average — but nothing is carried anywhere, and the pattern is entirely a property of position.

What follows from each answer
PropertyError diffusionOrdered
Average brightnessExactApproximate
PatternIrregular, never repeatsPerfectly regular, tiles
Depends on scan orderYes, entirelyNo
Can be computed in tilesNoYes
Characteristic artefactDiagonal worming on flat areasA visible grid
Cost per pixelHigher — neighbours must be updatedLower — one comparison

The three diffusion kernels, and why they differ

A diffusion kernel is a list of neighbours and the share of the error each one gets. All three on this site push error rightwards and downwards, because those are the pixels not yet visited; they differ in how far the error travels and how much of it survives the journey.

Floyd–Steinberg — four neighbours, all of the error

Seven sixteenths to the right, then three, five and one sixteenth to the row below. The weights sum to one, so nothing is created or lost, and the concentration on the immediate right keeps the pattern tight. It is the default here and the default nearly everywhere, because it is accurate and its grain is fine enough to read as tone rather than as texture.

Atkinson — six neighbours, three quarters of the error

An eighth each to six neighbours, reaching two pixels right and two rows down. Six eighths is not one: a quarter of every error is simply dropped. Judged as an implementation of error diffusion that is a defect, and judged as a look it is the entire appeal. Discarding error means contrast is not averaged away, so highlights run clean to paper and shadows close to solid instead of both filling with a scatter of opposite-coloured pixels. It is the reason early Macintosh images look the way they do.

Sierra — ten neighbours, all of the error

The widest spread of the three, reaching two pixels either side and two rows down, with the weights in thirty-seconds. Spreading the error further means no single neighbour is pushed hard, so the grain is smoother and more even than Floyd’s at the cost of more work per pixel. On large, gently-toned subjects — skin, sky, fog — it is usually the best-looking of the three.

All three scan in a serpentine here: alternate rows run right to left. That costs nothing, stays entirely deterministic, and stops the error from accumulating a direction, which is where most of the diagonal worming in a naive implementation comes from.

Where each one is ugly

This is the part most comparisons leave out, and it is the part that decides which one you should use.

Error diffusion is ugly on flat gradients and on hard graphics. A sky that changes by two levels across a thousand pixels gives the algorithm almost nothing to work with, and the tiny errors it is carrying organise themselves into travelling diagonal structures — the worms. Serpentine scanning and a larger palette both help, but on a genuinely smooth gradient something will always be visible. On flat graphics with hard edges the problem is different: error pushed off the edge of a shape lands on the background and stipples it, so a clean logo dithers with dirt around it.

Ordered dither is ugly on faces and on anything with fine detail. The matrix is the same everywhere regardless of what is underneath it, so it lays its grid across an eye exactly as it lays it across a wall, and features smaller than a couple of matrix tiles are simply overwritten by the pattern. It also cannot represent a value the matrix has no threshold for, which is why an 8×8 Bayer at a two-colour palette has sixty-four available densities and bands visibly when a subject needs more.

Pattern scale, which changes the argument

One control on this site cuts across the whole comparison: the dither can be computed on a reduced copy and enlarged back with no smoothing, so each decision covers a block of pixels rather than one. At a scale of three or four, the difference between the families becomes much more visible — the diffusion grain turns from texture into a scatter of distinct marks, and the Bayer grid turns from a fine screen into an unmistakable pattern.

It also changes which one is the better answer. At scale 1 on a photograph, Floyd usually wins on sight. At scale 4, where the pattern is the point rather than a means of reproducing tone, the ordered matrices frequently look better, because a regular pattern at that size reads as deliberate and an irregular one reads as noise.

Questions about the two families

Which one is better?
Neither, and the question is usually a proxy for a different one: is this picture going to be looked at as a photograph or as a graphic? Error diffusion preserves the average exactly and hides its own mechanism, which is what a photograph wants. Ordered dither announces its mechanism in every square inch, which is what a graphic often wants. Pick by what the result is for.
Why can ordered dither be tiled and error diffusion cannot?
Because an ordered dither decides each pixel from its position in a fixed matrix and from nothing else. Cut the result into squares, rearrange them, and every square is still correct. Error diffusion decides each pixel partly from the errors that arrived from the pixels before it, so the value at any point depends on the entire scan up to that point — cut it up and the seams do not match, and computing two halves separately gives a visible join down the middle.
My diffusion has diagonal streaks in the sky. Is that a bug?
It is a real artefact of the method, and a well-known one. Over a long, almost-flat region the errors being pushed forward reinforce each other and set off travelling in one direction, which shows up as diagonal grain. Scanning alternate rows in the opposite direction breaks most of it — this site does that everywhere — and raising the palette size removes what is left, because there is less error to push. Atkinson also breaks it, by discarding a quarter of the error outright.
Is Bayer worse because it is older?
No. Both families date from the same era and neither has been superseded. The ordered matrices were designed when carrying error between pixels was expensive, and that constraint gave them properties nothing else has — deterministic, parallelisable, tileable, and identical whichever direction you compute in. Those are still useful properties, and the look they produce is not available any other way.

Back to the lab

Rendered on your computer, not on a server.