Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan 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)
gpuarrayB = rgb2ycbcr(gpuarrayA)

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.

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

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

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 m-by-3 array.

Data Types: single | double

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

Data Types: single | double | uint8 | uint16

RGB color space values or RGB image to be processed on a graphics processing unit (GPU), specified as a gpuArray object.

Output Arguments

collapse all

YCbCr color space values, returned as an m-by-3 array. 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 array.

  • If the input is double or single, 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, Y, is in the range [16, 235], and Cb and Cr, are in the range [16, 240].

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

Output in YCbCr color space when run on a graphics processing unit (GPU), specified as a gpuArray object. The output is either an array of YCbCr color space values or a YCbCr image, depending on the input type.

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

Was this topic helpful?