如何缩放图像中的像素以调整亮度?
我有一张照片的灰度图像。我已经确定图像的某些部分照明不足,并且亮度 Y = 0.8 的像素实际上应该调整为 90% 灰色,即该像素的亮度应该为 0.9。我的问题是如何缩放附近的其他像素?我很确定将所有亮度乘以 9/8 是错误的,因为我隐约记得听到这个是为了看起来 均匀,缩放必须是非线性的。但我很难找到一个能让我取得进步的方程式。 (当然,我实际上正在编写一个程序来对大量照片进行这种调整。)
我的像素的来源是 pbmplus PGM 格式,手册页对此说道:
每个灰度值都是与强度成正比的数字 像素,由 CIE Rec 调整。第709章 伽马传递函数。 (那 传递函数指定伽马数为 2.2,并且具有线性 小强度部分)。因此,零值是黑色的。 Maxval的值代表CIE D65白色最强烈的值 在该图像以及可能与该图像进行比较的任何其他图像中。
如果我更好地理解这一点,我可能会更好地知道如何继续。
我发现了一个关于制作亮度均匀的图像的相关问题。
感谢 Shmoopty 让我走上正轨。我接受了你的答案,然后添加了一些信息。
I have a grayscale image from a photograph. I've determined that certain parts of the image are underilluminated, and that a pixel with luminance Y = 0.8 should actually be adjusted to 90% grey, i.e., that pixel should be given luminance 0.9. My question is how do I scale the other pixels nearby? I'm pretty sure multiplying all the luminances by 9/8 is wrong, because I vaguely remember hearing that in order to look uniform, the scaling has to be nonlinear. But I'm having trouble finding an equation that would enable me to make progress. (Of course I am actually writing a program to make this adjustment to a great many photographs.)
The source of my pixels is the pbmplus PGM format, about which the man page says:
Each gray value is a number proportional to the intensity of the
pixel, adjusted by the CIE Rec. 709 gamma transfer function. (That
transfer function specifies a gamma number of 2.2 and has a linear
section for small intensities). A value of zero is therefore black.
A value of Maxval represents CIE D65 white and the most intense value
in the image and any other image to which the image might be compared.
If I understood this better I would probably have a better idea how to proceed.
I found a related question on making an image of uniform brightness.
Thanks Shmoopty for getting me on track. I accepted your answer then added some info to it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要伽玛校正,这将保持纯黑和纯白正确,同时弯曲之间的值。
当输入在 (0.0, 1.0) 范围内时,伽玛调整的公式为:
...其中
gamma
当小于 1.0 时将变亮,当高于 1.0 时将变暗。要将 0.8 推至 0.9,您需要计算
log(0.9)/log(0.8)
以获得 0.4722。请注意,这是众多公式之一 - 而且它是数学上最简单的公式,它将保留黑色和白色作为独特的颜色(有些人认为这很重要) - 然而没有一个正确的公式可以告诉你“ true”。
附录:我验证了伽玛校正可以应用于已经伽玛编码的值。很难在 Markdown 中记下数学,但关键的代数定律是
如果应用该定律,则可以确定伽玛校正可交换,因此可以将伽玛校正应用于已经校正的值。 —NR
You probably want gamma correction, which will keep true black and true white correct, while bending the values in between.
The formula for gamma adjustment, when input is in the range (0.0, 1.0) is:
...where
gamma
will lighten when less than 1.0 and darken when above 1.0.To push 0.8 up to 0.9, you compute
log(0.9)/log(0.8)
to get a gamma of 0.4722.Note that this is one of very many formulas -- and it is the mathematically simplest that will preserve black and white as unique colors (which some would consider important) -- however there is no single correct formula to give you what's "true".
Addendum: I verified that the gamma correction can be applied to values that are already gamma-encoded. It's hard to notate the math in markdown, but the key algebraic law is
If you apply this law, you can determine that gamma corrections commute, so it is OK, to apply the gamma correction to already corrected values. —NR