Convert RGB color values to YCbCr color space
collapse all in page
Syntax
YCBCR = rgb2ycbcr(RGB)
Description
YCBCR = rgb2ycbcr(RGB)
converts the red, green, and blue values of an RGB image to luminance (Y) and chrominance (Cb and Cr) values of a YCbCr image.
Examples
collapse all
Convert RGB to YCbCr
Open Live Script
Convert Image from RGB to YCbCr
Read an RGB image into the workspace.
Convert the image to YCbCr.
YCBCR = rgb2ycbcr(RGB);
Display the original image and the new image
imshow(RGB);title("Image in RGB Color Space");
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.
newcmap = rgb2ycbcr(map);
Display the grayscale image with the original map and with the new map.
imshow(I,map)title("Indexed Image with RGB Colormap");
imshow(I,newcmap)title("Indexed Image with YCbCr Colormap");
Input Arguments
collapse all
RGB
— RGB color values
numeric array
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
Data Types: single
| double
| uint8
| uint16
Output Arguments
collapse all
YCBCR
— Converted YCbCr color values
numeric array
Converted YCbCr color values, returned as a numeric array of the same size as the input.
If the input is
double
orsingle
, thenY
is in the range [16/255, 235/255] andCb
andCr
are in the range [16/255, 240/255].If the input is
uint8
, thenY
is in the range [16, 235] andCb
andCr
are in the range [16, 240].If the input is
uint16
, thenY
is in the range [4112, 60395] andCb
andCr
are in the range [4112, 61680].
References
[1] Poynton, C. A.A Technical Introductionto Digital Video, John Wiley & Sons, Inc., 1996, p.175.
[2] Rec. ITU-R BT.601-5, StudioEncoding Parameters of Digital Television for Standard 4:3 and Wide-screen16:9 Aspect Ratios, (1982-1986-1990-1992-1994-1995),Section 3.5.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
rgb2ycbcr
supports the generation of C code (requires MATLAB® Coder™). Note that if you choose the genericMATLAB Host Computer
target platform,rgb2ycbcr
generates code that 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 Types of Code Generation Support in Image Processing Toolbox.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Image Processing on a GPU.
Version History
Introduced before R2006a
See Also
rgb2lab
| rgb2xyz
| rgb2ntsc
| ycbcr2rgb
| rgbwide2ycbcr
| ycbcr2rgbwide
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Contact your local office