Ordered dithering
![](http://upload.wikimedia.org/wikipedia/en/4/46/Lenna_ordered_dither.png)
![](http://upload.wikimedia.org/wikipedia/commons/e/e5/Ordered_4x4_Bayer_matrix_dithering.png)
Ordered dithering is an image dithering algorithm. It is commonly used to display a continuous image on a display of smaller color depth. For example, Microsoft Windows uses it in 16-color graphics modes. The algorithm is characterized by noticeable crosshatch patterns in the result.
Threshold map[]
The algorithm reduces the number of colors by applying a threshold map M to the pixels displayed, causing some pixels to change color, depending on the distance of the original color from the available color entries in the reduced palette.
Threshold maps come in various sizes, which is typically a power of two:
|
The map may be rotated or mirrored without affecting the effectiveness of the algorithm. This threshold map (for sides with length as power of two) is also known as an index matrix or Bayer matrix.[1]
Arbitrary size threshold maps can be devised with a simple rule: First fill each slot with a successive integers. Then reorder them such that the average distance between two successive numbers in the map is as large as possible, ensuring that the table "wraps" around at edges.[citation needed] For threshold maps whose dimensions are a power of two, the map can be generated recursively via:
The recursive expression can be calculated explicitly using only bit arithmetic:[2]
M(i, j) = bit_reverse(bit_interleave(bitwise_xor(i, j), i)) / n ^ 2
Pre-calculated threshold maps[]
Rather than storing the threshold map as a matrix of × integers from 0 to , depending on the exact hardware used to perform the dithering, it may be beneficial to pre-calculate the thresholds of the map into a floating point format, rather than the traditional integer matrix format shown above.
For this, the following formula can be used:
Mpre(i,j) = (Mint(i,j)+1) / n^2
This generates a standard threshold matrix.
for the 2×2 map:
|
this creates the pre-calculated map:
|
Additionally, normalizing the values to average out their sum to 0 (as done in the dithering algorithm shown below) can be done during pre-processing as well by substracting 1⁄2 from every value:
Mpre(i,j) = (Mint(i,j)+1) / n^2 - 0.5
creating the pre-calculated map:
|
Algorithm[]
The ordered dithering algorithm renders the image normally, but for each pixel, it offsets its color value with a corresponding value from the threshold map according to its location, causing the pixel's value to be quantized to a different color if it exceeds the threshold.
For most dithering purposes, it is sufficient to simply add the threshold value to every pixel (without performing normalization by subtracting 1⁄2), or equivalently, to compare the pixel's value to the threshold: if the brightness value of a pixel is less than the number in the corresponding cell of the matrix, plot that pixel black, otherwise, plot it white. This lack of normalization slightly increases the average brightness of the image, and causes almost-white pixels to not be dithered. This is not a problem when using a gray scale palette (or any palette where the relative color distances are (nearly) constant), and it is often even desired, since the human eye perceives differences in darker colors more accurately than lighter ones, however, it produces incorrect results especially when using a small or arbitrary palette, so proper normalization should be preferred.
![](http://upload.wikimedia.org/wikipedia/commons/4/4b/Scale_ordered_dither.png)
In other words, the algorithm performs the following transformation on each color c of every pixel:
Because the algorithm operates on single pixels and has no conditional statements, it is very fast and suitable for real-time transformations. Additionally, because the location of the dithering patterns always stays the same relative to the display frame, it is less prone to jitter than error-diffusion methods, making it suitable for animations. Because the patterns are more repetitive than error-diffusion method, an image with ordered dithering compresses better. Ordered dithering is more suitable for line-art graphics as it will result in straighter lines and fewer anomalies.
The values read from the threshold map should preferably scale into the same range as the minimal difference between distinct colors in the target palette. Equivalently, the size of the map selected should be equal to or larger than the ratio of source colors to target colors. For example, when quantizing a 24 bpp image to 15 bpp (256 colors per channel to 32 colors per channel), the smallest map one would choose would be 4×2, for the ratio of 8 (256:32). This allows expressing each distinct tone of the input with different dithering patterns.[citation needed]
A variable palette: pattern dithering[]
![]() | This section is empty. You can help by . (July 2021) |
Non-Bayer approaches[]
The above thresholding matrix approach describes the Bayer family of ordered dithering algorithms. A number of other algorithms are also known; they generally involve changes in the threshold matrix, equivalent to the "noise" in general descriptions of dithering.
Halftone[]
Halftone dithering performs a form of clustered dithering, creating a look similar to halftone patterns, using a specially crafted matrix.
Void and cluster[]
The Void and cluster algorithm uses a pre-generated blue noise as the matrix for the dithering process.[3] The blue noise matrix keeps the Bayer's good high frequency content, but with a more uniform coverage of all the frequencies involved shows a much lower amount of patterning.[4]
The "voids-and-cluster" method gets its name from the matrix generation procedure, where a black image with randomly initialized white pixels is gaussian-blurred to find the brightest and darkest parts, corresponding to voids and clusters. After a few swaps have evenly distributed the bright and dark parts, the pixels are numbered by importance. It takes significant computational resources to generate the blue noise matrix: on a modern computer a 64×64 matrix requires a couple seconds using the original algorithm.[5]
References[]
- ^ Bayer, Bryce (June 11–13, 1973). "An optimum method for two-level rendition of continuous-tone pictures" (PDF). IEEE International Conference on Communications. 1: 11–15. Archived from the original (PDF) on 2013-05-12. Retrieved 2012-07-19.
- ^ Joel Yliluoma. “Arbitrary-palette positional dithering algorithm”
- ^ Ulichney, Robert A (1993). "The void-and-cluster method for dither array generation" (PDF). Retrieved 2014-02-11.
- ^ Wronski, Bart (31 October 2016). "Dithering part three – real world 2D quantization dithering".
- ^ Peters, Christoph. "Free blue noise textures". momentsingraphics.de.
- Ordered Dithering (Graphics course project, Visgraf lab, Brazil)
- Dithering algorithms (Lee Daniel Crocker, Paul Boulay and Mike Morra)
Further reading[]
- Ancin, Hakan; Bhattacharjya, Anoop K.; Shu, Joseph S. (2 January 1998). "Improving void-and-cluster for better halftone uniformity". Photonics West '98 Electronic Imaging: 321–329. CiteSeerX 10.1.1.40.5331. doi:10.1117/12.298295.
External links[]
- Matlab implementation of various dithering methods
- anim8gdx, Java implementation of various (mostly ordered) dithering methods
- Image processing