如何自动校正图像中的颜色?
我将使用一组任意图像。 其中一些可能需要一些色彩校正。
我在 Photoshop 中打开了一张需要修正的图像 并注意到直方图中的黄色有点高。 我应用了自动颜色,这改善了图像。
这是如何运作的?如何实施? 我是否在直方图中寻找峰值并根据 其他山峰?
语言/语法应该不重要。
I will work with a set of arbitrary images.
Some of them might need some color correction.
I've opened up an image that needed correction in Photoshop
and noticed the yellows were a bit high in the Histogram.
I applied Auto Color and that improved the image.
How does that work ? How implement that ?
Do I look for peaks in the histogram and average them based on the
other peaks ?
The language/syntax shouldn't matter much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不容易,确实需要实践和艺术,但这是理论。
Photoshop 和 Picasa 等工具具有一键自动色彩校正功能。它必须对平均颜色分布应该是什么做出假设,并且它们可能适用于 Lab 颜色空间,而不是您熟悉的 RGB 颜色空间。由于该方法是启发式的,因此对于某些图像会出现错误。例如,如果您在明亮但被遮蔽的森林中拍摄图像,环境光具有明显的绿色色偏,您根本无法摇动颜色以使白色物体变白,因为您必须太用力地推入红色,从而搞砸了例如,绿色衬衫。同样,午后橙色阳光下的图像也有偏黄的倾向,要纠正这一点,就会过度偏向蓝色。自动颜色模式中可能有停止值以避免过度补偿。
现在,Lab 色彩空间是一个奇怪的野兽,几乎有整本关于它的书。它是一个三通道空间,其中一个通道上有亮度(这是最简单的通道),而这些通道与我们思考颜色的方式几乎没有联系,因此它们被简单地称为“a”和“b”。 a 和 b 通道以可粗略地称为黄-蓝和绿-红的维度对所有色度数据(除亮度之外的所有数据)进行编码。还有一个奇怪的地方,Lab 的色域远远大于我们的眼睛可以处理的范围(RGB 和 CMYK 都小于我们的视觉色域),产生不可能的颜色,例如深度饱和的红色,几乎没有亮度。我们可以描述它,但随着亮度的降低,我们的感知会失去颜色(这就是为什么夜间让一切呈现蓝灰色的外观)。
那么你会如何通过算法来做到这一点呢?首先,您需要真正理解感知模型,将图像转换为感知空间,根据相当复杂的法线期望调整双轴分布,然后将结果投射回 RGB 空间,以便可以渲染。是的,这可以在袖珍相机中实现,但它并不简单,并且通常需要提示(例如,将预期色温设置为阳光或阴影、钨丝光或荧光灯等)。如果没有人工指导,算法会更频繁地出错,并且如果不手动屏蔽某些色偏(例如绿色森林),就无法在整个图像上令人满意地完成这些色偏。
太长了;博士
It isn't easy and it does take practice and art, but here's the theory.
Tools like Photoshop and Picasa have automatic color correction on one button. It has to make assumptions about what the mean color distributions ought be and they probably work in the Lab color space rather than the RGB colorspace that you are familiar with. Since the approach is heuristic, it will get it wrong for some images. For example, if you take images in a bright yet shrouded forest, the ambient light has a decided green cast and you simply cannot jiggle the colors to make a white object white because you'd have to push too hard into the red thus screwing up, for example, a green shirt. Similarly, images in from the late afternoon orange sun are yellow biased and to correct that pushes too hard into the blue. There may be stop values in the auto-color modes to avoid over compensation.
Now Lab colorspace is a strange beast and there are literally entire books about it. It is a three channel space with Luminance on one channel (that's the easy one) and channels that have so little connection to the way we think of color that they are simply called "a" and "b". The a and b channels encode all the chromaticity data (everything that isn't Luminance) in dimensions that could be roughly called yellow-blue and green-red. Here's another weirdness, the gamut of Lab is far bigger than our eyes can handle (RGB and CMYK are both smaller than our visual gamut) yielding colors that are impossible, for example a deeply saturated red with almost no Luminance. We can describe it, but our perception drops color out as Luminance decreases (which is why nighttime give everything a blue-grey appearance).
So how would you do so algorithmically? First, you need to really understand the perceptual models, transform the images into a perceptual space, adjust the bi-axial distribution according to pretty complicated expectations of normal and then cast the result back into an RGB space so it can be rendered. Yes, this can be implemented in a pocket camera, but it is non-trivial and often needs hints (e.g. setting the expected color temperature to sunny or shaded, tungsten, or fluorescent, etc.). Absent human guidance algorithms will be wrong more often, and without hand masking some color casts like the green forest can't be done pleasingly on an image as a whole.
tl;dr
简单的算法可能如下所示:
计算直方图(https://en.wikipedia.org/wiki /Histogram)
查找直方图中值小于最高值 1% 的最低点 (a) 和最高点 (b)。
将亮度调整到直方图的中心。将颜色值乘以 256/(a+b)
调整对比度以将直方图从 0 扩展到 255。将颜色值乘以 127/(bb-128),其中 bb 是 b 乘以亮度值。
这是非常简单的算法,但我认为这是许多程序中发生的情况。此外,程序可能会针对饱和度做一些事情。
Simple algorithm could look like this:
Calculate histogram (https://en.wikipedia.org/wiki/Histogram)
Find lowest (a) and highest points (b) in histogram where values are less than 1% than highest value.
Adjust brightness to center histogram. Multiply color values by 256/(a+b)
Adjust contrast to spread histogram from 0 to 255. Multiply color values by 127/(bb-128), where bb is b multiplied by brightness value.
This is very simplistic algorithm but I think this is what happens in many programs. Additionally programs might do something about saturation.