Live data from Hacker News

Ditherpunk: The article I wish I had about monochrome image dithering

surma.dev

161–170 of 203 posts

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#161

Earlier quoted context omitted.

I don't think of colorspaces as "historical burdens". I don't like that CRT monitors are brought up every time sRGB is mentioned though. I know it has historical relevance, but it's not relevant anymore, and it's not needed to understand the difference between linear and non-linear colorspaces.

I don't see why you would avoid talking about it. As far as I've understood, CRT monitor gamma has basically evolved to become the inverse of human eye gamma : http://poynton.ca/PDFs/Rehabilitation_of_gamma.pdf (With some changes for a less accurate, but more visually pleasing/exciting replication of brightness levels ?) Now, with many modern, digital screens (LCD, LED, e-ink?), as far as I've understood the electro-…

> I expected to have to do gamma correction when making a gradient recently, but in the end it looked like I didn't have to

If you don't explicitly specify the color space you're working in, then you're using some implicitly defined color space in which case you basically need to know what that is (at least roughly).

So traditionally in Windows, way back, when you created a bitmap, wrote some data to it and then drew it, there was no explicit mention of a color space. Instead it was implicit, and it was de-facto non-linear.

These days you can specify[1][2] the color space you're working in, and Windows will then transform the colors into the specified device color space. So then you can specify if you want to work in linear RGB space or say non-linear sRGB.

Unity has something similar[3], which affects how you write shaders, how your textures should be saved etc.

[1]: https://docs.microsoft.com/en-us/previous-versions/windows/d...

[2]: https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf...

[3]: https://docs.unity3d.com/Manual/LinearRendering-LinearOrGamm...

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#162
post #64

I am in the same boat as the author of having only recently played Return of the Obra Dinn between Christmas and new years. I cannot recommend it enough, if you haven't played it and like puzzlers you should pick it up. It's an extremely engaging story, and a narrative tool I have not previously encountered. No spoilers as this is revealed immediately, but essentially you are navigating past events through frozen tim…

May as well ask here, the ESRB rating at the bottom of the Obra Dinn page [1] highlights "intense violence". Is this accurate? I'm a big wimp about visceral violence, so I'd prefer to have some idea before paying up. If 1/4 of the crew got disemboweled or something, I'm probably out. [1] https://obradinn.com/

I have only played for a few hours, but all the violence (so far) has been communicated via sound effects during blacked out cut scenes (no visuals). The sound effects in the game are really well done and visceral, but otherwise you just see the low res frozen time ‘results’ of these cut scenes (e.g. a dead body under a cannon, a skeleton crushed and distorted, etc).

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#163

If you don't mind, I'll plug a little innovation of my own: mixing ordered and error diffusion dithering. The idea behind it is actually pretty simple: technically all forms of dithering use a threshold map, we just don't tend to think of it when it's one flat threshold for the entire image. So there is nothing stopping us from decoupling the threshold map from the rest of the dithering algorithm, meaning it's trivia…

I'll also plug an invention of my own: error diffusion with a random parameter in the diffusion matrix, keeping the sum of weights constant (and equal to 4/5, so boosting contrast slightly).

I came up with this for a Code Golf challenge a few years ago, personally I think it looks really good. I haven't seen it elsewhere.

Disclaimer: yes I like to write ugly Fortran code for fun (and profit).

https://codegolf.stackexchange.com/a/26569

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#164
post #81

> However, sRGB is not linear, meaning that (0.5,0.5,0.5) in sRGB is not the color a human sees when you mix 50% of (0,0,0) and (1,1,1). Instead, it’s the color you get when you pump half the power of full white through your Cathod-Ray Tube (CRT). While true, to avoid confusion, it might be better rephrased without bringing human color perception or even colors into the mix. sRGB uses non-linear (gamma) values, which…

Are you sure about sRGB being already good enough for averaging ? (As long as we don't want to go to a wider color space of course.) We have been recently taught how to do it 'properly', and we had to go through CIELAB 76 (which, AFAIK, is still an approximation, as human perception is actually non-euclidean).

If you want physically accurate averaging (resize, blur etc), then RGB is fine, as long as you use linear values (or do long-winded transformed math). AFAIU it is by definition 100% physically accurate. As was said, sRGB uses gamma values, where typical math creates ill effects, as in many if not most typical programs.

If you want to do perceptually uniform averaging of colors, color mixing / generating / artistic effects, that's something else entirely.

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#165

Earlier quoted context omitted.

May as well ask here, the ESRB rating at the bottom of the Obra Dinn page [1] highlights "intense violence". Is this accurate? I'm a big wimp about visceral violence, so I'd prefer to have some idea before paying up. If 1/4 of the crew got disemboweled or something, I'm probably out. [1] https://obradinn.com/

I have only played for a few hours, but all the violence (so far) has been communicated via sound effects during blacked out cut scenes (no visuals). The sound effects in the game are really well done and visceral, but otherwise you just see the low res frozen time ‘results’ of these cut scenes (e.g. a dead body under a cannon, a skeleton crushed and distorted, etc).

To be safe: There is some more graphic violence, but due to the dithering it’s not very offensive imo. However, pretty much the entire crew does die rather brutal deaths (and that’s what the plot of the game is centered around).

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#166
I'm surprised the algorithm for producing blue noise is so complicated.

Could you not generate white noise, then apply a high-pass filter? Say, by blurring it and then subtracting the blurred version from the original?

Could you split the map into blocks, fill each block with a greyscale ramp, then shuffle the pixels inside the block?

Could you take a random sudoku approach, where you start with a blank map, then randomly select pixels, look at the distribution of pixels in their neighbourhood, randomly pick one of the greyscale values not present (or least present) for that pixel, then repeat?

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#167

If you don't mind, I'll plug a little innovation of my own: mixing ordered and error diffusion dithering. The idea behind it is actually pretty simple: technically all forms of dithering use a threshold map, we just don't tend to think of it when it's one flat threshold for the entire image. So there is nothing stopping us from decoupling the threshold map from the rest of the dithering algorithm, meaning it's trivia…

I'll also plug an invention of my own: error diffusion with a random parameter in the diffusion matrix, keeping the sum of weights constant (and equal to 4/5, so boosting contrast slightly). I came up with this for a Code Golf challenge a few years ago, personally I think it looks really good. I haven't seen it elsewhere. Disclaimer: yes I like to write ugly Fortran code for fun (and profit). https://codegolf.stackex…

That is a very elegant trick, I love it! I wonder what comes out of that when applied to a flat grayscale image - perhaps it leads to a decent blue noise pattern, or an approximation of it? EDIT: The reason I'm half-expecting that is because semi-randomizing the diffusion matrix reminds me a bit of Bridson's Algorithm, in that it mixes constraints with randomization[0].

And kudos for sticking to the programming language you love and feel comfortable in :)

EDIT: Something I never noticed before: a black and white dithered image causes flickering when scrolling on an LCD screen, as least on mine, and it amplifies regions with patterns, like the checkerboards in ordered dithering, or the regular artifacts like in the example image of the challenge.

However, your "randomized Sierra Lite" version seems to mask that flickering: it's still there, but feels much more like white noise that is relatively easy to ignore.

[0] https://observablehq.com/@techsparx/an-improvement-on-bridso...

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#168

Earlier quoted context omitted.

I don't see why you would avoid talking about it. As far as I've understood, CRT monitor gamma has basically evolved to become the inverse of human eye gamma : http://poynton.ca/PDFs/Rehabilitation_of_gamma.pdf (With some changes for a less accurate, but more visually pleasing/exciting replication of brightness levels ?) Now, with many modern, digital screens (LCD, LED, e-ink?), as far as I've understood the electro-…

> I expected to have to do gamma correction when making a gradient recently, but in the end it looked like I didn't have to If you don't explicitly specify the color space you're working in, then you're using some implicitly defined color space in which case you basically need to know what that is (at least roughly). So traditionally in Windows, way back, when you created a bitmap, wrote some data to it and then drew…

Yes, and in almost all of these discussions, the implicit color space is (non-linear) sRGB. (IIRC Macs might have used a different default color space one-two decades ago ?)

Also, I'm on Linux, and doing picture manipulation with Octave, but thank you for the links anyway !

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#169
post #166

I'm surprised the algorithm for producing blue noise is so complicated. Could you not generate white noise, then apply a high-pass filter? Say, by blurring it and then subtracting the blurred version from the original? Could you split the map into blocks, fill each block with a greyscale ramp, then shuffle the pixels inside the block? Could you take a random sudoku approach, where you start with a blank map, then ran…

The first technique is challenging because the filter needs to have a specific frequency response, without shortcuts. Such high quality filtering can be done more simply and more exactly with an inverse Fourier transform.

The second technique doesn't seem promising because shuffling is very crude: differently shuffled small blocks are going to have border artifacts, repeating small blocks are going to have worse periodic artifacts, large blocks are going to approximate white noise rather than blue noise. Higher quality would require precomputing blue noise images, losing the advantage of on-the-fly computation.

The third technique, being sequential, is unlikely to be practically cheaper than an inverse Fourier transform.

Re: Ditherpunk: The article I wish I had about monochrome image dithering

#170

Tangential, but when I view certain dithered images in that article and on the demo page, my entire monitor drops in brightness by a bit. As soon as I scroll away, the monitor returns to normal brightness. I wonder if this is a result of hardware or something on the software / driver side.

Probably dynamic contrast ratio by graphic driver and/or monitor that is tricked/triggered by unusual dithered patterns during scrolling.
Post reply on HN