TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Image Dithering: Eleven Algorithms and Source Code

199 pointsby nkronalmost 9 years ago

21 comments

dahartalmost 9 years ago
I still use dithering daily with 24 bit color images. In fact, my test for whether a modern image editor is serious and good is whether it supports dithering when converting from floating point color channels down to 8 bits per channel. Photoshop does this.<p>The most important reason for me is not display on the monitor, but printing the image. I do a lot of large format printing, and printers smash parts of your color space and make some gradient&#x2F;banding problems stick out like a sore thumb. Dithering is critical when printing!<p>Gradients with banding can easily show up when you resize a large image down to a smaller size. This is a good reason that resizing probably anything less than 16 bits per channel images should be done in a higher precision format than the image.<p>I haven&#x27;t tried to use an error diffusion dither when converting 16 bits per channel down to 8... I&#x27;m not sure how much that matters. It might make a difference, and it sounds fun to code either way, but in my experience, a good random number generator suffices to make color bands vanish.
bajsejohannesalmost 9 years ago
&gt; It also has uses when reducing 48 or 64bpp RAW-format digital photos to 24bpp RGB for editing.<p>The author touches upon it here, but I think it&#x27;s worth generalizing further: If you have high or maybe infinite precision in your color values, dithering will look much nicer than simply rounding to the nearest value. A concrete example is a color gradient. If done naively with rounding, color bands will be clearly visible. With dithering, they will be almost impossible to see.<p>See for example: <a href="http:&#x2F;&#x2F;johanneshoff.com&#x2F;dithering&#x2F;" rel="nofollow">http:&#x2F;&#x2F;johanneshoff.com&#x2F;dithering&#x2F;</a>
the8472almost 9 years ago
The article doesn&#x27;t mention the void and cluster[0][1] ordered dithering (and modernized variants) which have the advantage of ordered dithering that they are highly parallelization, e.g. via GPU shaders but do not leave the easily spottable patterns of ordered dithering.<p>For example the madVR[2] video renderer uses it for realtime video dithering to avoid banding shallow color gradients from 10bit sources or debanded internal 16bit representation on &lt;= 8bit displays.<p>[0] <a href="http:&#x2F;&#x2F;cv.ulichney.com&#x2F;papers&#x2F;1993-void-cluster.pdf" rel="nofollow">http:&#x2F;&#x2F;cv.ulichney.com&#x2F;papers&#x2F;1993-void-cluster.pdf</a> [1] <a href="http:&#x2F;&#x2F;www.hpl.hp.com&#x2F;research&#x2F;isl&#x2F;halftoning&#x2F;publications&#x2F;1995-filter-extent.pdf" rel="nofollow">http:&#x2F;&#x2F;www.hpl.hp.com&#x2F;research&#x2F;isl&#x2F;halftoning&#x2F;publications&#x2F;1...</a> [2] <a href="http:&#x2F;&#x2F;madvr.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;madvr.com&#x2F;</a>
评论 #11889374 未加载
评论 #11889159 未加载
harryfalmost 9 years ago
A while back got curious about the approach used by apps like Manga Camera ( <a href="https:&#x2F;&#x2F;play.google.com&#x2F;store&#x2F;apps&#x2F;details?id=jp.co.supersoftware.mangacamera" rel="nofollow">https:&#x2F;&#x2F;play.google.com&#x2F;store&#x2F;apps&#x2F;details?id=jp.co.supersof...</a> ) to turn photos into Manga style &quot;drawings&quot;.<p>Turns out there&#x27;s a paper on it &quot;MANGAWALL: GENERATING MANGA PAGES FOR REAL-TIME APPLICATIONS&quot; ( <a href="https:&#x2F;&#x2F;www.semanticscholar.org&#x2F;paper&#x2F;MangaWall-Generating-manga-pages-for-real-time-Wu-Aizawa&#x2F;c027ee8729d44f3a08b5e7361689513123954ac6&#x2F;pdf" rel="nofollow">https:&#x2F;&#x2F;www.semanticscholar.org&#x2F;paper&#x2F;MangaWall-Generating-m...</a> ) and an implementation - <a href="https:&#x2F;&#x2F;github.com&#x2F;zippon&#x2F;MangaWall" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;zippon&#x2F;MangaWall</a> - that implementation uses ordered dithering ( <a href="https:&#x2F;&#x2F;github.com&#x2F;zippon&#x2F;MangaWall&#x2F;blob&#x2F;master&#x2F;src&#x2F;MangaEngine.cc#L206" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;zippon&#x2F;MangaWall&#x2F;blob&#x2F;master&#x2F;src&#x2F;MangaEng...</a> ) among other things to help produce a pencil drawn like effect.<p>Anyway just saying ;) To me at least, pretty fascinating ...
1wdalmost 9 years ago
A fun (if not terribly effective) algorithm that&#x27;s missing here is dithering along a Hilbert curve.<p><a href="http:&#x2F;&#x2F;caca.zoy.org&#x2F;study&#x2F;part3.html" rel="nofollow">http:&#x2F;&#x2F;caca.zoy.org&#x2F;study&#x2F;part3.html</a>
评论 #11887155 未加载
akavelalmost 9 years ago
For an interesting case of modern artistic use of dithering, see the discussion related to development of indie game &quot;Return of the Obra Dinn&quot; [1] (by Lucas Pope, author of &quot;Papers, please&quot;), where a participant contributed a dithering scheme he invented [2] for a specific purpose of making faces of in-game characters better looking and easier to recognize.<p>[1] <a href="https:&#x2F;&#x2F;forums.tigsource.com&#x2F;index.php?topic=40832.msg1217196#msg1217196" rel="nofollow">https:&#x2F;&#x2F;forums.tigsource.com&#x2F;index.php?topic=40832.msg121719...</a><p>[2] <a href="https:&#x2F;&#x2F;forums.tigsource.com&#x2F;index.php?topic=40832.msg1212805#msg1212805" rel="nofollow">https:&#x2F;&#x2F;forums.tigsource.com&#x2F;index.php?topic=40832.msg121280...</a><p>(Just in case and for easier browsing, I took liberty of uploading a copy to github: <a href="https:&#x2F;&#x2F;github.com&#x2F;akavel&#x2F;WernessDithering" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;akavel&#x2F;WernessDithering</a>, although I&#x27;m not clear on what&#x27;s the license of the code, unfortunately; that said I hope the numbers in the matrix are not patented.)<p>(<i>edit:</i> lol, didn&#x27;t notice there&#x27;s another thread on Obra Dinn already on HN, now I&#x27;m surprised! :)
richard_toddalmost 9 years ago
I don&#x27;t know if it&#x27;s some kind of nostalgia factor (since a lot of old 16-color EGA software used it, I think), but I find ordered dithering output strangely appealing. I have also used it sometimes where size mattered more than style on the assumption that GIF&#x2F;PNG compression rates would be better on ordered dithers. ImageMagick can do a lot of dithering styles and it&#x27;s fun to play with.
nullcalmost 9 years ago
This thesis on image dithering and noise shaping is one of the best works I&#x27;ve read on the subject: <a href="http:&#x2F;&#x2F;uwspace.uwaterloo.ca&#x2F;bitstream&#x2F;10012&#x2F;3867&#x2F;1&#x2F;thesis.pdf" rel="nofollow">http:&#x2F;&#x2F;uwspace.uwaterloo.ca&#x2F;bitstream&#x2F;10012&#x2F;3867&#x2F;1&#x2F;thesis.pd...</a>
评论 #11886803 未加载
RiscyAcornalmost 9 years ago
Last year I tried painting some Floyd-Steinberg dithered pixels... <a href="https:&#x2F;&#x2F;flashasm.wordpress.com&#x2F;2015&#x2F;11&#x2F;04&#x2F;more-incredibly-slow-rendering-algorithms-cupcakes-pixel-art&#x2F;" rel="nofollow">https:&#x2F;&#x2F;flashasm.wordpress.com&#x2F;2015&#x2F;11&#x2F;04&#x2F;more-incredibly-sl...</a> (16 colours) and <a href="https:&#x2F;&#x2F;flashasm.wordpress.com&#x2F;2016&#x2F;05&#x2F;18&#x2F;81920-pixels-of-64-colour-cupcake-goodness&#x2F;" rel="nofollow">https:&#x2F;&#x2F;flashasm.wordpress.com&#x2F;2016&#x2F;05&#x2F;18&#x2F;81920-pixels-of-64...</a> (64 colours)
1wdalmost 9 years ago
Another fun fact I always think of when dithering comes up is how Tim Sweeney&#x27;s software rendered or the original Unreal game used dithering instead of bilinear interpolation for texture mapping. This was very impressive at the time.<p><a href="http:&#x2F;&#x2F;www.flipcode.com&#x2F;archives&#x2F;Texturing_As_In_Unreal.shtml" rel="nofollow">http:&#x2F;&#x2F;www.flipcode.com&#x2F;archives&#x2F;Texturing_As_In_Unreal.shtm...</a>
huuualmost 9 years ago
It&#x27;s a kind of funny those images look nice on high res screens.<p>Some time ago I experimented with 16-32 color images on websites. Because of high res screens they look great but save a lot of data.
IvanK_netalmost 9 years ago
Few years ago, I created a real-time dithering of video in Javascript: <a href="http:&#x2F;&#x2F;blog.ivank.net&#x2F;floyd-steinberg-dithering-in-javascript.html" rel="nofollow">http:&#x2F;&#x2F;blog.ivank.net&#x2F;floyd-steinberg-dithering-in-javascrip...</a>
semi-extrinsicalmost 9 years ago
This article is really nice. I used it as my starting point when I once won a code golf competition on image quality in dithering. Using Fortran.<p>The algorithm is based on Sierra Lite, but I added a random element to the direction in which the error is propagated. This removes essentially all dithering artifacts.<p><a href="http:&#x2F;&#x2F;codegolf.stackexchange.com&#x2F;questions&#x2F;26554&#x2F;dither-a-grayscale-image" rel="nofollow">http:&#x2F;&#x2F;codegolf.stackexchange.com&#x2F;questions&#x2F;26554&#x2F;dither-a-g...</a>
joostersalmost 9 years ago
Has anyone tried using the equivalent of animated GIFs to help with dithering? If you have a limited palette of colours, perhaps you could produce two dithered versions, with pixels sometimes having different colours in alternate frames. If the image is refreshed fast enough, two colours could blend into a third.<p>The most extreme example could be &#x27;dithering&#x27; a grey square into 1) a black square and 2) a white square, and when they are rapidly switching between the two it might appear as a grey instead.<p>I guess that in practice, the refresh rates of monitors are too low to make it seem anything other than a terrible flickering image, but on old CRTs the effect might work a little better. It&#x27;s also memory and CPU intensive, but I&#x27;d still be curious to see if it could be used successfully, and if it improved the quality compared to &#x27;just&#x27; a single dithered image.
评论 #11893666 未加载
评论 #11889101 未加载
评论 #11888274 未加载
评论 #11892146 未加载
评论 #11889023 未加载
chhabrakadabraalmost 9 years ago
This was a great read. Very approachable.
dividuumalmost 9 years ago
There is another interesting application for dithering that I&#x27;ve read about in the recent Uncharted 4 Brain Dump (Ctrl-F for &quot;Dithering&quot;) here <a href="https:&#x2F;&#x2F;redd.it&#x2F;4itbxq" rel="nofollow">https:&#x2F;&#x2F;redd.it&#x2F;4itbxq</a>: Use dithering instead of alpha blending to fade out close objects. Alpha blending can be quite expensive while dithering just omits pixels. The result looks like this: <a href="http:&#x2F;&#x2F;allenchou.net&#x2F;wp-content&#x2F;uploads&#x2F;2016&#x2F;05&#x2F;dithering-1-1024x576.png" rel="nofollow">http:&#x2F;&#x2F;allenchou.net&#x2F;wp-content&#x2F;uploads&#x2F;2016&#x2F;05&#x2F;dithering-1-...</a> (best visible at the top left corner).
评论 #11889967 未加载
seanwilsonalmost 9 years ago
Great and easy to follow article!<p>&gt; For simplicity of computation, all standard dithering formulas push the error forward, never backward. If you loop through an image one pixel at a time, starting at the top-left and moving right, you never want to push errors backward (e.g. left and&#x2F;or up).<p>Would the image look a lot different if you dithered it backwards from the bottom right pixel?<p>Are there dithering algorithms that consider the error in all directions instead of pushing the errors forward only?
评论 #11887877 未加载
评论 #11888349 未加载
rabidsnailalmost 9 years ago
Also if you don&#x27;t know what your target palette is you can do k-means clustering over colorspace, and the palette is the cluster centers (each point you&#x27;re giving to k-means is an &lt;r,g,b&gt; or &lt;h,s,v&gt; vector).
评论 #11889728 未加载
mynegationalmost 9 years ago
Back when I was at university, we had a computer graphics course. Each week we got new assignment that we needed to program, write to a floppy disk (it was before Internet became widely available) and give it to the prof next week.<p>Dithering was one of the assignments. We were required to implement black-white quantization and then Atkinson and Floyd-Steinberg. We were given the freedom to choose our own images.<p>During development at the dorm my favourite picture to debug on was pretty racy (think along the lines of full version of &quot;Lena&quot;). I totally did not intend to put it to the floppy disk...<p>Not only I got the 10 - the highest number of points for this assignment, I got +2 on top of that with the comment from prof: &quot;for the choice of test images in the best tradition of the field&quot;.
评论 #11906417 未加载
评论 #11886777 未加载
rasz_plalmost 9 years ago
Neat facts:<p>-3DFX Voodoo (all models in 16bit color depth) let you enable hardware dithering block (2x2&#x2F;4x4 ordered dither, zero performance penalty). They did it to save framebuffer space (24bit textures, 16bit framebuffer). It made 3dfx graphics look significantly better than nvidia&#x2F;ati in 16bit depth. Earlier cards used 4x1 filter on the output, Banshee and later models gained 2x2 filter providing &quot;22 bit like quality&quot; as 3dfx called it.<p>-Back in ~1994 some HP unix workstations used dithering to produce &#x27;near 23bit color&#x27; out of 8bit framebuffer <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;HP_Color_recovery" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;HP_Color_recovery</a><p>-All crappy (TN) LCD panels (staple of garbage bin supermarket 1366x768 laptop, and older &#x27;gaming&#x27; fullhd ones) use FRC which is a form of temporal dithering <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Frame_rate_control" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Frame_rate_control</a><p>One legitimate use of dithering was in the days of CGA&#x2F;EGA&#x2F;other fixed palette hardware. You can relive it here &#x27;Joel Yliluoma&#x27;s arbitrary-palette positional dithering algorithm&#x27;: <a href="http:&#x2F;&#x2F;bisqwit.iki.fi&#x2F;story&#x2F;howto&#x2F;dither&#x2F;jy&#x2F;" rel="nofollow">http:&#x2F;&#x2F;bisqwit.iki.fi&#x2F;story&#x2F;howto&#x2F;dither&#x2F;jy&#x2F;</a>
ja27almost 9 years ago
I sense a disturbance in the force. It&#x27;s as if 1,000 BitCam clones were just born.