• Advertisement
Sign in to follow this  

Color - Gray

This topic is 3977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The simplest algorithm I know is: Gr = (R + G + B) / 3, or, sometimes, another coefficients are used. Is there more complex, but smarter algorithm to color2gray transformation?

Share this post


Link to post
Share on other sites
Advertisement
You can also try taking (min(r, g, b) + max(r, g, b))/2. This is the luminance value in HSL color space.

Share this post


Link to post
Share on other sites
Try having a look at converting rgb to hue/saturation/luminescence, and then setting saturation to 0. This appears to be how most image manipulation programs do it, and there's probably a simplified way of doing so if all you want to do is set saturation to 0, rather than converting everything.

Share this post


Link to post
Share on other sites
I usually use:

Gray = Red * 0.3 + Green * 0.59 + Blue * 0.11

so in a shader this may equate to a dot product between the colour.xyz and (0.3,0.59,0.11)

Share this post


Link to post
Share on other sites
There are several values floating around for direct conversion to luminance.

-- http://www.graficaobscura.com/matrix/index.html
R_lumin = 0.308600
G_lumin = 0.609400
B_lumin = 0.082000

-- Colorspace-faq: http://www.faqs.org/faqs/graphics/colorspace-faq
R_lumin = 0.212671
G_lumin = 0.715160
B_lumin = 0.072169

-- Unknown Lumin
R_lumin = 0.299000
G_lumin = 0.587000
B_lumin = 0.114000

used as in gray = red * R_lumin + green * G_lumin + blue * B_lumin

I tend to favour the one from the ColourSpace FAQ

Share this post


Link to post
Share on other sites
An approach that may be technically more accurate would be to convert to linear light (using each component raised to a power depending on gamma, often 1/2.2 is used as an approx for CRTs, but color profiles can have more accurate values for the specific display) then average, then perform the calculation (I would use the luminance formulas for YCrCb color space to calculate Y as the gray value), then convert back into gamma-adjusted color space (by raising to 2.2 or whatever value you used for gamma in the first place)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement