Luminance Matching Two Colors

人盡茶涼 提交于 2019-12-04 13:05:22

You need to be careful about luminance-matching digital images, because the actual luminance depends on how they're displayed. In particular, you want to watch out for "gamma correction", which is a nonlinear mapping between the RGB values and the actual display brightness. Some images may have an internal "gamma" value associated with the data itself, and many display devices effectively apply a "gamma" to the RGB values they display.

However, for an image stored and displayed linearly (with an effective gamma of 1), there is a standard luminance measure for RGB values:

Y = 0.2126 * R + 0.7152 * G + 0.0722 * B

There are, actually, a number of standards, with different weights for the linear R, G, and B components. However, if you aren't sure exactly how your image will be displayed, you might as well pick one and stick with it...


Anyway, you can use this to solve your specific problem, as follows: you want a grey value (r,g,b) = (x,x,x) with the same luminance as a pure-red value of 255. Conveniently, the three luminance constants sum to 1.0. This gives you the following formula:

Y == 1.0 * x == 0.2126 * 255
--> x ~ 54

If you want to match a different color, or use different luminance weights (which still sum to 1.0), the procedure is the same: just weight the RGB values according to the luminance formula, then pick a grey value equal to the luminance.

I believe the answer already given is misleading (SO doesn't let me comment). As mentioned the formula given applies to intensities and you should watch out for gamma, see e.g. here:

http://www.poynton.com/notes/colour_and_gamma/GammaFAQ.html#luminance

Thus, the application example should use coefficients that account for gamma, or compensate the gamma by hand which it doesn't. Yes, the image could be linear (so you have actual intensities), but judging from the description the chance is close to zero that it is.

These coefficients yield 'luma', not luminance, but that is what you have asked for anyway. See:

http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC11

To summarize:

luma = 0.299 R + 0.587 G + 0.114 B

(r,g,b) = (luma, luma, luma)

The material should also help with your addendum question. I've found it to be very reliable, which is clearly an exception in this field.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!