Sign in to follow this  
Phong

Color - Gray

Recommended Posts

Phong    128
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
Twincamtinman    154
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
Rompa    307
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
noisecrime    817
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
Extrarius    1412
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this