# How Is Image Dithering Computed?

1. Oct 4, 2011

### peter.ell

After reading about how dithering works for created the sense of a larger range of colors from a small color palette, it makes sense how it works, but how in the world do computers figure out how to dither an image so that it looks correct to us?

Is the fact that blue and red combined create the sense of purple just programmed, or how does it come about so that an image capture with no dithering gets dithered to correctly give the impression of certain colors?

Thank you so much!

2. Oct 4, 2011

### DavidSnider

Colors have their own "space", so given a limited palette you can find the closest color just like you'd find the closest point in any other space.

What dithering does is diffuse the quantization error (how far off it is from the original) of a pixel to the neighboring pixels so that the average over an area of the image remains close to the original.

So for example Floydâ€“Steinberg diffuses the error to neighboring pixels like this:
[0,0,0]
[0,0,a]
[b,c,d]

Where a = 7/16, b = 3/16, c = 5/16, d = 1/16.

You'll also notice that it only diffuses the error to the bottom right, thus leaving already quantized pixels alone when you process the image from left-to-right and top-to-bottom.

Take the example of purple being dithered to a palette containing only Red and Blue:
Purple Value: (255,0,255)

By definition purple is a mixture of red and blue. Our palette doesn't have (255,0,255) so a single pixel can not represent it exactly, so we diffuse Red (255,0,0) and Blue (0,0,255) throughout space so that on average it comes out looking purple.

Last edited: Oct 4, 2011
3. Oct 4, 2011

### peter.ell

Thank you. I appreciate your answer, it was very helpful.

All the best!