Main Content


Apply device-independent color space transformation



B = applycform(A,C) converts the color values in A to the color space specified in the color transformation structure C.


collapse all

Read color image that uses the sRGB color space into the workspace.

rgb = imread('peppers.png');

Create a color transformation structure that defines an sRGB to L*a*b* conversion.

C = makecform('srgb2lab');

Perform the transformation by using the applycform function.

lab = applycform(rgb,C);

Input Arguments

collapse all

Input color space, specified as one of the following:

  • 2-D numeric matrix. applycform interprets each row as a color unless the color transformation structure, C, contains a grayscale ICC profile. In that case, applycform interprets each pixel in A as a color.

  • 3-D numeric matrix. Each row-column location is interpreted as a color. size(A,3) is typically 1 or more, depending on the input color space.

  • string or character vector. A is only a string or character vector if C is created with the following syntax:

    C = makecform('named', profile, space)

Data Types: double | uint8 | uint16 | char | string

Color transformation, specified as a structure. The color transformation structure specifies various parameters of the transformation. You can create a color transformation structure using makecform.

Output Arguments

collapse all

Output color space, returned as a numeric array. The size of B depends on the dimensionality and size of the input color space, A:

  • When A is two-dimensional, B has the same number of rows and one or more columns, depending on the output color space. (The ICC specification currently supports up to 15-channel device spaces).

  • When A is three-dimensional, B is the same number of rows and columns as A, and size(B,3) is 1 or more, depending on the output color space.


The applycform function assumes that the input color space values follow encoding conventions. Encoding describes the mapping between color values and numeric values in different data types. For example, in an RGB image of data type double, a value of 1.0 is fully saturated. In an RGB image of data type uint8, a value of 255 is fully saturated.

For the L*a*b* color space, the applycform function assumes values follow the encoding convention described in the Algorithms section of the lab2double function page.

For the RGB and CMYK color spaces, the applycform function assumes values are scaled to the data type range. If there is a mismatch between the data type and value range for your data, rescale the values or convert your data to the correct data type.

  • The function assumes values of data type double are in the range [0, 1].

  • The function assumes values of data type uint8 are in the range [0, 255].

  • The function assumes values of data type uint16 are in the range [0, 65535].

Version History

Introduced before R2006a