This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

rgb2ycbcr

Convert RGB color values to YCbCr color space

Syntax

ycbcrmap = rgb2ycbcr(rgbmap)
YCBCR = rgb2ycbcr(RGB)

Description

example

ycbcrmap = rgb2ycbcr(rgbmap) converts the RGB color space values in rgbmap to the YCbCr color space. ycbcrmap is an m-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™). For more information, see Image Processing on a GPU.

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

Examples

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

figure
imshow(RGB);
title('Image in RGB Color Space');

figure
imshow(YCBCR);
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.

figure
imshow(I,map)
title('Indexed Image with RGB Colormap');

figure
imshow(I,newmap)
title('Indexed Image with YCbCr Colormap');

Input Arguments

collapse all

RGB color space values, specified as an c-by-3 matrix representing c colors.

To perform the conversion using a GPU, specify rgbmap as a gpuArray that contains a c-by-3 matrix.

Data Types: single | double

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

To perform the conversion using a GPU, specify RGB as a gpuArray that contains an m-by-n-by-3 array.

Data Types: single | double | uint8 | uint16

Output Arguments

collapse all

YCbCr color space values, returned as an 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].

If the conversion is performed using a GPU, then ycbcrmap is returned as a gpuArray containing a c-by-3 matrix.

Image in YCbCr color space, returned as an m-by-n-by-3 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].

If the conversion is performed using a GPU, then YCBCR is returned as a gpuArray containing an m-by-n-by-3 array.

References

[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

Introduced before R2006a