Thursday, July 9, 2009

Grayscale Conversion

예전에 RGB color가 Grayscale로 전환 시킬때 쓰이는 값 (0.222, 0.707, 0.071)이 어떻게 나온 것인지 참 궁금했었는데 이제야 해소가 된것 같다.

Consider the common conversion from RGB color to a grayscale. There are several approaches available: We can choose one color channel, or evenly blend all three channels, or mix the three RGB channels by varying weights to achieve a final grayscale result. The third choice, blending by weights, is generally accepted as the best, and it can be set to match the sensitivity of typical human eyesight.
We can express this blending with a dot product:
float grayscale = dot(float3(0.222, 0.707, 0.071), inColor);
The values (0.222, 0.707, 0.071) represent the relative scales for red, green, and blue, respectively. These numbers follow an international industrial color standard called ITU Rec 709 (there are actually a number of alternate formulations). Note that the components of the float3 vector used for this conversion sum to 1.0—this makes the conversion nominally "energy conserving," though in fact you can assign almost any values and get different interesting results, much as you can with the Photoshop Color Mixer tool.
In particular, a standardized conversion such as the one just described means that the brightness of pure colors may be limited—bright pure blues, for example, will never appear as more than a dark 7 percent gray. For artistic reasons, therefore, we may often want to vary the weights of our grayscale conversions, so that important colors aren't needlessly suppressed.
We can also use the results of such a grayscale conversion as a texture index to create alternative color mappings, using color-lookup textures similar to the one used in the previous section. Consider this mapping:
float grayscale = dot(float3(0.222, 0.707, 0.071), inColor);
// set the texture's edge-addressing to "clamp"

float3 OutColor = tex1D(ColorCorrMap, grayscale);
Using a grayscale-to-color-gradient mapping in this way permits us to create a wide variety of false-color and toned-print effects, both naturalistic (such as duotones or tritones) and highly stylized (such as robot vision or infrared "heat signatures" à la the movie Predator).

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home