色彩空间,伽玛和图像增强 [英] Color spaces, gamma and image enhancement

查看:113
本文介绍了色彩空间,伽玛和图像增强的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

色彩空间.好吧,每个人都知道RGB:在[0.0,1.0]范围内归一化的三个值,它们具有颜色成分Red Green Blue的强度的含义;这个强度是线性的,不是吗?

Color space. Well, everybody knows about RGB: three values normalized in the range [0.0,1.0], which have the meaning of the intensity of the color components Red Green Blue; this intensity is meant as linear, isn't?

伽玛.据我了解,gamma是将RGB颜色分量映射到另一个值的函数.谷歌搜索,我已经看到了线性函数和非线性函数... 线性函数似乎可以缩放RGB分量,因此似乎可以调整图像的亮度.非线性函数似乎可以解压缩"较暗/较亮的组件.

Gamma. As far I can understand, gamma is a function which maps RGB color components to another value. Googling on this, I've seen linear functions and non linear functions... Linear functions seems to scale RGB components, so it seems to tune image brightness; non linear functions seems to "decompress" darker/lighter components.

现在,我开始实现图像查看器,它将显示不同的图像格式作为纹理.我想修改这些图像的灰度系数,因此我应该构建一个片段着色器并在带纹理的四边形上运行.很好,但是如何确定正确的伽玛校正?

Now, I'm starting to implement an image viewer, which shall display different image formats as texture. I'd like to modify the gamma of these images, so I should build up a fragment shader and run over the textured quad. Fine, but how do I determine the right gamma correction?

OpenGL使用浮点组件使用线性RGB颜色空间.确实,我可以从这些值(具有特殊的浮点精度)开始计算经过伽马校正的值,因此在钳位经过伽马校正的值之后便会显示它们.

OpenGL works using linear RGB color space, using floating point components. Indeed, I could compute gamma-corrected values starting from those values (with special floating point precision), so they are displayed after having clamped the gamma-corrected value.

首先,我将确定伽玛斜率.我如何确定呢? (从语法上或使用查找表)

First, I shall determine the gamma ramp. How could I determine it? (analitically or using lookup tables)

然后,我开始研究OpenGL扩展名EXT_framebuffer_sRGB,该扩展名与扩展名 EXT_texture_sRGB .

Then, I came up to investigate on the OpenGL extension EXT_framebuffer_sRGB, which seems very related with the extension EXT_texture_sRGB.

EXT_texture_sRGB引入了一种新的纹理格式,该格式用于将textel值线性化为RGB线性空间. (脚注1)这样,我就知道了sRGB色彩空间并将其用作线性RGB色彩空间.

EXT_texture_sRGB introduce a new texture format which is used to linearize textel values into RGB linear space. (footnote 1) In this way, I'm aware of sRGB color space and use it as linear RGB color space.

相反,EXT_framebuffer_sRGB扩展使我可以将线性RGB值编码到sRGB帧缓冲区中,而不必担心.

Instead, EXT_framebuffer_sRGB extension allows me to encode linear RGB values onto the sRGB framebuffer, without worrying about it.

...

等等,所有这些信息有什么用?如果我可以使用sRGB帧缓冲区并加载sRGB纹理,请在不进行sRGB转换的情况下处理该纹理...为什么我应该更正伽玛?

Wait, all this information for what? If I can use sRGB framebuffer and load sRGB textures, process that textures without sRGB conversions... why should I correct gamma?

也许即使在sRGB缓冲区上,我也可以全部校正伽玛吗?还是我最好不要?亮度和对比度:它们应在伽玛校正之前还是之后应用?

Maybe can I correct gamma all the same, even on a sRGB buffer? Or I better not? And brightness and contrast: shall they applied before or after gamma correction?

很多信息,我现在很困惑.希望你们中的一些人能向我解释所有这些概念!谢谢.

That's a lot of information, I'm getting confused now. Hope that someone of you can explain me more all these concepts! Thank you.

...

还有另一个问题.如果设备的伽玛值不同于标准" 2.2,我如何累积"不同的伽玛校正值?我不知道是否很清楚:如果伽玛值为2.2的显示器的图像RGB值已经被校正,但是显示器的伽玛值为2.8,我该如何校正伽玛?

There's another question. In the case the device gamma is different from the "standard" 2.2, how do I "accumulate" different gamma corrections? I don't know if it is clear: in the case image RGB values are already corrected for a monitor with a gamma value of 2.2, but the monitor has a gamma of value 2.8, how to I correct gamma?

(1)以下是一些摘录,以突出我的意思:

(1) Here is some extract to highlight what I mean:

sRGB色彩空间基于典型(非线性)监视器 在昏暗的办公室中预期的特征.它一直 由国际电工委员会(IEC)标准化 符合IEC 61966-2-1. sRGB色彩空间大致对应于2.2 伽玛校正.

The sRGB color space is based on typical (non-linear) monitor characteristics expected in a dimly lit office. It has been standardized by the International Electrotechnical Commission (IEC) as IEC 61966-2-1. The sRGB color space roughly corresponds to 2.2 gamma correction.


此扩展程序是否提供任何类型的sRGB帧缓冲格式 或保证使用sRGB纹理渲染的图像将看起来不错" 当输出到支持sRGB色彩空间的设备时?

Does this extension provide any sort of sRGB framebuffer formats or guarantee images rendered with sRGB textures will "look good" when output to a device supporting an sRGB color space?

   RESOLVED:  No.

  Whether the displayed framebuffer is displayed to a monitor that
    faithfully reproduces the sRGB color space is beyond the scope
    of this extension.  This involves the gamma correction and color
    calibration of the physical display device.

    With this extension, artists can author content in an sRGB color
    space and provide that sRGB content for use as texture imagery
    that can be properly converted to linear RGB and filtered as part
    of texturing in a way that preserves the sRGB distribution of
    precision, but that does NOT mean sRGB pixels are output
    to the framebuffer.  Indeed, this extension provides texture
    formats that convert sRGB to linear RGB as part of filtering.

    With programmable shading, an application could perform a
    linear RGB to sRGB conversion just prior to emitting color
    values from the shader.  Even so, OpenGL blending (other than
    simple modulation) will perform linear math operations on values
    stored in a non-linear space which is technically incorrect for
    sRGB-encoded colors.

    One way to think about these sRGB texture formats is that they
    simply provide color components with a distribution of values
    distributed to favor precision towards 0 rather than evenly
    distributing the precision with conventional non-sRGB formats
    such as GL_RGB8.

推荐答案

不幸的是,OpenGL本身并没有定义色彩空间.刚刚定义传递给OpenGL的RGB值形成线性向量空间.然后,将渲染的帧缓冲区的值按原样发送到显示设备. OpenGL只是通过该值.

Unfortunately OpenGL by itself doesn't define a colour space. It's just defined that the RGB values passed to OpenGL form a linear vector space. The values of the rendered framebuffer are then sent to the display device as they are. OpenGL just passes through the value.

伽玛服务于两个目的:

  • 感觉感知是非线性的
  • 过去,显示设备具有非线性响应

伽玛校正用于补偿这两种情况.

The gamma correction is used to compensate for both.

变换只是线性值V到某个幂Gamma",即y(v)= v ^ gamma

The transformation is just "linear value V to some power Gamma", i.e. y(v) = v^gamma

色彩空间转换涉及从输入值到发送到显示器的内容的完整链,因此其中包括伽玛校正.这也意味着您不应该自己操纵伽玛斜率.

Colorspace transformations involve the complete chain from input values to whats sent to the display, so this includes the gamma correction. This also implies that you should not manipulate the gamma ramp youself.

很长时间以来,典型的Gamma值曾经是2.2.但是,这导致了一些不希望的低值量化,因此Adobe引入了一种新的色彩空间,称为sRGB,它具有低值的线性部分和幂函数,高值的指数函数约为2.3.如今,大多数显示设备都使用sRGB.同样,这些天大多数图像文件都在sRGB中.

For a long time the typical Gamma value used to be 2.2. However this caused some undesireable quantisation of low values, so Adobe introduced a new colour space, called sRGB which has a linear part for low values and a powerfunction with exponential ~2.3 for the higher values. Most display devices these days use sRGB. Also most image files these days are in sRGB.

因此,如果您有sRGB图像,并在sRGB显示设备上按原样显示它,并且该设备上配置了线性伽马斜率(即视频驱动程序gamma = 1),则只需使用sRGB纹理和帧缓冲就可以了而不做其他任何事情.

So if you have a sRGB image, and display it as-is on a sRGB display device with a linear gamma ramp configured on the device (i.e. video driver gamma=1) you're good by simply using sRGB texturing and framebuffer and not doing anything else.

由于评论而编辑

总结一下:

  • 使用ARB_framebuffer_sRGB帧缓冲区,以便驱动程序将所有颜色输入线性化到OpenGL

    Linearize all colour inputs to OpenGL

    sRGB颜色空间中的纹理应通过EXT_texture_sRGB http://www.opengl.org/registry/specs/EXT/texture_sRGB.txt

    Textures in sRGB colour space should be passed through EXT_texture_sRGB http://www.opengl.org/registry/specs/EXT/texture_sRGB.txt

    请勿使用伽玛校正输出值(sRGB格式的帧缓冲区将对此进行处理)

    Don't gamma correct the output values (the sRGB format framebuffer will take care of this)

    如果您的系统不支持sRGB帧缓冲区:

    If your system does not support sRGB framebuffers:

    • 在显示设备上设置线性色带.

    • Set a linear colour ramp on your display device.

    • Windows http://msdn.microsoft.com/en-us/library/ms536529(v=vs.85).aspx
    • X11 can be done though xgamma http://www.xfree86.org/current/xgamma.1.html

    创建(线性)帧缓冲对象,以在帧缓冲对象中进行线性渲染.为了适当地进行混合,FBO的使用仅在线性色彩空间中有效.

    create (linear) framebuffer objects, to linear rendering in the framebuffer object. The use of a FBO is, to properly to blending, which only works in linear colour space.

    使用片段着色器将最终的渲染结果从FBO绘制到窗口,该片段着色器将应用所需的颜色(伽玛和其他)校正.

    draw the final render result from the FBO to the window using a fragment shader that applies the desired colour (gamma and other) corrections.

    这篇关于色彩空间,伽玛和图像增强的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆