A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Functions
ycbcr2rgb
ArrayFire Functions | ArrayFire Functions by Category » Image Processing » Colorspace conversions

## Functions
AFAPI array | ycbcr2rgb (const array &in, const YCCStd standard=AF_YCC_601)
| C++ Interface for converting YCbCr to RGB.
AFAPI af_err | af_ycbcr2rgb (af_array *out, const af_array in, const af_ycc_std standard)
| C Interface for converting YCbCr to RGB.

## Detailed Description

YCbCr to RGB colorspace converter

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.

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.

Input array to this function should be of real data with the following range in their respective channels.

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

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

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

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

\( R = \frac{\displaystyle Y - \displaystyle 16}{\displaystyle 219} + \frac{\displaystyle C_r - \displaystyle 128}{\displaystyle 112} * (\displaystyle 1 - \displaystyle k_r) \)

\( G = \frac{\displaystyle Y - \displaystyle 16}{\displaystyle 219} - \frac{\displaystyle C_r - \displaystyle 128}{\displaystyle 112} * (\displaystyle 1 - \displaystyle k_r) * \frac{\displaystyle k_r}{\displaystyle 1 - \displaystyle k_b - \displaystyle k_r} - \frac{\displaystyle C_b - \displaystyle 128}{\displaystyle 112} * (\displaystyle 1 - \displaystyle k_b) * \frac{\displaystyle k_b}{\displaystyle 1 - \displaystyle k_b - \displaystyle k_r}\)

\( B = \frac{\displaystyle Y - \displaystyle 16}{\displaystyle 219} + \frac{\displaystyle C_b - \displaystyle 128}{\displaystyle 112} * (\displaystyle 1 - \displaystyle k_b) \)

Output image in RGB will have values in range \([0, 1]\).

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_ycbcr2rgb()

AFAPI af_err af_ycbcr2rgb | ( | af_array * | out,
|  | const af_array | in,
|  | const af_ycc_std | standard )

C Interface for converting YCbCr to RGB.

Parameters

  [out] | out | is an array in the RGB color space
  [in] | in | is an array in the YCbCr color space
  [in] | standard | specifies 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]

## ◆ ycbcr2rgb()

AFAPI array ycbcr2rgb | ( | const array & | in,
|  | const YCCStd | standard = AF_YCC_601 )

C++ Interface for converting YCbCr to RGB.

Parameters

  [in] | in | is an array in the YCbCr colorspace
  [in] | standard | specifies the ITU-R BT "xyz" standard which determines the Kb, Kr values used in colorspace conversion equation

Returns
  array in RGB colorspace

Note
  `in` must be three dimensional and values should lie in the range [0,1]