{"id":1671,"date":"2025-07-11T13:53:05","date_gmt":"2025-07-11T13:53:05","guid":{"rendered":"https:\/\/www.newsbeep.com\/us\/1671\/"},"modified":"2025-07-11T13:53:05","modified_gmt":"2025-07-11T13:53:05","slug":"dithering-with-quantization-to-smooth-things-over","status":"publish","type":"post","link":"https:\/\/www.newsbeep.com\/us\/1671\/","title":{"rendered":"Dithering With Quantization To Smooth Things Over"},"content":{"rendered":"<p>It should probably come as no surprise to anyone that the images which we look at every day \u2013 whether printed or on a display \u2013 are simply illusions. That cat picture isn\u2019t actually a cat, but rather a collection of dots that when looked at from far enough away tricks our brain into thinking that we are indeed looking at a two-dimensional cat and happily fills in the blanks. These dots can use the full CMYK color model for prints, RGB(A) for digital images or a limited color space including greyscale.<\/p>\n<p>Perhaps more interesting is the use of dithering to further trick the mind into seeing things that aren\u2019t truly there by adding noise. Simply put, dithering is the process of adding noise to reduce quantization error, which in images shows up as artefacts like color banding. Within the field of digital audio dithering is also used, for similar reasons. Part of the process of going from an analog signal to a digital one involves throwing away data that falls outside the sampling rate and quantization depth.<\/p>\n<p>By adding dithering noise these quantization errors are smoothed out, with the final effect depending on the dithering algorithm used.<\/p>\n<p>The Digital Era<br \/>\n<a href=\"https:\/\/hackaday.com\/wp-content\/uploads\/2016\/06\/quantizatio-error.png\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"212456\" data-permalink=\"https:\/\/hackaday.com\/2016\/07\/07\/tearing-into-delta-sigma-adcs-part-1\/quantizatio-error\/\" data-orig-file=\"https:\/\/hackaday.com\/wp-content\/uploads\/2016\/06\/quantizatio-error.png\" data-orig-size=\"489,320\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"quantizatio error\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Source:Wikipedia&lt;\/p&gt;&#10;\" data-medium-file=\"https:\/\/www.newsbeep.com\/us\/wp-content\/uploads\/2025\/07\/quantizatio-error.png\" data-large-file=\"https:\/\/hackaday.com\/wp-content\/uploads\/2016\/06\/quantizatio-error.png?w=489\" class=\"size-medium wp-image-212456\" src=\"https:\/\/www.newsbeep.com\/us\/wp-content\/uploads\/2025\/07\/quantizatio-error.png\" alt=\"Plot of a quantized signal and its error. (Source: Wikimedia)\" width=\"400\" height=\"262\"  \/><\/a>Plot of a quantized signal and its error. (Source: <a href=\"https:\/\/commons.wikimedia.org\/wiki\/File:Quanterr.png\" target=\"_blank\" rel=\"nofollow noopener\">Wikimedia<\/a>)<\/p>\n<p>For most of history, humanity\u2019s methods of visual-auditory recording and reproduction were analog, starting with methods like drawing and painting. Until fairly recently reproducing music required you to assemble skilled artists, until the arrival of analog recording and playback technologies. Then suddenly, with the rise of computer technology in the second half of the 20th century we gained the ability to not only perform analog-to-digital conversion, but also store the resulting digital format in a way that promised near-perfect reproduction.<\/p>\n<p>Digital optical discs and tapes found themselves competing with analog formats like the compact cassette and vinyl records. While video and photos remained analog for a long time in the form of VHS tapes and film, eventually these all gave way to the fully digital world of digital cameras, JPEGs, PNGs, DVDs and MPEG. Despite the theoretical pixel- and note-perfect reproduction of digital formats, considerations like sampling speed (<a href=\"https:\/\/www.ghostbsd.org\/\" target=\"_blank\" rel=\"nofollow noopener\">Nyquist frequency<\/a>) and the aforementioned quantization errors mean a range of new headaches to address.<\/p>\n<p>That said, the first use of dithering was actually in the 19th century, when newspapers and other printed media were looking to print phots without the hassle of having a woodcut or engraving made. This led to the invention of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Halftone\" target=\"_blank\" rel=\"nofollow noopener\">halftone<\/a> printing.<\/p>\n<p>Polka Dots<br \/>\n<a href=\"https:\/\/hackaday.com\/wp-content\/uploads\/2025\/05\/Halftoning_introduction.svg_.png\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"789174\" data-permalink=\"https:\/\/hackaday.com\/2025\/07\/09\/dithering-with-quantization-to-smooth-things-over\/halftoning_introduction-svg\/\" data-orig-file=\"https:\/\/hackaday.com\/wp-content\/uploads\/2025\/05\/Halftoning_introduction.svg_.png\" data-orig-size=\"260,310\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Halftoning_introduction.svg\" data-image-description=\"&lt;p&gt;https:\/\/en.wikipedia.org\/wiki\/File:Halftoning_introduction.svg?useskin=vector&lt;\/p&gt;&#10;\" data-image-caption=\"&lt;p&gt;Left: halftone dot pattern with increasing size downwards, Right: how the human eye would see this, when viewed from a sufficient distance. (Credit: Wikimedia)&lt;\/p&gt;&#10;\" data-medium-file=\"https:\/\/www.newsbeep.com\/us\/wp-content\/uploads\/2025\/07\/Halftoning_introduction.svg_.png\" data-large-file=\"https:\/\/www.newsbeep.com\/us\/wp-content\/uploads\/2025\/07\/Halftoning_introduction.svg_.png\" class=\"size-medium wp-image-789174\" src=\"https:\/\/www.newsbeep.com\/us\/wp-content\/uploads\/2025\/07\/Halftoning_introduction.svg_.png\" alt=\"Left: halftone dot pattern with increasing size downwards, Right: how the human eye would see this, when viewed from a sufficient distance. (Credit: Wikimedia)\" width=\"260\" height=\"310\"  \/><\/a>Left: halftone dot pattern with increasing size downwards, Right: how the human eye would see this, when viewed from a sufficient distance. (Source: <a href=\"https:\/\/en.wikipedia.org\/wiki\/File:Halftoning_introduction.svg?useskin=vector\" target=\"_blank\" rel=\"nofollow noopener\">Wikimedia<\/a>)<\/p>\n<p>With early printing methods, illustrations were limited to an all-or-nothing approach with their ink coverage. This obviously meant serious limitations when it came to more detailed illustrations and photographs, until the\u00a0 arrival of the halftone printing method. First patented in 1852\u00a0 by William Fox Talbot, his approach used a special screen to break down an image into discrete points on a photographic plate. After developing this into a printing plate, these plates would then print this pattern of differently sized points.<\/p>\n<p>Although the exact halftone printing methods were refined over the following decades, the basic principle remains the same to this day: by varying the size of the dot and the surrounding empty (white) space, the perceived brightness changes. When this method got extended to color prints with the CMYK color model, the resulting printing of these three colors as adjoining dots allowed for full-color photographs to be printed in newspapers and magazines despite having only so few ink colors available.<\/p>\n<p>While it\u2019s also possible to do CMYK printing with blending of the inks, as in e.g. inkjet printers, this comes with some disadvantages especially when printing on thin, low-quality paper, such as that used for newspapers, as the ink saturation can cause the paper to rip and distort. This makes CMYK and monochrome dithering still a popular technique for newspapers and similar low-fidelity applications.<\/p>\n<p>Color Palettes<\/p>\n<p>In an ideal world, every image would have an unlimited color depth. Unfortunately we sometimes have to adapt to a narrower color space, such as when converting to the Graphics Interchange Format (<a href=\"https:\/\/en.wikipedia.org\/wiki\/GIF\" target=\"_blank\" rel=\"nofollow noopener\">GIF<\/a>), which is limited to 8 bits per pixel. This 1987-era and still very popular format thus provides an astounding 256 possible colors\u00a0 -albeit from a full 24-bit color space \u2013 which poses a bit of a challenge when using a 24-bit PNG or similar format as the source. Simply reducing the bit depth causes horrible color banding, which means that we should use dithering to ease these sharp transitions, like the very common Floyd-Steinberg dithering algorithm:<\/p>\n<p><a href=\"https:\/\/hackaday.com\/wp-content\/uploads\/2025\/05\/cat_original_undithered_floyd_steinberg_dithering.jpg\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"789177\" data-permalink=\"https:\/\/hackaday.com\/2025\/07\/09\/dithering-with-quantization-to-smooth-things-over\/cat_original_undithered_floyd_steinberg_dithering\/\" data-orig-file=\"https:\/\/hackaday.com\/wp-content\/uploads\/2025\/05\/cat_original_undithered_floyd_steinberg_dithering.jpg\" data-orig-size=\"770,200\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"cat_original_undithered_floyd_steinberg_dithering\" data-image-description=\"&lt;p&gt;https:\/\/en.wikipedia.org\/wiki\/Floyd\u2013Steinberg_dithering&lt;\/p&gt;&#10;\" data-image-caption=\"&lt;p&gt;From left to right: original image, converted to web safe colors, web safe with Floyd-Steinberg dithering. (Credit: Wikipedia)&lt;\/p&gt;&#10;\" data-medium-file=\"https:\/\/hackaday.com\/wp-content\/uploads\/2025\/05\/cat_original_undithered_floyd_steinberg_dithering.jpg?w=400\" data-large-file=\"https:\/\/www.newsbeep.com\/us\/wp-content\/uploads\/2025\/07\/cat_original_undithered_floyd_steinberg_dithering.jpg\" class=\"wp-image-789177 size-large\" src=\"https:\/\/www.newsbeep.com\/us\/wp-content\/uploads\/2025\/07\/cat_original_undithered_floyd_steinberg_dithering.jpg\" alt=\"From left to right: original image. Converted to web safe color. Web safe with Floyd-Steinberg dithering. (Credit: Wikipedia)\" width=\"770\" height=\"200\"  \/><\/a>From left to right: original image. Converted to web safe color. Web safe with Floyd-Steinberg dithering. (Source: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Floyd\u2013Steinberg_dithering\" target=\"_blank\" rel=\"nofollow noopener\">Wikipedia<\/a>)<\/p>\n<p>The Floyd-Steinberg dithering algorithm was created in 1976 by Robert W. Floyd and Louis Steinberg. Its approach to dithering is based on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Error_diffusion\" target=\"_blank\" rel=\"nofollow noopener\">error diffusion<\/a>, meaning that it takes the quantization error that causes the sharp banding and distributes it across neighboring pixels. This way transitions are less abrupt, even if it means that there is noticeable image degradation (i.e. noise) compared to the original.<\/p>\n<p>This algorithm is quite straightforward, working its way down the image one pixel at a time without affecting previously processed pixels. After obtaining the current pixel\u2019s quantization error, this is distributed across the subsequent pixels following and below the current one, as in the below pseudo code:<\/p>\n<p>for each y from top to bottom do<br \/>\n    for each x from left to right do<br \/>\n        oldpixel\u00a0:= pixels[x][y]<br \/>\n        newpixel\u00a0:= find_closest_palette_color(oldpixel)<br \/>\n        pixels[x][y]\u00a0:= newpixel<br \/>\n        quant_error\u00a0:= oldpixel &#8211; newpixel<br \/>\n        pixels[x + 1][y    ]\u00a0:= pixels[x + 1][y    ] + quant_error \u00d7 7 \/ 16<br \/>\n        pixels[x &#8211; 1][y + 1]\u00a0:= pixels[x &#8211; 1][y + 1] + quant_error \u00d7 3 \/ 16<br \/>\n        pixels[x    ][y + 1]\u00a0:= pixels[x    ][y + 1] + quant_error \u00d7 5 \/ 16<br \/>\n        pixels[x + 1][y + 1]\u00a0:= pixels[x + 1][y + 1] + quant_error \u00d7 1 \/ 16<\/p>\n<p>The implementation of the\u00a0find_closest_palette_color() function is key here, with for a greyscale image a simple round(oldpixel \/ 255) sufficing, or trunc(oldpixel + 0.5) as <a href=\"https:\/\/research.cs.wisc.edu\/graphics\/Courses\/559-s2004\/docs\/floyd-steinberg.pdf\" target=\"_blank\" rel=\"nofollow noopener\">suggested<\/a> in this CS 559 course material from 2000 by the Universe of Wisconsin-Madison.<\/p>\n<p>As basic as Floyd-Steinberg is, it\u2019s still commonly used today due to the good results that it gives with fairly minimal effort. Which is not to say that there aren\u2019t other dithering algorithms out there, with the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dither\" target=\"_blank\" rel=\"nofollow noopener\">Wikipedia entry on dithering<\/a> helpfully pointing out a number of alternatives, both within the same error diffusion category as well as other categories like <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ordered_dithering\" target=\"_blank\" rel=\"nofollow noopener\">ordered dithering<\/a>. In the case of ordered dithering there is a distinct crosshatch pattern that is both very recognizable and potentially off-putting.<\/p>\n<p>Dithering is of course performed here to compensate for a lack of bit-depth, meaning that it will never look as good as the original image, but the less obnoxious the resulting artefacts are, the better.<\/p>\n<p>Dithering With Audio<\/p>\n<p>Although at first glance dithering with digital audio seems far removed from dithering the quantization error with images, the same principles apply here. When for example the original recording has to be downsampled to CD-quality (i.e. 16-bit) audio, we can either round or truncate the original samples to get the desired sample size, but we\u2019d get distortion in either case. This distortion is highly noticeable by the human ear as the quantization errors create new frequencies and harmonics, this is quite noticeable in the 16- to 6-bit downsampling examples provided in the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dither\" target=\"_blank\" rel=\"nofollow noopener\">Wikipedia entry<\/a>.<\/p>\n<p>In the sample with dithering, there is clearly noise audible, but the original signal (a sine wave) now sounds pretty close to the original signal. This is done through the adding of random noise to each sample by randomly rounding up or down and counting on the average. Although random noise is clearly audible in the final result, it\u2019s significantly better than the undithered version.<\/p>\n<p>Random noise distribution is also possible with images, but more refined methods tend to give better results. For audio processing there are alternative noise distributions and noise shaping approaches.<\/p>\n<p>Regardless of which dither method is being applied, it remains fascinating how the humble printing press and quantization errors have led to so many different ways to trick the human eye and ear into accepting lower fidelity content. As many of the technical limitations that existed during the time of their conception \u2013 such as expensive storage and low bandwidth \u2013 have now mostly vanished, it will be interesting to see how dithering usage evolves over the coming years and decades.<\/p>\n<p>Featured image: \u201cJJN Dithering\u201d from [Tanner Helland]\u2019s <a href=\"https:\/\/tannerhelland.com\/2012\/12\/28\/dithering-eleven-algorithms-source-code.html\" target=\"_blank\" rel=\"nofollow noopener\">great dithering writeup<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"It should probably come as no surprise to anyone that the images which we look at every day&hellip;\n","protected":false},"author":2,"featured_media":1672,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[49],"tags":[199,79],"class_list":{"0":"post-1671","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-physics","8":"tag-physics","9":"tag-science"},"_links":{"self":[{"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/posts\/1671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/comments?post=1671"}],"version-history":[{"count":0,"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/posts\/1671\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/media\/1672"}],"wp:attachment":[{"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/media?parent=1671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/categories?post=1671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.newsbeep.com\/us\/wp-json\/wp\/v2\/tags?post=1671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}