A high-performance general-purpose compute library

RGB to YCbCr colorspace converter. More...

Functions

AFAPI array rgb2ycbcr (const array &in, const YCCStd standard=AF_YCC_601)
 C++ Interface for converting RGB to YCbCr. More...
 
AFAPI af_err af_rgb2ycbcr (af_array *out, const af_array in, const af_ycc_std standard)
 C Interface for converting RGB to YCbCr. More...
 

Detailed Description

RGB to YCbCr colorspace converter.

RGB (Red, Green, Blue) is the most common format used in computer imaging. RGB stores individual values for red, green and blue, and hence the 3 values per pixel. A combination of these three values produces the gamut of unique colors.

YCbCr is a family of color spaces used as a part of the color image pipeline in video and digital photography systems where Y is luma component and Cb & Cr are the blue-difference and red-difference chroma components.

Input array to this function should be of real data in the range \([0,1]\).

The following equations are used to convert image from RGB color space to YCbCr color space.

\( Y = 16 + \displaystyle k_r*R + (1 - \displaystyle k_r- \displaystyle k_b)*G + \displaystyle k_b * B \)

\( Cb = 128 + \frac{\displaystyle 1}{\displaystyle 2} * \frac{\displaystyle B - Y\displaystyle }{\displaystyle 1 - \displaystyle k_b} \)

\( Cr = 128 + \frac{\displaystyle 1}{\displaystyle 2} * \frac{\displaystyle R - Y\displaystyle }{\displaystyle 1 - \displaystyle k_r} \)

Output image in YCbCr has following range for their respective channels.

\(Y -> [16, 219]\)

\(Cb-> [16, 240]\)

\(Cr-> [16, 240]\)

Based on the ITU-R BT.xyz[w] standard used, different values of \(k_b\) and \(k_r\) are used to do the color space conversion. You can change these values by passing the af_ycc_std enum value.


Function Documentation

◆ af_rgb2ycbcr()

AFAPI af_err af_rgb2ycbcr ( af_array out,
const af_array  in,
const af_ycc_std  standard 
)

C Interface for converting RGB to YCbCr.

Parameters
[out]outis an array in the YCbCr color space
[in]inis an array in the RGB color space
[in]standardspecifies the ITU-R BT "xyz" standard which determines the Kb, Kr values used in colorspace conversion equation
Returns
AF_SUCCESS if the color transformation is successful, otherwise an appropriate error code is returned.
Note
in must be three dimensional and values should lie in the range [0,1]

◆ rgb2ycbcr()

AFAPI array rgb2ycbcr ( const array in,
const YCCStd  standard = AF_YCC_601 
)

C++ Interface for converting RGB to YCbCr.

Parameters
[in]inis an array in the RGB colorspace
[in]standardspecifies the ITU-R BT "xyz" standard which determines the Kb, Kr values used in colorspace conversion equation
Returns
array in YCbCr colorspace
Note
in must be three dimensional and values should lie in the range [0,1]