Convert RGB color values to YCbCr color space



ycbcrmap = rgb2ycbcr(rgbmap) converts the RGB color space values in rgbmap to the YCbCr color space. ycbcrmap is a c-by-3 matrix that contains the YCbCr luminance (Y) and chrominance (Cb and Cr) color values as columns. Each row in ycbcrmap represents the equivalent color to the corresponding row in rgbmap.

You optionally can perform the conversion using a GPU (requires Parallel Computing Toolbox™).

YCBCR = rgb2ycbcr(RGB) converts the truecolor image RGB to the equivalent image in YCbCr color space.


collapse all

Convert Image from RGB to YCbCr

Read an RGB image into the workspace.

RGB = imread('board.tif');

Convert the image to YCbCr.

YCBCR = rgb2ycbcr(RGB);

Display the original image and the new image

title('Image in RGB Color Space');

title('Image in YCbCr Color Space');

Convert Colormap from RGB to YCbCr.

Load an indexed image into the workspace. The colormap is in RGB colorspace.

[I,map] = imread('forest.tif');

Convert the colormap to YCbCr.

newmap = rgb2ycbcr(map);

Display the grayscale image with the original map and with the new map.

title('Indexed Image with RGB Colormap');

title('Indexed Image with YCbCr Colormap');

Input Arguments

collapse all

RGB color space values, specified as a c-by-3 numeric matrix with values in the range [0, 1]. Each row is a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.

Data Types: single | double

RGB image, specified as an m-by-n-by-3 numeric array.

Data Types: single | double | uint8 | uint16

Output Arguments

collapse all

YCbCr color space values, returned as a c-by-3 matrix. The first column corresponds to Y. The second and third columns correspond to Cb and Cr. Y is in the range [16/255, 235/255], and Cb and Cr are in the range [16/255, 240/255].

Image in YCbCr color space, returned as an m-by-n-by-3 numeric array.

  • If the input is double or single, then Y is in the range [16/255, 235/255] and Cb and Cr are in the range [16/255, 240/255].

  • If the input is uint8, then Y is in the range [16, 235] and Cb and Cr are in the range [16, 240].

  • If the input is uint16, then Y is in the range [4112, 60395] and Cb and Cr are in the range [4112, 61680].


[1] Poynton, C. A.A Technical Introduction to Digital Video, John Wiley & Sons, Inc., 1996, p. 175.

[2] Rec. ITU-R BT.601-5, Studio Encoding Parameters of Digital Television for Standard 4:3 and Wide-screen 16:9 Aspect Ratios, (1982-1986-1990-1992-1994-1995), Section 3.5.

Extended Capabilities

GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

Introduced before R2006a