Main Content


Convert RGB to CIE 1931 XYZ


XYZ = rgb2xyz(RGB) converts the red, green, and blue values of an sRGB image to CIE 1931 XYZ values (2° observer).


XYZ = rgb2xyz(RGB,Name,Value) specifies additional conversion options, such as the color space of the RGB image, using one or more name-value arguments.


collapse all

Convert images and color values from RGB to CIE 1931 XYZ color space.

Convert RGB Image to XYZ

Read an RGB image into the workspace.

RGB = imread('peppers.png');

Convert the image to XYZ color space.

XYZ = rgb2xyz(RGB);

Display the original image alongside the new image.

title('Image in RGB Color Space (Left) and XYZ Color Space (Right)');

Convert RGB Color Value to XYZ

Convert the value of white from RGB to XYZ color space. In RGB, white is represented by the vector [1 1 1].

rgb2xyz([1 1 1])
ans = 1×3

    0.9505    1.0000    1.0888

Convert RGB Color to XYZ using D50 as Reference White

XYZ_D50 = rgb2xyz(RGB,'WhitePoint','d50');

Display the first output XYZ image alongside the XYZ image with D50 as reference white.

title('XYZ Image, Without (Left) and With (Right) Reference White');

Convert Adobe RGB (1998) Color to XYZ

XYZ_Adobe = rgb2xyz(RGB,'ColorSpace','adobe-rgb-1998');

Display the XYZ images generated from the default RGB and the Adobe RGB (1998) color spaces.

title(['XYZ Image, Starting From Default RGB (Left) and Adobe RGB ',...
  '(Right) Color Space']);

Input Arguments

collapse all

RGB color values to convert, specified as a numeric array in one of these formats.

  • c-by-3 colormap. Each row specifies one RGB color value.

  • m-by-n-by-3 image

  • m-by-n-by-3-by-p stack of images

Data Types: single | double | uint8 | uint16

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: xyz = rgb2xyz([.2 .3 .4],WhitePoint="d50")

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: xyz = rgb2xyz([.2 .3 .4],"WhitePoint","d50")

Color space of the input RGB values, specified as "srgb", "adobe-rgb-1998", "prophoto-rgb", or "linear-rgb". If you specify "linear-rgb", then rgb2xyz assumes the input RGB values are linearized sRGB values.

Data Types: string | char

Reference white point, specified as a 1-by-3 vector or one of the CIE standard illuminants listed in the table.

ValueWhite Point

CIE standard illuminant A, [1.0985, 1.0000, 0.3558]. Simulates typical, domestic, tungsten-filament lighting with correlated color temperature of 2856 K.

"c"CIE standard illuminant C, [0.9807, 1.0000, 1.1822]. Simulates average or north sky daylight with correlated color temperature of 6774 K. Deprecated by CIE.
"e"Equal-energy radiator, [1.000, 1.000, 1.000]. Useful as a theoretical reference.
"d50"CIE standard illuminant D50, [0.9642, 1.0000, 0.8251]. Simulates warm daylight at sunrise or sunset with correlated color temperature of 5003 K. Also known as horizon light.


CIE standard illuminant D55, [0.9568, 1.0000, 0.9214]. Simulates mid-morning or mid-afternoon daylight with correlated color temperature of 5500 K.

"d65"CIE standard illuminant D65, [0.9504, 1.0000, 1.0888]. Simulates noon daylight with correlated color temperature of 6504 K.
"icc"Profile Connection Space (PCS) illuminant used in ICC profiles. Approximation of [0.9642, 1.000, 0.8249] using fixed-point, signed, 32-bit numbers with 16 fractional bits. Actual value: [31595,32768, 27030]/32768.

Data Types: single | double | string | char

Output Arguments

collapse all

Converted XYZ color values, returned as a numeric array of the same size as the input. The output type is class double unless the input type is single, in which case the output type is also single.


  • If you specify the input RGB color space as "linear-rgb", then rgb2xyz assumes the input values are linearized sRGB values. If instead you want the input color space to be linearized Adobe RGB (1998), then you can use the lin2rgb function.

    For example, to convert linearized Adobe RGB (1998) image RGBlinadobe to CIE 1931 XYZ color space, perform the conversion in two steps:

    RGBadobe = lin2rgb(RGBlinadobe,"ColorSpace","adobe-rgb-1998");
    XYZ = rgb2xyz(RGBadobe,"ColorSpace","adobe-rgb-1998");

Version History

Introduced in R2014b

expand all