rgb2ycbcr

Convert RGB color values to YCbCr color space

Syntax

ycbcrmap = rgb2ycbcr(map)
YCBCR = rgb2ycbcr(RGB)
gpuarrayB = rgb2ycbcr(gpuarrayA)

Description

ycbcrmap = rgb2ycbcr(map) converts the RGB values in map to the YCbCr color space. map must be an M-by-3 array. 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 ycbcfmap represents the equivalent color to the corresponding row in the RGB colormap, map.

This function supports code generation (see Tips).

YCBCR = rgb2ycbcr(RGB) converts the truecolor image RGB to the equivalent image in the YCbCr color space. RGB must be a M-by-N-by-3 array.

gpuarrayB = rgb2ycbcr(gpuarrayA) performs the conversion on a GPU. The input image, gpuarrayA, can be an RGB gpuArray colormap or an RGB gpuArray image. The output is an YCbCr gpuArray colormap or an YCbCr gpuArray image, depending on the input type. This syntax requires the Parallel Computing Toolbox™.

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

  • If the input is a double, 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 uint16, Y is in the range [4112 60395] and Cb and Cr are in the range [4112 61680].

Class Support

If the input is an RGB image, it can be of class uint8, uint16, or double. If the input is a colormap, it must be double. The output is of the same class as the input image.

If the input gpuArray is an RGB image, it can be of class uint8, uint16, single, or double. If the input gpuArray is a colormap, it must be single or double. The output gpuArray is of the same class as the input image.

Examples

Convert RGB image to YCbCr.

RGB = imread('board.tif');
YCBCR = rgb2ycbcr(RGB);

Convert RGB color space to YCbCr.

map = jet(256);
newmap = rgb2ycbcr(map);

Convert RGB image to YCbCr on a GPU.

RGB = imread('board.tif');
YCBCR = rgb2ycbcr(gpuArray(RGB));

Convert RGB color space to YCbCr on a GPU.

map = jet(256);
newmap = rgb2ycbcr(gpuArray(map));

More About

expand all

Tips

  • This function supports the generation of C code using MATLAB® Coder™. The code generated for this function uses a precompiled, platform-specific shared library. Use of a shared library preserves performance optimizations but limits the target platforms for which code can be generated. For more information, see Code Generation Using a Shared Library.

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.

Was this topic helpful?