``` 抖动 – 第一部分 ```
Dithering – Part 1

原始链接: https://visualrambling.space/dithering-part-1/

这篇文章解释了迷人的**抖动**过程,这是一种用于创造*看起来*比实际可用的颜色更多的技术的手段。具体来说,它着重介绍了抖动如何使用只有黑白像素来模拟灰度阴影。 与简单地将像素映射到最接近的可用颜色(导致生硬的过渡)不同,抖动策略性地以图案分布黑白像素。更密集的黑色浓度产生更深的阴影,而更密集的白色浓度产生更浅的阴影。 一种方法,**有序抖动**,利用**阈值图**——一个将每个像素的亮度与设定的值进行比较的网格。如果像素比阈值亮,它就变成白色;否则,变成黑色。在整个图像上重复此过程,通过不同的像素密度来重现阴影。 本质上,抖动不是*添加*效果,而是巧妙地*移除*颜色信息,同时保留整体视觉外观。这是三部分系列文章的第一部分,未来将计划探索不同的抖动算法,例如阈值图创建和误差扩散。

## 抖动解释:黑客新闻总结 最近黑客新闻上出现了一场关于抖动(visualrambling.space)的讨论,该内容以视觉化的方式呈现。文章的展示广受好评,但也引发了关于什么才是真正的“抖动”,以及与半调等相关技术的区别的争论。 一些人认为,文中展示的技术,使用图案来*看起来*增加颜色深度,并非真正的抖动,他们将抖动定义为在颜色调色板有限的情况下,使用噪声来平滑颜色分层。另一些人则指出,定义中包含有序抖动也是一种抖动形式,即使没有明确的噪声。 讨论延伸到抖动的历史和细微之处,提到了早期Windows界面和现代应用程序(Squoosh.app、GIMP)中使用的技术,甚至包括游戏开发(Obra Dinn、Quake纹理)。 许多用户分享了资源,包括Rust和Go中的代码实现,以及来自Coding Train等来源的相关YouTube解释链接。 最终,这场讨论突出了颜色表示的复杂性,以及对创造*看起来*比实际可用的更多色调的技术的持续迷恋。
相关文章

原文

Understanding how dithering works, visually.

tap/click the right side of the screen to go forward →

I’ve always been fascinated by the dithering effect. It has a unique charm that I find so appealing.

← tap/click the left side to go back

I was even more amazed when I learned how dithering works.

← or use arrow keys to navigate →

Look closely, and you’ll see this animation is made of alternating black and white pixels.

But these black and white pixels are specifically arranged to create the illusion of multiple shades.

That’s what dithering does: it simulates more color variations than what are actually used.

Here, it uses black and white to give the impression of multiple gray shades.

To me, dithering is about creating the most out of what we have, and that's what amazes me the most!

It inspired me to learn more about it, and now I want to share what I’ve learned.

Please note that this is just part one out of three, so I’ll only scratch the surface here.

I’ll go deeper in the next parts, which will come soon. Stay tuned!

First, let’s explore the dithering basics with this grayscale image example.

A grayscale image has various gray shades, from black to white.

Imagine a display that only shows black or white pixels, no grays. We must turn some pixels black and others white—but how?

One way is to map each pixel to the closest available color.

Pixels darker than medium gray turn black and lighter ones turn white.

This splits pixels into black or white groups.

However, this creates a harsh image with abrupt black-white transitions.

Shadow details vanish as gray pixels become fully black or white.

Dithering fixes this by selectively pushing some pixels towards the opposite color.

Some light gray pixels that are closer to white turn black.

Likewise, some dark grays turn white.

And it's done in a way that produces special patterns which simulate shades by varying the black-and-white pixel densities.

Denser black pixels are used in darker areas, while denser white pixels are used in lighter ones.

Next question: How are these patterns generated?

One simple dithering method, known as ordered dithering, uses a threshold map.

A threshold map is a grid of values representing brightness levels, from 0 (darkest) to 1 (brightest).

To dither, we compare each input pixel’s brightness to a corresponding threshold value.

If a pixel’s brightness exceeds the threshold (it’s brighter than the threshold), the pixel turns white. Otherwise, it turns black.

Repeating this for all pixels gives us the black-and-white dither patterns.

The threshold map is designed to output patterns where the black-and-white pixel density matches the input image’s shades.

So brighter input produces patterns with more white, while darker input produces more black.

These black-and-white density variations are what create the illusion of gray shades when viewed from a distance.

To dither larger images, we extend the threshold map to match the image size and follow the same principle:

Compare each pixel’s brightness to the threshold map, then turn it black or white accordingly.

The image now uses only two colors, but its overall appearance is preserved.

The variations in shades are now replaced by variations in black/white pixel density of the dithering patterns.

And that’s how dithering works in a nutshell: it replicates shades with fewer colors, which are strategically placed to maintain the original look.

I find it a bit ironic how I used to think dithering ‘adds’ a cool effect, when what it actually does is ‘remove’ colors!

That's all for now! We’ve reached the end, but there’s still a lot more to explore.

For example, we haven’t explored the algorithm to create a threshold map. (spoiler: there are many ways!)

There’s also another algorithm called error diffusion, which doesn’t use a threshold map.

Each algorithm creates a distinct, unique look, which I believe deserves its own article.

And that's why I decided to break this series into three parts.

In the next part, I’ll dive into various algorithms for creating threshold maps.

In the final part, I’ll focus on the error diffusion algorithm.

We'll dive even deeper into dithering's mechanisms in these next 2 parts, so stay tuned!

Thank you for reading!

visualrambling.space is a personal project by Damar, someone who loves to learn about different topics and rambling about them visually.

If you like this kind of visual article, please consider following me on X/Twitter and sharing this with your friends.

I'll keep creating more visual articles like this!

https://x.com/damarberlari

_blank

联系我们 contact @ memedata.com