设计与产品4p8.com
所有图像编辑软件的缩放都错了
All image-editing software gets scaling wrong
2010 — 2014,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这篇文章解释图像缩放时若忽略 gamma(伽马)校正,会在缩小时造成亮度、对比度错误,并称多数图像编辑软件因此把缩放做错。作者用示例说明正确做法,但评论指出 gamma 处理并非绝对,是否该转换取决于图像数据和整条处理流水线。
为什么经久不衰:它把日常图像工具里一个隐蔽的 gamma 假设讲清楚,多年后仍提醒读者:像素数值并不等于线性亮度。
HN 评论精选
gamma 不是简单的对错问题,孤立地做转换可能反而有害。
并不是说 gamma-aware 就“正确”,而多数软件为了速度就“错”。很多场景下 RGB 值本身并没有关联 gamma,就像它们没有 ColorSync 配置文件;即使有,也可能只是处理某个阶段随意引入的。对图像编辑器来说,用当前屏幕 gamma 会相当任意。如果你的整条流水线不遵循这套理念,或者更糟,只有 Photoshop 或 PNG 这么做,那么在处理中尝试在不同 gamma 值之间“转换”可能弊大于利。
dgreensp查看英文原文
It's not that being gamma-aware is "right" and most software does it "wrong" for speed. In many contexts, RGB values don't have gamma associated with them, just as they don't have ColorSync profiles or whatnot, or if they have one, it was just invented at some stage of processing. (Using the current screen gamma would be pretty arbitrary for an image editor.) Trying to "convert" between different gamma values during processing likely will do more harm than good if your entire pipeline doesn't have this philosophy, or worse, if only one program (e.g. Photoshop) or format (e.g. PNG) does. I suppose PNG files win a prize for carrying gamma information, so that web browsers and image viewers can apply a curve in software that throws off their brightness and contrast relative to everything around them? And when Photoshop decides the colors in my GIF file need to be "converted" to sRGB from god-knows-what it thinks they were before? If you want every last image operation to be done with perceptual accuracy, convert your images to some fancy color space like CIELAB, after careful consideration of their intended source gamma and color space, and do your calculations there; then somehow be sure they are accurately converted for display on the user's monitor.
忽略 gamma 曾是 32 位时代的重要性能取舍,如今做正确重采样已便宜很多。
我写了 Picasa 使用的 Lanczos3 缩放器(大约 14 年前!),它默认不校正 gamma。对大多数图像和核,在约 31 位总精度内做运算就够(留一位做下溢钳制),所以在老 32 位架构上忽略 gamma 就是那个神奇的速度优化。如果做 gamma 校正,变换后源图像需要 10–12 bpc,大核还需要超过 32 位的整数精度。x86 有 32x32 到 32 位高字的乘法,但这一切在 x64 上会好得多。所以今天在 64 位机器或宽 SIMD 上,gamma 正确的重采样比十年前便宜得多。补充:最终在线条艺术上能看出差别,但对大多数照片,你更愿意把 CPU 预算花在锐度上(使用更宽的核)。
herf查看英文原文
I wrote the Lanczos3 scaler that Picasa uses (about 14 years ago!), and it doesn't (by default) correct for gamma. For most images & kernels, you can get by with doing math in about 31 bits total precision (a bit for underflow clamping), so that's the magic speed improvement from ignoring gamma on old 32-bit architectures. If you gamma-correct, your sources will need to be 10-12 bpc after transformation, and you'll need >32 bits of integer precision for large kernels. Even though x86 has a 32x32 -> 32bit high word multiply, this all gets a lot better on x64. So basically: today on 64-bit machines (or wide SIMD) you could do gamma-correct resampling a whole lot cheaper than you could do 10 years ago. [edit] In the end you notice the difference with line art, but for most photographs you want to spend spend your CPU budget on sharpness (by using wider kernels).
科学数据通常来自线性传感器且很少缩放,所谓影响被夸大了。
我认为说这会影响科学数据有点危言耸听。我处理的大多数数据来自 CCD,我几乎可以肯定其输入亮度和像素值之间是线性关系。更重要的是,我几乎不会缩小图像,除非为了发表,而到那时通常已经调整过亮度和对比度了。
rflrob查看英文原文
I think the claim that this will affect scientific data is a little alarmist. Most of the data I work with comes from a CCD, which Im almost certain has a linear scale between input brightness and pixel value. But more importantly, I wouldn't ever scale my images down, except possibly for publication, and by that point, I've usually tweaked the brightness and contrast anyways.
图像算法设计者应掌握基础色度学,以免犯这类错误。
任何设计图像处理算法的人都至少应该对色度学和颜色感知有基本了解。这绝对不难理解,但也并不平凡。我只能建议读 [1]。那本书相当厚,但你只需要读前几章,就能避免这类错误。
leni536查看英文原文
Anyone who designs algorithms dealing with image manipulation should have at least a basic understanding of colorimetry and color perception. It's absolutely not hard to understand but it is not trivial either. I can only suggest to read [1]. It's a rather thick book but you only need to read the first few chapters to avoid such mistakes. [1] Wyszecki, Stiles: Color science
历次讨论
同类还值得读
贝塞尔曲线入门
A Primer on Bézier Curves
Pomax 编写的贝塞尔曲线在线教程,从基础概念一路讲到曲线求交、投影、曲率等进阶内容,并配有可交互的示例和配套的 bezier.js 库。
设计与产品上首页 7 次 · 2014–2022pomax.github.io编辑精选WebGL 水面模拟
WebGL Water
Evan Wallace 制作的 WebGL Water 演示:在浏览器里实时渲染一片水面,展示折射、反射和焦散等 GPU 图形效果。
设计与产品上首页 6 次 · 2011–2025madebyevan.com设计建议:永远不要使用黑色
Design Tip: Never Use Black
设计随笔提出“永远不要用纯黑”的建议,主张在界面和绘画中改用深灰或带色相的暗色,并借阴影与色彩关系来论证。
设计与产品上首页 5 次 · 2012–2021ianstormtaylor.com用于思考不可想象之物的媒介
Media for Thinking the Unthinkable
Bret Victor 的这个页面围绕《Media for Thinking the Unthinkable》展开,探讨我们用来思考和表达复杂问题的媒介,以及以文字/符号为主的传…
设计与产品上首页 5 次 · 2013–2020worrydream.com编辑精选页面重量很重要
Page Weight Matters
博文讲 YouTube 工程师 Chris Zacharias 的一次页面瘦身实验:团队做了一个更轻量的页面版本,起初从整体平均加载时间看反而更慢;按地理区域分层后才发现,轻量版…
设计与产品上首页 4 次 · 2012–2022blog.chriszacharias.com