Graphics Reference
In-Depth Information
necessary to consider luminance when creating a color system that could sup-
port both black-and-white and color television.
The sRGB specification (also known as IEC 61966-2-1) is emerging as a
standard way to define colors across various monitors and applications [42].
In sRGB, luminance is defined as a linear combination of red, green, and blue.
The weight vector for luminance in sRGB is
const vec3 W = vec3( 0.2125, 0.7154, 0.0721 );
W e use this set of weights in much of the upcoming sample vertex shader
code to compute the luminance of a pixel by taking the dot product of the vec-
tor .rgb with this weighting vector as follows:
vec3 irgb = texture( uImageUnit, vST ).rgb;
float luminance = dot( irgb, W );
Note that these numbers in the weight vector W sum to 1.0000 so that
doting this vector with a legitimate RGB vector will produce a luminance
between 0 and 1. We will find luminance to be an important concept in several
image manipulation techniques, such as grayscale. Grayscale conversion of an
image is accomplished by replacing the color of each pixel with its luminance
value. When you compute each pixel's luminance, as shown in the code frag-
ment above, you can create a grayscale representation of the image by seting
the pixel color to a vector of the luminance value:
fFragColor = vec4( luminance, luminance, luminance, 1.);
A conversion from a color image to grayscale in this way is shown in
Figure 11.2.
Figure 11.2. A supermarket fruit image (left) and its grayscale equivalent (right).
Search WWH ::




Custom Search