计算亮度时的常数k是多少

发布于 2025-01-12 23:14:34 字数 396 浏览 0 评论 0原文

我想使用 RGB 值计算图像的亮度,但在公式中有一个常数 ki 不知道它是什么,这是文档中的公式:

“在计算亮度 (L) 时,CIE Y 乘以一个常数值“k”,其中 k 对于摄像机来说可以是常数,也可以根据场景中所选区域的测量来确定场景。

L=k*(0,2127Red+0,7151Green+0,0722*Blue) (cd/m²)

这是文档的链接:https://faculty.washington.edu/inanici/Publications/LRTPublished.pdf 强调文本

I want to calculate the luminance of image using RGB value but in the formula there is a constant k i didn't know what it is this is the formula from the document:

"In calculating luminance (L), CIE Y is multiplied by a constant value ‘k’, where k can be either aconstant for the camera or determined for a scene based on a measurement of a selected region in the scene.

L=k*(0,2127Red+0,7151Green+0,0722*Blue) (cd/m²)

this is the link to the document:https://faculty.washington.edu/inanici/Publications/LRTPublished.pdf emphasized text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无需解释 2025-01-19 23:14:34

简短回答

您正在混淆仅适用于名为“Photosphere”的特定软件的内容,而数学不适用于一般亮度用途。

完整答案

你说:

使用RGB值计算图像的亮度

什么意思?某个给定像素的亮度?或者RMS平均亮度?或者???

并且:您的图像采用什么色彩空间(配置文件)?

我假设你的图像是 sRGB,每像素 8 位。但它可能是 P3 或 Adob​​e98,或任何其他数量......我将向您展示的数学是针对 sRGB 的。

1) 转换为浮点

每个 8 位 0-255 sRGB 颜色通道必须转换为 0.0-1.0

    let rF = sR / 255.0;
    let gF = sG / 255.0;
    let bF = sB / 255.0;

2) 转换为线性

必须删除传输曲线(又名“伽玛”)。对于 sRGB,“准确”方法是:

    function sRGBtoLin(chan) {
       return (chan > 0.04045) ? Math.pow(( chan + 0.055) / 1.055, 2.4) : chan / 12.92
    }

3) 计算亮度

现在,将每个线性化通道乘以适当的系数,然后将它们相加即可得出亮度。

  let luminance = sRGBtoLin(rF) * 0.2126 + sRGBtoLin(gF) * 0.7152 + sRGBtoLin(bF) * 0.0722;

额外奖励:Andy 的 Down and Dirty 版本

这是一个替代方案,仍然非常准确,但更简单,性能更好。将每个通道提高到 2.2 次方,然后乘以系数并求和:

  let lum = (sR/255.0)**2.2*0.2126+(sG/255.0)**2.2*0.7152+(sB/255.0)**2.2*0.0722;

如果您还有其他问题,请告诉我...

Short Answer

You are conflating something that is only for a specific piece of software called "Photosphere" and that math is not for general luminance use.

Complete Answer

You said:

calculate the luminance of image using RGB value

What do you mean? The luminance of some given pixel? Or the RMS average luminance? Or???

AND: What colorspace (profile) is your image in?

I am going to ASSUME your image is sRGB, and 8 bit per pixel. But it could be P3 or Adobe98, or any number of others... The math I am going to show you is for sRGB.

1) Convert to float

Each 8bit 0-255 sRGB color channel must be converted to 0.0-1.0

    let rF = sR / 255.0;
    let gF = sG / 255.0;
    let bF = sB / 255.0;

2) Convert to linear

The transfer curve aka "gamma" must be removed. For sRGB, the "accurate" method is:

    function sRGBtoLin(chan) {
       return (chan > 0.04045) ? Math.pow(( chan + 0.055) / 1.055, 2.4) : chan / 12.92
    }

3) Calculate Luminance

Now, multiply each linearized channel by the appropriate coefficient, and sum them to find luminance.

  let luminance = sRGBtoLin(rF) * 0.2126 + sRGBtoLin(gF) * 0.7152 + sRGBtoLin(bF) * 0.0722;

BONUS: Andy's Down and Dirty Version

Here's an alternate that is still usefully accurate, but simpler for better performance. Raise each channel to the power of 2.2, then multiply the coefficients, and sum:

  let lum = (sR/255.0)**2.2*0.2126+(sG/255.0)**2.2*0.7152+(sB/255.0)**2.2*0.0722;

Let me know if you have additional questions...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文