Dither


Dither is an intentionally applied form of noise used to randomize quantization error, preventing large-scale patterns such as color banding in images. Dither is routinely used in processing of both digital audio and video data, and is often one of the last stages of mastering audio to a CD.
A common use of dither is converting a greyscale image to black and white, such that the density of black dots in the new image approximates the average grey level in the original.

Etymology

The term dither was published in books on analog computation and hydraulically controlled guns shortly after World War II. Though he did not use the term dither, the concept of dithering to reduce quantization patterns was first applied by Lawrence G. Roberts in his 1961 MIT master's thesis and 1962 article. By 1964 dither was being used in the modern sense described in this article.

In digital processing and waveform analysis

Dither is utilized in many different fields where digital processing and analysis are used. These uses include systems using digital signal processing, such as digital audio, digital video, digital photography, seismology, radar and weather forecasting systems.
Quantization yields error. If that error is correlated to the signal, the result is potentially cyclical or predictable. In some fields, especially where the receptor is sensitive to such artifacts, cyclical errors yield undesirable artifacts. In these fields introducing dither converts the error to random noise. The field of audio is a primary example of this. The human ear functions much like a Fourier transform, wherein it hears individual frequencies. The ear is therefore very sensitive to distortion, or additional frequency content, but far less sensitive to additional random noise at all frequencies such as found in a dithered signal.

Digital audio

In an analog system, the signal is continuous, but in a PCM digital system, the amplitude of the signal out of the digital system is limited to one of a set of fixed values or numbers. This process is called quantization. Each coded value is a discrete step... if a signal is quantized without using dither, there will be quantization distortion related to the original input signal... In order to prevent this, the signal is "dithered", a process that mathematically removes the harmonics or other highly undesirable distortions entirely, and that replaces it with a constant, fixed noise level.

The final version of audio that goes onto a compact disc contains only 16 bits per sample, but throughout the production process, a greater number of bits are typically used to represent the sample. In the end, the digital data must be reduced to 16 bits for pressing onto a CD and distributing.
There are multiple ways to do this. One can, for example, simply discard the excess bits – called truncation. One can also round the excess bits to the nearest value. Each of these methods, however, results in predictable and determinable errors in the result. Using dither replaces these errors with a constant, fixed noise level.

Examples

Take, for example, a waveform that consists of the following values:
1 2 3 4 5 6 7 8
If the waveform is reduced by 20%, then the following are the new values:
0.8 1.6 2.4 3.2 4.0 4.8 5.6 6.4
If these values are truncated it results in the following data:
0 1 2 3 4 4 5 6
If these values are rounded instead it results in the following data:
1 2 2 3 4 5 6 6
For any original waveform, the process of reducing the waveform amplitude by 20% results in regular errors. Take for example a sine wave that, for some portion, matches the values above. Every time the sine wave's value hit 3.2, the truncated result would be off by 0.2, as in the sample data above. Every time the sine wave's value hit 4.0, there would be no error since the truncated result would be off by 0.0, also shown above. The magnitude of this error changes regularly and repeatedly throughout the sine wave's cycle. It is precisely this error which manifests itself as distortion. What the ear hears as distortion is the additional content at discrete frequencies created by the regular and repeated quantization error.
A plausible solution would be to take the 2 digit number and round it one direction or the other. For example, it could be rounded to 5 one time and then 4 the next time. This would make the long-term average 4.5 instead of 4, so that over the long-term the value is closer to its actual value. This, on the other hand, still results in determinable error. Every other time the value 4.8 comes up the result is an error of 0.2, and the other times it is −0.8. This still results in a repeating, quantifiable error.
Another plausible solution would be to take 4.8 and round it so that the first four times out of five it is rounded up to 5, and the fifth time it is rounded to 4. This would average out to exactly 4.8 over the long term. Unfortunately, however, it still results in repeatable and determinable errors, and those errors still manifest themselves as distortion to the ear.
This leads to the dither solution. Rather than predictably rounding up or down in a repeating pattern, it is possible to round up or down in a random pattern. If a series of random numbers between 0.0 and 0.9 are calculated and added to the results of the equation, two times out of ten the result will truncate back to 4 and eight times out of ten it will truncate to 5. Each given situation has a random 20% chance of rounding to 4 or 80% chance of rounding to 5. Over the long haul these results will average to 4.8 and their quantization error will be random noise. This noise is less offensive to the ear than the determinable distortion that other solutions would produce.

Usage

Dither is added before any quantization or re-quantization process, in order to de-correlate the quantization noise from the input signal and to prevent non-linear behavior. Quantization with lesser bit depth requires higher amounts of dither. The result of the process still yields distortion, but the distortion is of a random nature so the resulting noise is, effectively, de-correlated from the intended signal.
In a seminal papers published in the AES Journal, Lipshitz and Vanderkooy pointed out that different noise types, with different probability density functions behave differently when used as dither signals, and suggested optimal levels of dither signal for audio. Gaussian noise requires a higher level of added noise for full elimination of distortion than noise with rectangular or triangular distribution. Triangular distributed noise also minimizes noise modulationaudible changes in the volume level of residual noise behind quiet music that draw attention to the noise.
Dither can be useful to break up periodic limit cycles, which are a common problem in digital filters. Random noise is typically less objectionable than the harmonic tones produced by limit cycles.

Different types

Rectangular probability density function dither noise has a uniform distribution; any value in the specified range has the same probability of occurring.
Triangular probability density function dither noise has a triangular distribution; values in the center of the range have a higher probability of occurring. Triangular distribution can be achieved by adding two independent RPDF sources.
Gaussian PDF has a normal distribution. The relationship of probabilities of results follows a bell-shaped, or Gaussian curve, typical of dither generated by analog sources such as microphone preamplifiers. If the bit depth of a recording is sufficiently great, that preamplifier noise will be sufficient to dither the recording.
Noise shaping is a filtering process that shapes the spectral energy of quantization error, typically to either de-emphasize frequencies to which the ear is most sensitive or separate the signal and noise bands completely. If dither is used, its final spectrum depends on whether it is added inside or outside the feedback loop of the noise shaper. If inside, the dither is treated as part of the error signal and shaped along with actual quantization error. If outside, the dither is treated as part of the original signal and linearises quantization without being shaped itself. In this case, the final noise floor is the sum of the flat dither spectrum and the shaped quantization noise. While real-world noise shaping usually includes in-loop dithering, it is also possible to use it without adding dither at all, in which case quantization error is evident at low signal levels.
Colored dither is sometimes mentioned as dither that has been filtered to be different from white noise. Noise shaping is one such application.

Which types to use

If the signal being dithered is to undergo further processing, then it should be processed with a triangular-type dither that has an amplitude of two quantization steps so that the dither values computed range from, for example, −1 to +1, or 0 to 2. This is the lowest power ideal dither, in that it does not introduce noise modulation, and completely eliminates the harmonic distortion from quantization. If a colored dither is used instead at these intermediate processing stages, then frequency content may "bleed" into other frequency ranges that are more noticeable and become distractingly audible.
If the signal being dithered is to undergo no further processing — if it is being dithered to its final result for distribution — then a "colored" dither or noise shaping is appropriate. This can effectively lower the audible noise level, by putting most of that noise in a frequency range where it is less critical.

Digital photography and image processing

Dithering is used in computer graphics to create the illusion of color depth in images on systems with a limited color palette. In a dithered image, colors that are not available in the palette are approximated by a diffusion of colored pixels from within the available palette. The human eye perceives the diffusion as a mixture of the colors within it. Dithered images, particularly those using palettes with relatively few colors, can often be distinguished by a characteristic graininess or speckled appearance.
Dithering introduces noise or a pattern into an image, and often the patterning is visible. In these circumstances, it has been shown that dither generated from blue noise is the least unsightly and distracting. The error diffusion techniques were some of the first methods to generate blue-noise dithering patterns. However, other techniques such as ordered dithering can also generate blue-noise dithering without the tendency to degenerate into areas with artifacts.

Examples

Reducing the color depth of an image can have significant visual side-effects. If the original image is a photograph, it is likely to have thousands, or even millions of distinct colors. The process of constraining the available colors to a specific color palette effectively throws away a certain amount of color information.
A number of factors can affect the resulting quality of a color-reduced image. Perhaps most significant is the color palette that will be used in the reduced image. For example, an original image may be reduced to the 216-color "web-safe" color palette. If the original pixel colors are simply translated into the closest available color from the palette, no dithering will occur. However, typically this approach will result in flat areas and a loss of detail, and may produce patches of color that are significantly different from the original. Shaded or gradient areas may appear as color bands, which may be distracting. The application of dithering can help to minimize such visual artifacts, and usually results in a better representation of the original. Dithering helps to reduce color banding and flatness.
One of the problems associated with using a fixed color palette is that many of the needed colors may not be available in the palette, and many of the available colors may not be needed; a fixed palette containing mostly shades of green would not be well-suited for images that do not contain many shades of green, for instance. The use of an optimized color palette can be of benefit in such cases. An optimized color palette is one in which the available colors are chosen based on how frequently they are used in the original source image. If the image is reduced based on an optimized palette the result is often much closer to the original.
The number of colors available in the palette is also a contributing factor. If, for example, the palette is limited to only 16 colors then the resulting image could suffer from additional loss of detail, resulting in even more pronounced problems with flatness and color banding. Once again, dithering can help to minimize such artifacts.

Applications

Many different kinds of display hardware, including early computer video adapters as well as many modern LCDs used in mobile phones and inexpensive digital cameras, show a much smaller color range than more advanced displays. One common application of dithering is to more accurately display graphics containing a greater range of colors than the hardware is capable of showing. For example, dithering might be used in order to display a photographic image containing millions of colors on video hardware that is only capable of showing 256 colors at a time. The 256 available colors would be used to generate a dithered approximation of the original image. Without dithering, the colors in the original image might simply be "rounded off" to the closest available color, resulting in a new image that is a poor representation of the original. Dithering takes advantage of the human eye's tendency to "mix" two colors in close proximity to one another.
Some LCDs may use temporal dithering to achieve a similar effect. By alternating each pixel's color value rapidly between two approximate colors in the panel's color space, a display panel which natively supports only 18-bit color can represent a 24-bit "true" color image.
Dithering such as this, in which the computer's display hardware is the primary limitation on color depth, is commonly employed in software such as web browsers. Since a web browser may be retrieving graphical elements from an external source, it may be necessary for the browser to perform dithering on images with too many colors for the available display. It was due to problems with dithering that a color palette known as the "web-safe color palette" was identified, for use in choosing colors that would not be dithered on displays with only 256 colors available.
But even when the total number of available colors in the display hardware is high enough to "properly" render full color digital photographs, banding may still be evident to the eye, especially in large areas of smooth shade transitions. Dithering the 32 or 64 RGB levels will result in a pretty good "pseudo truecolor" display approximation, which the eye will not resolve as grainy. Furthermore, images displayed on 24-bit RGB hardware can be dithered to simulate somewhat higher bit depth, and/or to minimize the loss of hues available after a gamma correction. High-end still image processing software commonly uses these techniques for improved display.
Another useful application of dithering is for situations in which the graphic file format is the limiting factor. In particular, the commonly used GIF format is restricted to the use of 256 or fewer colors in many graphics editing programs. Images in other file formats, such as PNG, may also have such a restriction imposed on them for the sake of a reduction in file size. Images such as these have a fixed color palette defining all the colors that the image may use. For such situations, graphical editing software may be responsible for dithering images prior to saving them in such restrictive formats.
Dithering is analogous to the halftone technique used in printing. The recent widespread adoption of inkjet printers and their ability to print isolated dots has increased the use of dithering in printing. For this reason the term dithering is sometimes used interchangeably with the term halftoning, particularly in association with digital printing.
A typical desktop inkjet printer can print just 16 colors. Some of these ink combinations are not useful though, because when the black ink is used it typically obscures any of the other colors. To reproduce a large range of colors, dithering is used. In densely printed areas, where the color is dark the dithering is not always visible because the dots of ink merge producing a more uniform print. However, a close inspection of the light areas of a print where the dithering has placed dots much further apart reveals the tell-tale dots of dithering.

Algorithms

There are several algorithms designed to perform dithering. One of the earliest, and still one of the most popular, is the Floyd–Steinberg dithering algorithm, which was developed in 1975. One of the strengths of this algorithm is that it minimizes visual artifacts through an error-diffusion process; error-diffusion algorithms typically produce images that more closely represent the original than simpler dithering algorithms.
Dithering methods include:
Stimulated Brillouin Scattering is a nonlinear optical effect that limits the launched optical power in fiber optic systems. This power limit can be increased by dithering the transmit optical center frequency, typically implemented by modulating the laser's bias input. See also polarization scrambling.
An artificial jitter can be used in electronics for reducing quantization errors in A/D-Elements. Another common application is to get through EMC tests by smearing out single frequency peaks.
Another type of temporal dithering has recently been introduced in financial markets, in order to reduce the incentive to engage in high-frequency trading. ParFX, a London foreign exchange market that began trading in 2013, imposes brief random delays on all incoming orders; other currency exchanges are reportedly experimenting with the technique. The use of such temporal buffering or dithering has been advocated more broadly in financial trading of equities, commodities, and derivatives.