# Color - Gray

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

## 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 on other sites
You can also try taking (min(r, g, b) + max(r, g, b))/2. This is the luminance value in HSL color space.

##### 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 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 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 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 on other sites
If you wanted to be fancy you could use a "salience preserving" color removal.

LeGreg

• 10
• 17
• 9
• 14
• 41