[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]

details Color Space Conversions VIGRA

Convert between RGB, R'G'B', XYZ, L*a*b*, L*u*v*, Y'PbPr, Y'CbCr, Y'IQ, and Y'UV color spaces.

#include "vigra/colorconversions.hxx"
Namespace: vigra

This module provides conversion from RGB/R'G'B' into more perceptually uniform color spaces. In image analysis, colors are usually converted into another color space in order to get good estimates of perceived color differences by just calculating Euclidean distances between the transformed colors. The L*a*b* and L*u*v* were designed with exactly this application in mind and thus give the best results. But these conversions are also the most computationally demanding. The Y'PbPr color difference space (designed for the coding of digital video) is computationally much cheaper, and almost as good. Y'CbCr represents esentially the same transformation, but the color values are scaled so that they can be stored with 8 bits per channel with minimal loss of information. The other transformations are of lesser interest here: XYZ is a device independent (but not perceptually uniform) color representation, and Y'IQ and Y'UV are the color spaces used by the PAL and NTSC analog video standards. Detailed information about these color spaces and their transformations can be found in Charles Poynton's Color FAQ

When you want to perform a color conversion, you must first know in which color space the data are given. Although this sounds trivial, it is quite often done wrong in practice, because the distinction between RGB and R'G'B' is frequently overlooked: nowadays, most images are stored in R'G'B' space, and treating them as RGB leads to wrong results. RGB and R'G'B' are related by a so called gamma correction:

(where usually ). In practice, you can distinguish the two kinds of red, green, and blue by displaying the images: if they look too dark, they are probably RGB, if they are OK, they are likely R'G'B'. (However, this may also be misleading: Some graphics cards and display programs silently apply a gamma correction to every image, so that RGB appears correct and R'G'B' is too bright.) The distinction between RGB and R'G'B' is important because some conversions start at RGB (XYZ, L*a*b*, L*u*v*), while others start at R'G'B' (Y'PbPr, Y'CbCr, Y'IQ, and Y'UV). The names of VIGRA's color conversion functors always make clear to which color space they must be applied.

In addition VIGRA provides a polar coordinate interface to several color spaces (L*a*b*, L*u*v*, Y'PbPr, Y'CbCr, Y'IQ, and Y'UV). This interface makes use of the fact that these color spaces are conceptually similar: they represent colors by a "brightness" coordinate (L* or Y') and a pair of "chromaticity" coordinates that span a plane of colors with equal brightness. The polar representation transforms chroma coordinates into a color "angle" (similar to hue in the HSV system) and a "saturation". The polar coordinates are normalized so that a color angle of 0 degrees is always associated with red (green is at about 120 degrees, blue at about 240 degrees - exact values differ between color spaces). A saturation of 1 is the highest saturation that any RGB color in the unit cube can have after transformation into the respective color space, and saturation 0 corresponds to gray. Polar coordinates provide a more intuitive interface to color specification by users and make different color spaces somewhat comparable.

© Ullrich Köthe (koethe@informatik.uni-hamburg.de)
Cognitive Systems Group, University of Hamburg, Germany

html generated using doxygen and Python
VIGRA 1.3.3 (18 Aug 2005)