Seeing Dither

Let's take a photograph like the one below.


Figure 1 - A photograph with 256 possible levels of gray available for each pixel.

That photo is composed of pixels, and each pixel is a shade of gray ranging from completely white to completely black. In fact, since this is an 8-bit gray photograph, there are 256 levels of gray (ranging from 00000000 to 11111111 counting in binary).

Now let's say that I wanted to reproduce the same photograph shown in Figure 1, but I had fewer shades of gray. Let's say, for example, that I reduced it to 16 levels of gray (4-bit). What I could do is to look at each pixel in the first photograph, "round" its gray value to the nearest one that I have in my new range and make the pixel that value. (In mathematical terms, if "x" is my original gray level between 0 and 256 and "y" is my new gray value between 0 and 16, then the equation will be y = round(x/16). Note that we're dividing by 16 to get from 256 down to 16. (256/16 = 16))


Figure 2 - The same photograph shown in Figure 1, quantised (rounded down) to 16 levels of gray. Look at the effect in the sky and the windows just under the dome.

It's pretty easy to see the problem here. Since there are only 16 levels of gray, you can see that what was a nice cloudy sky becomes a big splotch of the same colour gray. This is because we don't have enough shades of gray to smoothly show small differences in the clouds. In addition, you'll see that the building gets spotty, losing subtle details and turning them into big blocks of the same colour of gray.

How do we fix this problem? Oddly enough we add noise. However, the important thing is to add the noise to the original photo BEFORE we reduce the number of colours. (In mathematical terms, if "x" is my original gray level between 0 and 256 and "y" is my new gray value between 0 and 16, then the equation will be y = round((x + Dither)/16).)

The problem is that "noise" is too general a term. Let's be more precise. We could add a collection of pixels, randomly chosen to be either black or white, as shown below. This is called "Rectangular Probability Distribution Function Dither" (better known as RPDF Dither). For more info on what a "Rectangular Probability Distribution Function" is, click here. An example of RPDF Dither is shown in Figure 3, below


Figure 3 - RPDF Dither

If we take Figure 1 and add Figure 3, and then quantise (a fancy word meaning "round off") to 16 levels of gray, the result will be Figure 4, shown below.


Figure 4 - The same photograph shown in Figure 1, with RPDF noise added, and than quantised to 16 levels of gray. Again, look at the effect in the sky and the windows just under the dome.

Notice in Figure 4 that some problems have been solved. We still have large areas of the same colour gray (particularly in the sky) but the transition between the different colours has been smoothed. This smoothing is essentially noise, and it's where that dither that we added is most evident.

However, there are still problems. There are still large areas of the same level of gray, and we're still missing details. How do we fix this? We change the type of noise that we add. Instead of adding a random collection of black and white dots, let's add a random collection of black, 50% gray and white dots - a total of three values. Also, we'll make sure that there are more gray dots than white (or black). In fact, there are just as many gray dots as there are white and black dots combined. This is called "Triangular Probability Distribution Function Dither" (or TPDF Dither). For more info on what a "Triangular Probability Distribution Function" is, click here. An example of RPDF Dither is shown in Figure 5, below


Figure 5 - RPDF Dither

Now, if we add the original photograph in Figure 1 and add the TPDF Dither in Figure 5 before rounding, we get the result shown in Figure 6, below.


Figure 6 - The same photograph shown in Figure 1, with TPDF noise added, and than quantised to 16 levels of gray. Again, look at the effect in the sky and the windows just under the dome. Comparing Figures 4 and 6, you can see that, although Figure 6 (with TPDF Dither) is noisier, it has smoother transisitions and more perceived detail. Both, however, are preferable to the quantised version shown in Figure 2. What's important to remember, however, is that all three of these Figures only have 16 levels of gray in them.

What we've essentially done in Figures 4 and 6 is traded the colour distortion caused by the imprecise quantisation (rounding) for noise. The advantage is that we're able to "see through" the noise and see patterns that are similar to the original photo.

Now what happens if we reduce the number of shade of gray even further? We'll go down to only two - just black and white.


Figure 7 - The same photograph shown in Figure 1, quantised to 2 levels of gray.


Figure 8 - The same photograph shown in Figure 1, with RPDF noise added, and than quantised to 2 levels of gray. Again, look at the effect in the sky and the windows just under the dome.


Figure 9 - The same photograph shown in Figure 1, with TPDF noise added, and than quantised to 2 levels of gray. Again, look at the effect in the sky and the windows just under the dome.

As you can see, the general effect is the same, but moreso. In Figure 7, we lose all sorts of things with the quantisation. The RPDF version in Figure 8 is a little better on the transitions, but still has large areas of black. Finally, the TPDF version in Figure 9 is very noisy, but contains many more "details" (if you squint your eyes just right...)

For more specific information on what this all means to audio, check out the following links:

Quantization Error and Dither

Dither

Dither Examples

When to Use Dither