colour.models.rgb Module

RGB Colourspace Transformations

Defines the RGB colourspace transformations:

colour.models.rgb.XYZ_to_RGB(XYZ, illuminant_XYZ, illuminant_RGB, to_RGB, chromatic_adaptation_method=u'CAT02', transfer_function=None)[source]

Converts from CIE XYZ colourspace to RGB colourspace using given CIE XYZ colourspace matrix, illuminants, chromatic adaptation method, normalised primary matrix and transfer function.

Parameters:
  • XYZ (array_like, (3,)) – CIE XYZ colourspace matrix.
  • illuminant_XYZ (array_like) – CIE XYZ colourspace illuminant xy chromaticity coordinates.
  • illuminant_RGB (array_like) – RGB colourspace illuminant xy chromaticity coordinates.
  • to_RGB (array_like, (3, 3)) – Normalised primary matrix.
  • chromatic_adaptation_method (unicode, optional) – (‘XYZ Scaling’, ‘Bradford’, ‘Von Kries’, ‘Fairchild’, ‘CAT02’) Chromatic adaptation method.
  • transfer_function (object, optional) – Transfer function.
Returns:

RGB colourspace matrix.

Return type:

ndarray, (3,)

Notes

  • Input CIE XYZ colourspace matrix is in domain [0, 1].
  • Input illuminant_XYZ xy chromaticity coordinates are in domain [0, 1].
  • Input illuminant_RGB xy chromaticity coordinates are in domain [0, 1].
  • Output RGB colourspace matrix is in domain [0, 1].

Examples

>>> XYZ = np.array([0.1151847498, 0.1008, 0.0508937252])
>>> illuminant_XYZ = (0.34567, 0.35850)
>>> illuminant_RGB = (0.31271, 0.32902)
>>> chromatic_adaptation_method =  'Bradford'
>>> to_RGB = np.array([
...     [3.24100326, -1.53739899, -0.49861587],
...     [-0.96922426, 1.87592999, 0.04155422],
...     [0.05563942, -0.2040112, 1.05714897]])
>>> XYZ_to_RGB(
...     XYZ,
...     illuminant_XYZ,
...     illuminant_RGB,
...     to_RGB,
...     chromatic_adaptation_method)  
array([ 0.1730350...,  0.0821103...,  0.0567249...])
colour.models.rgb.RGB_to_XYZ(RGB, illuminant_RGB, illuminant_XYZ, to_XYZ, chromatic_adaptation_method=u'CAT02', inverse_transfer_function=None)[source]

Converts from RGB colourspace to CIE XYZ colourspace using given RGB colourspace matrix, illuminants, chromatic adaptation method, normalised primary matrix and transfer function.

Parameters:
  • RGB (array_like, (3,)) – RGB colourspace matrix.
  • illuminant_RGB (array_like) – RGB colourspace illuminant chromaticity coordinates.
  • illuminant_XYZ (array_like) – CIE XYZ colourspace illuminant chromaticity coordinates.
  • to_XYZ (array_like, (3, 3)) – Normalised primary matrix.
  • chromatic_adaptation_method (unicode, optional) – (‘XYZ Scaling’, ‘Bradford’, ‘Von Kries’, ‘Fairchild’, ‘CAT02’) Chromatic adaptation method.
  • inverse_transfer_function (object, optional) – Inverse transfer function.
Returns:

CIE XYZ colourspace matrix.

Return type:

ndarray, (3,)

Notes

  • Input RGB colourspace matrix is in domain [0, 1].
  • Input illuminant_RGB xy chromaticity coordinates are in domain [0, 1].
  • Input illuminant_XYZ xy chromaticity coordinates are in domain [0, 1].
  • Output CIE XYZ colourspace matrix is in domain [0, 1].

Examples

>>> RGB = np.array([0.17303501, 0.08211033, 0.05672498])
>>> illuminant_RGB = (0.31271, 0.32902)
>>> illuminant_XYZ = (0.34567, 0.35850)
>>> chromatic_adaptation_method = 'Bradford'
>>> to_XYZ = np.array([
...     [0.41238656, 0.35759149, 0.18045049],
...     [0.21263682, 0.71518298, 0.0721802],
...     [0.01933062, 0.11919716, 0.95037259]])
>>> RGB_to_XYZ(
...     RGB,
...     illuminant_RGB,
...     illuminant_XYZ,
...     to_XYZ,
...     chromatic_adaptation_method)  
array([ 0.1151847...,  0.1008    ,  0.0508937...])
colour.models.rgb.RGB_to_RGB(RGB, input_colourspace, output_colourspace, chromatic_adaptation_method=u'CAT02')[source]

Converts from given input RGB colourspace to output RGB colourspace using given chromatic adaptation method.

Parameters:
  • RGB (array_like, (3,)) – RGB colourspace matrix.
  • input_colourspace (RGB_Colourspace) – RGB input colourspace.
  • output_colourspace (RGB_Colourspace) – RGB output colourspace.
  • chromatic_adaptation_method (unicode, optional) – (‘XYZ Scaling’, ‘Bradford’, ‘Von Kries’, ‘Fairchild’, ‘CAT02’) Chromatic adaptation method.
  • (3,) (ndarray,) – RGB colourspace matrix.

Notes

  • RGB colourspace matrices are in domain [0, 1].

Examples

>>> from colour import sRGB_COLOURSPACE, PROPHOTO_RGB_COLOURSPACE
>>> RGB = np.array([0.35521588, 0.41, 0.24177934])
>>> RGB_to_RGB(
...     RGB,
...     sRGB_COLOURSPACE,
...     PROPHOTO_RGB_COLOURSPACE)  
array([ 0.3579334...,  0.4007138...,  0.2615704...])