Convert RGB color values to YCbCr color space (2024)

Convert RGB color values to YCbCr color space

collapse all in page

Syntax

YCBCR = rgb2ycbcr(RGB)

Description

example

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");

Convert RGB color values to YCbCr color space (1)

imshow(YCBCR);title("Image in YCbCr Color Space");

Convert RGB color values to YCbCr color space (2)

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");

Convert RGB color values to YCbCr color space (3)

imshow(I,newcmap)title("Indexed Image with YCbCr Colormap");

Input Arguments

collapse all

RGBRGB 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 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].

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

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

Version History

Introduced before R2006a

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.

Convert RGB color values to YCbCr color space (5)

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

Europe

Asia Pacific

Contact your local office

Convert RGB color values to YCbCr color space (2024)

FAQs

How to convert RGB to YCbCr? ›

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.

Why do we convert colors from the the RGB color model to the YCbCr model? ›

But medical research proved that the human eye has different sensitivity to colour and brightness. Thus there came about the transformation of RGB to YCbCr. Y: Luminance; Cb: Chrominance-Blue; and Cr: Chrominance-Red are the components. Luminance is very similar to the grayscale version of the original image.

How to convert RGB image to YCbCr in Matlab? ›

Convert Image from RGB to YCbCr

RGB = imread("board. tif"); Convert the image to YCbCr. imshow(YCBCR); title("Image in YCbCr Color Space");

What is the relationship between RGB and YCbCr? ›

The difference between YCbCr and RGB is that RGB represents colors as combinations of red, green and blue signals, while YCbCr represents colors as combinations of a brightness signal and two chroma signals. In YCbCr, Y is luma (brightness), Cb is blue minus luma (B-Y) and Cr is red minus luma (R-Y).

Is RGB high better than YCbCr? ›

RGB High is often preferred for its fidelity, especially when used with TVs that handle a full RGB signal well, presenting a picture without alterations in contrast or brightness range. Meanwhile, YCbCr is suitable for compatibility and bandwidth efficiency.

How to convert RGB to YCbCr in Python? ›

RGB to YcrCb conversion
  1. import cv2 import numpy as np from matplotlib import pyplot as plt.
  2. fn3= 'tria.jpg' img1 = cv2. imread(fn3, cv2. CV_LOAD_IMAGE_UNCHANGED)
  3. img2=np. zeros(img1. shape,np. uint8) img2[:,:,0]=img1[:,:,2] img2[:,:,1]=img1[:,:,1] img2[:,:,2]=img1[:,:,0] plt. ...
  4. transcol=cv2. cvtColor(img1, cv2. cv.

What are the advantages of YCbCr over RGB? ›

Conversion from RGB to YCbCr allows for efficient video storage and broadcasting. For instance, signals in the YCbCr color space, as opposed to RGB, can be compressed significantly, which is pivotal for bandwidth-restricted applications.

What is the difference between RGB and YCbCr color format? ›

The difference between YCbCr and RGB is that YCbCr represents color as brightness and two color difference signals, while RGB represents color as red, green and blue. In YCbCr, the Y is the brightness (luma), Cb is blue minus luma (B-Y) and Cr is red minus luma (R-Y). See component video.

What is YCbCr color format? ›

The YCbCr format contains a subset of color coding data, also referred to as Chroma Subsampling and represented in the 4:n:n (Y:Cb:Cr) format. The left digit denotes luminance, the middle digit represents the blue channel, and the right digit is the red channel.

What is the YCbCr color space in MATLAB? ›

Another color space, widely used for digital video, is the YCbCr color space. In this color space, luminance (brightness or intensity) information is stored as a single component (Y). Chrominance (color) information is stored as two color-difference components (Cb and Cr).

How to convert RGB image to black and white in MATLAB? ›

I = rgb2gray( RGB ) converts the truecolor image RGB to the grayscale image I . The rgb2gray function converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance.

How do I convert RGB mode? ›

Open the Image in Photoshop and select Image> Mode > RGB Color to convert it to RGB color mode. When converting an image to RGB, the actual colors in the Image will not change.

What is the value of YCbCr for white? ›

Y′PbPr to Y′CbCr

For example, the scaling and offset applied to the Y′ component per specification (e.g. MPEG-2) results in the value of 16 for black and the value of 235 for white when using an 8-bit representation.

How do you set RGB to transparent? ›

The rgb() command is the key: you define a new color using numerical values (0–255) for red, green and blue. In addition, you set an alpha value (also 0–255), which sets the transparency (0 being fully transparent and 255 being “solid”).

Can you set RGB to black? ›

RGB Color Values

Another example, rgb(0, 255, 0) is displayed as green, because green is set to its highest value (255), and the other two (red and blue) are set to 0. To display black, set all color parameters to 0, like this: rgb(0, 0, 0).

Can I convert RGB to hex? ›

In order to convert an RGB color code to a hex color code, you must convert each of the values individually.

Top Articles
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 6415

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.