Grayscale

From Wikipedia, the free encyclopedia

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
A typical grayscale image.
A typical grayscale image.

In computing, a grayscale or greyscale digital image is an image in which the value of each pixel is a single sample, that is, it carries the full (and only) information about its intensity. Images of this sort are composed exclusively of shades of neutral gray, varying from black at the weakest intensity to white at the strongest.

Grayscale images are distinct from black-and-white images, which in the context of computer imaging are images with only two colors, black and white (also called bilevel, binary images); grayscale images have many shades of gray in between. In most contexts other than digital imaging, however, the term "black and white" is used in place of "grayscale"; for example, photography in shades of gray is typically called "black-and-white photography". The term monochromatic in some digital imaging contexts is synonymous with grayscale (as it denotes absence of any concrete hue), and in some contexts synonymous with black-and-white.

Grayscale images are often the result of measuring the intensity of light at each pixel in a single band of the electromagnetic spectrum (e.g. infrared, visible light, ultraviolet, etc.), and in such cases they are monochromatic proper when only a given frequency is captured. But also they can be synthesized from a full color image; see the section about converting to grayscale.

Contents

[edit] Numerical representations

4096 gray levels
4096 gray levels

The intensity of a pixel is expressed within a given range between a minimum and a maximum, inclusive. This range is represented in an abstract way as a range from 0 (total absence, black) and 1 (total presence, white), with any fractional values in between. This notation is used in academic papers, but it must be noted that this does not define what "black" or "white" is in terms of colorimetry.

Another convention is to employ percentages, so the scale is then from 0% to 100%. This is used for a more intuitive approach, but if only integer values are used, the range encompasses a total of only 101 intensities, which are insufficient to represent a broad gradient of grays. Also, the percentile notation is used in printing to denote how much ink is employed in halftoning, but then the scale is reversed, being 0% the paper white (no ink) and 100% a solid black (full ink).

In computing, although the grayscale can be computed through rational numbers, image pixels are stored in binary, quantized form. Some early monochrome monitors can only show up to sixteen (4-bit) different shades, but today grayscale images (as photographs) intended for visual display (both on screen and printed) are commonly stored with 8 bits per sampled pixel, which allows 256 different intensities (i.e., shades of gray) to be recorded, typically on a non-linear scale. The accuracy provided by this format is barely sufficient to avoid visible banding artifacts, but very convenient for programming due to a single pixel occupies then a single byte.

Technical uses (e.g. in medical imaging or remote sensing applications) often require more levels, to make full use of the sensor accuracy (typically 10 or 12 bits per sample) and to guard against roundoff errors in computations. Sixteen bits per sample (65,536 levels) is a convenient choice for such uses, as computers manage 16-bit words efficiently. The TIFF and the PNG (among other) image file formats supports 16-bit grayscale natively, although browsers and many imaging programs tend to ignore the low order 8 bits of each pixel.

No matter what pixel depth is used, the binary representations assume that 0 is black and the maximum value (255 at 8 bpp, 65,535 at 16 bpp, etc.) is white, if not otherwise noted.

[edit] Converting color to grayscale


A photograph of a Neighborhood Watch sign in color A photograph of a Neighborhood Watch sign in grayscale A photograph of a Neighborhood Watch sign in black and white
The same picture in three different color modes. The picture on the left is the original photograph, in full color. The picture in the center is in grayscale; all the colors contained in it are black, white, or any shade of gray. The picture on the right is in black and white, or bitmap; the only colors used in the picture are black and white, with no intermediary grays.

To convert any color to its most approximate level of gray, first one must obtain the values of its red, green and blue (RGB) primaries, in linear intensity encoding.

Then, add 30% of the red value, 59% of the green value, and 11% of the blue value, together. Regardless of the scale employed (0.0 to 1.0, 0 to 255, 0% to 100%, etc.), the resultant number is the desired gray value. These percentages are chosen due to the different relative sensitivity of the normal human eye to each of the primary colors (less sensitive to blue, more to green). The result is the linear intensity value of the equivalent gray; it can be gamma corrected if necessary.

This is the method used to obtain the luminance in the YUV and related color models, used in standard color TV and video systems as PAL and NTSC, as well as in the L*a*b color model. Visit these articles for a rationale of the above formula.

To convert a gray intensity value to RGB, simply set all the three primary color components red, green and blue to the gray value, scaling if necessary (that is, when the gray and RGB component ranges are not the same).

[edit] Grayscale as single channels of multichannel color images

Color images are often built of several stacked color channels, each of them representing value levels of the given channel. For example, RGB images are composed of three independent channels for red, green and blue primary color components; CMYK images have four channels for cyan, magenta, yellow and black ink plates, etc. Being every single channel also a single sample, they can be managed easily as independent grayscale images.

Here is an example of color channel splitting of a full RGB color image. The column at left shows the isolated color channels in natural colors, while at right there are their grayscale equivalences:

The reverse is also possible: to build a full color image from their separate grayscale channels. By mangling channels, offseting, rotating and other manipulations, artistic effects can be achieved instead to make the mere accurate original image.

[edit] Colorized grayscale

By clever use of color palettes, grayscale images can be easily colorized to both achieve artistic effects (as the sepia tone) and to map the pixels' intensities through a false color palette to study false color images in scientific fields.

At right is the previous parrot image seen using an arbitrary false color palette, which reveals additional details of the dark background areas.

[edit] See also

[edit] External links