colour.matrix_YCbCr#

colour.matrix_YCbCr(K: NDArrayFloat = WEIGHTS_YCBCR['ITU-R BT.709'], bits: int = 8, is_legal: bool = False, is_int: bool = False) NDArrayFloat[source]#

Compute the Y’CbCr to R’G’B’ matrix for given weights, bit-depth, range legality and representation.

The related offset for the R’G’B’ to Y’CbCr matrix can be computed with the colour.offset_YCbCr() definition.

Parameters:
  • K (NDArrayFloat) – Luma weighting coefficients of red and blue. See colour.WEIGHTS_YCBCR for presets. Default is (0.2126, 0.0722), the weightings for ITU-R BT.709.

  • bits (int) – Bit-depth of the Y’CbCr colour encoding ranges array.

  • is_legal (bool) – Whether the Y’CbCr colour encoding ranges array is legal.

  • is_int (bool) – Whether the Y’CbCr colour encoding ranges array represents int code values.

Returns:

Y’CbCr matrix.

Return type:

numpy.ndarray

Examples

>>> matrix_YCbCr()  
array([[  1.0000000...e+00,  ...,   1.5748000...e+00],
       [  1.0000000...e+00,  -1.8732427...e-01,  -4.6812427...e-01],
       [  1.0000000...e+00,   1.8556000...e+00,  ...]])
>>> matrix_YCbCr(K=WEIGHTS_YCBCR["ITU-R BT.601"])  
array([[  1.0000000...e+00,  ...,   1.4020000...e+00],
       [  1.0000000...e+00,  -3.4413628...e-01,  -7.1413628...e-01],
       [  1.0000000...e+00,   1.7720000...e+00,  ...]])
>>> matrix_YCbCr(is_legal=True)  
array([[  1.1643835...e+00,  ...,   1.7927410...e+00],
       [  1.1643835...e+00,  -2.1324861...e-01,  -5.3290932...e-01],
       [  1.1643835...e+00,   2.1124017...e+00,  ...]])

Matching the default output of the colour.RGB_to_YCbCr() is done as follows:

>>> from colour.algebra import vector_dot
>>> from colour.utilities import as_int_array
>>> RGB = np.array([1.0, 1.0, 1.0])
>>> RGB_to_YCbCr(RGB)  
array([ 0.9215686...,  0.5019607...,  0.5019607...])
>>> YCbCr = vector_dot(np.linalg.inv(matrix_YCbCr(is_legal=True)), RGB)
>>> YCbCr += offset_YCbCr(is_legal=True)
>>> YCbCr  
array([ 0.9215686...,  0.5019607...,  0.5019607...])

Matching the int output of the colour.RGB_to_YCbCr() is done as follows:

>>> RGB = np.array([102, 0, 51])
>>> RGB_to_YCbCr(RGB, in_bits=8, in_int=True, out_bits=8, out_int=True)
... 
array([ 38, 140, 171])
>>> YCbCr = vector_dot(np.linalg.inv(matrix_YCbCr(is_legal=True)), RGB)
>>> YCbCr += offset_YCbCr(is_legal=True, is_int=True)
>>> as_int_array(np.around(YCbCr))
... 
array([ 38, 140, 171])