Image Processing Toolbox User's Guide |
Converting Between Device-Independent Color Spaces
The standard terms used to describe colors, such as hue, brightness, and intensity, are subjective and make comparisons difficult.
In 1931, the International Commission on Illumination, known by the acronym CIE, for Commission Internationale de l'Éclairage, studied human color perception and developed a standard, called the CIE XYZ. This standard defined a three-dimensional space where three values, called tristimulus values, define a color. This standard is still widely used today.
In the decades since that initial specification, the CIE has developed several additional color space specifications that attempt to provide alternative color representations that are better suited to some purposes than XYZ. For example, in 1976, in an effort to get a perceptually uniform color space that could be correlated with the visual appearance of colors, the CIE created the L*a*b* color space.
The toolbox supports conversions between members of the CIE family of device-independent color spaces. In addition, the toolbox also supports conversions between these CIE color spaces and the sRGB color space. This color space was defined by an industry group to describe the characteristics of a typical PC monitor.
Supported Conversions
This table lists all the device-independent color spaces that the toolbox supports.
Example: Performing a Color Space Conversion
To illustrate a conversion between two device-independent color spaces, this example reads an RGB color image into the MATLAB workspace and converts the color data to the XYZ color space:
makecform
function to create the structure, specifying a transformation type string as an argument.
applycform
function to perform the conversion, specifying as arguments the color data you want to convert and the color transformation structure that defines the conversion. The applycform
function returns the converted data.
Color Space Data Encodings
When you convert between two device-independent color spaces, the data type used to encode the color data can sometimes change, depending on what encodings the color spaces support. In the preceding example, the original image is uint8
data. The XYZ conversion is uint16
data. The XYZ color space does not define a uint8
encoding. The following table lists the data types that can be used to represent values in all the device-independent color spaces.
Color Space |
Encodings |
XYZ |
uint16 or double |
xyY |
double |
uvL |
double |
u'v'L |
double |
L*a*b* |
uint8 , uint16 , or double |
L*ch |
double |
sRGB |
double |
As the table indicates, certain color spaces have data type limitations. For example, the XYZ color space does not define a uint8
encoding. If you convert 8-bit CIE LAB data into the XYZ color space, the data is returned in uint16
format. If you want the returned XYZ data to be in the same format as the input LAB data, you can use one of the following toolbox color space format conversion functions.
Converting Color Data Between Color Spaces | Performing Profile-Based Conversions |
© 1994-2005 The MathWorks, Inc.