One important task in image processing applications is the color space conversion. Real-time images and videos are stored in RGB color space, because it is based on the sensitivity of color detection cells in the human visual system. In digital image processing the YCbCr color space is often used in order to take advantage of the lower resolution capability of the human visual system for color with respect to luminosity. Thus, RGB to YCbCr conversion is widely used in image and video processing .
Given a digital pixel represented in RGB format, 8 bits per sample, where 0 and 255 represents the black and white color, respectively, the YCbCr components can be obtained according to equations (1) to (3):
Approximating the equations (1) to (3) to the nearest integer and replacing multiplication and division by shift registers, the equations (4) to (6) are obtained:
Image and Video consumes a lot of data. One of the reasons is because they are represented in the RGB format. However, is not worth to store or transmit information in this color space representaion, once it has a large bandwidth. Thus all the pixels should be converted to YCbCr to accomplish that.
A practical example
To understand the effect of converting RGB to YCbCr, we will use the Figure (1).
Using Matlab or Octave can be done some processing on the image. For example, the code below reads the image file "rgb.png":
A color image has three channels (red, green and blue components). To access each component of the image, the Matlab code below can be used:
Each component of the image can be seen in Figures (2) to (4). Note that each channel has only the each corresponding color.
The Matlab provides the function rgb2ycbcr that converts an image from RGB to YCbCr. The script to convert the image from one space to another and to access each component (Y, Cb and Cr) can be seen below:
The converted image in the YCbCr space can be seen in Figure (5). It has three components: the lumminance Y, the blue difference Cb and the red difference Cr.
The Y component only filters the luminance (brightness) of the image (see Figure (6)); the Cb and Cr components subtract the red and blue colors, respectively, from the image (see Figures (7) and (8)).
The hardware implementation of the RGB to YCbCr converter may be done using equations (4) to (6). The computation is done using only shift registers and adders. Each component is described in Figures (9) to (11).
The SystemVerilog implementation of the RGB2YCbCr converter can be seen below:
The module of the converter has two interfaces:
- The RGB interface rgb_if: contains the three components of the RGB pixel, plus the clock and reset signals
- The YCbCr interface ycbcr_if: contains the three components of the YCbCr pixel, plus the clock and reset signals
The SystemVerilog implementation of the testbench of the RGB2YCbCr is shown below. Note that the ROM memory module provides the pixels to stimulate the RGB2YCbCr module.
Also available in GitHub.
 Keith Jack. Video demystified: a handbook for the digital engineer. Elsevier, 2011