以与 Photoshop 中的 L 分量类似的方式增加图像亮度的公式是什么?
例如,我有一个具有以下值的像素:
CGFloat red = 34 // 0 - 255
CGFloat green = 128
CGFloat blue = 190
我想增加亮度,使蓝色为 255。 注意:“亮度”是指 LAB 色彩空间中 Photoshop 的 L 分量。看图片!
必须有一个特殊的公式来计算增加的亮度的 RGB 值,因为 RGB 值是以非线性方式修改的!
证明:我在 Photoshop 中进行了测试并创建了相同的颜色,然后打开颜色选择器进行检查:
然后我激活了 LAB 色彩空间的 L 分量,它控制亮度(至少这就是我所说的 - 我的意思是由该 L 分量控制的亮度。猜猜这就是亮度)。
因此,在激活 L 的情况下,我向上拖动左侧的滑块,直到 B 达到 255:
现在读取生成的 RGB 值:
CGFloat newRed = 112 // 0 - 255
CGFloat newGreen = 188
CGFloat newBlue = 255
这些值之间的差异是:
newRed - red = +78
newGreen - green = +60
newBlue - blue = +65
百分比是:
red shift: +38.42%
green shift: +29.55%
blue shift: +32.01%
这与已知的不符用于计算 RGB 亮度的公式,接近于亮度 = (red * 0.3) + (green * 0.6) + (blue * 0.1)
。
显然,它们已经以非线性方式移动。
是否有一种已知的方法可以以与 Photoshop 类似的方式从红、绿、蓝中计算出 newRed、newGreen、newBlue?
For example I have a pixel with these values:
CGFloat red = 34 // 0 - 255
CGFloat green = 128
CGFloat blue = 190
and I want to increase luminance so that blue is 255.
NOTE: With "Luminance" I mean the L-component of Photoshop in LAB color space. See pictures!
There must be a special formula to compute the RGB values for the increased luminance, because the R G B values are modified in a non-linear way!
Proof: I did a test in Photoshop and created this same color, and then opened the color picker to examine it:
Then I activated the L component of the LAB color space, which controls luminance (at least that is what I am talking about - I mean the brightness controlled by that L component. Guess that is luminance).
So with L activated, I dragged the slider on the left upwards until B reached 255:
Now read the resulting R G B values:
CGFloat newRed = 112 // 0 - 255
CGFloat newGreen = 188
CGFloat newBlue = 255
The differences between these is:
newRed - red = +78
newGreen - green = +60
newBlue - blue = +65
The percentages are:
red shift: +38.42%
green shift: +29.55%
blue shift: +32.01%
This does not correspond with the known formula for computing Luminance out of R G B, which is something close to luminance = (red * 0.3) + (green * 0.6) + (blue * 0.1)
.
Obviously, they have been shifted in a non-linear manner.
Is there a known way to compute newRed, newGreen, newBlue out of red, green, blue in a similar fashion how Photoshop does it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想将 RGB 颜色转换为 Lab 颜色空间吗?当然,这是可能的。
但有很多不同的标准都用通用名称“Lab”颜色来引用。您需要选择一种在编写算法时使用。特别是 Photoshop 使用 CIELAB D50 标准,因此如果您需要精确模拟其处理,则需要使用该标准。
您必须记住的另一件事是 RGB 模型设备相关,这意味着为了从 RGB 转换为 Lab,您首先需要从 RGB 转换为某种设备 -独立、绝对的色彩空间。 Adobe 使用“Adobe RGB”格式来实现此目的,但您可以使用 sRGB 等标准格式。调整过程考虑了 RGB 颜色的设备相关性,但将颜色转换为与设备无关的颜色。完成后,您可以执行最后一步,将颜色转换为 Lab 颜色空间。
维基百科文章提供了编写转换算法时的一些背景信息和有用的公式。 有人已经编写了这样的转换算法。您可能可以转换MATLAB 版。
根据您的认真程度(可能不是),您还可以下载 GIMP 的源代码并了解他们如何实现转换算法。他们的软件声称支持实验室空间。
不过,将返回转换为 RGB 时要小心。 Lab 色彩空间可以表示远远超出 sRGB 范围的颜色。即使在 Photoshop 中,一旦将图像转换回 RGB(或 CMYK),您在 Lab 模式中看到的大部分内容都会被丢弃。
编辑:还值得考虑的是,如果您的唯一目标是在比 RGB 更接近人类色彩感知的色彩空间中调亮颜色,那么您可能根本不需要为 Lab 烦恼。许多应用程序通过转换为 HSL 或 HSV 色彩空间来实现此目的。 (Photoshop 称为 HSV、HSB)。
优点是您可以简单地调整“亮度”或“值”值来改变颜色的强度(就像您在 Lab 颜色空间中调整“亮度”值一样),但转换算法要简单得多(并且通常内置于您选择的语言的标准库中)。
例如,请参阅我对此问题的回答< /a> 用于以 .NET 语言编写的转换算法。
So you want to convert an RGB color into the Lab color space? Sure, that's possible.
But there are a lot of different standards that are all referred to with the general name "Lab" color. You'll need to select one to use when writing your algorithm. Photoshop in particular uses the CIELAB D50 standard, so you would want to use that one if you need to accurately simulate its processing.
Another thing you have to keep in mind is that the RGB model is device-dependent, which means that in order to convert from RGB to Lab, you'll first need to convert from RGB into some device-independent, absolute color space. Adobe does this with their "Adobe RGB" format, but you can use something standard like sRGB. The adjustment process considers the device-dependence of the RGB color, but transforms the color into one that is device-independent. Once you have that, you can take the last step of transforming the color into the Lab color space.
The Wikipedia article provides some background information and useful formulas when writing a conversion algorithm. And here's someone that has already written such a conversion algorithm. And one for MATLAB you could probably convert.
Depending on how serious you are (so probably not), you could also download the source for GIMP and see how they've implemented the conversion algorithms. Their software claims to support the Lab space.
Be careful, though, when converting back to RGB. The Lab color space can represent colors that are well outside the range of sRGB. Even in Photoshop, most of what you see in Lab mode is discarded once you convert the image back to RGB (or CMYK).
Edit: It's also worth considering that if your only goal is to lighten a color in a color space that better approximates human color perception than RGB, you might not need to fuss with Lab at all. Lots of applications do this by converting to either the HSL or HSV color space. (Photoshop calls HSV, HSB).
The advantage is that you can simply adjust the "Lightness" or "Value" values to alter the intensity of the color (much like you would adjust the "Luminance" value in the Lab color space), but the conversion algorithms are much simpler (and often built into the standard libraries of your language of choice).
For example, see my answer to this question for a conversion algorithm written in a .NET language.