colour.models.rgb Module

RGB Colourspace & Transformations

Defines the RGB_Colourspace class for the RGB colourspaces dataset from colour.models.dataset.aces_rgb, etc... and the following RGB colourspace transformations:

class colour.models.rgb.RGB_Colourspace(name, primaries, whitepoint, illuminant=None, RGB_to_XYZ_matrix=None, XYZ_to_RGB_matrix=None, transfer_function=None, inverse_transfer_function=None)[source]

Bases: object

Implements support for the RGB colourspaces dataset from colour.models.dataset.aces_rgb, etc....

Parameters:
  • name (unicode) – RGB colourspace name.
  • primaries (array_like) – RGB colourspace primaries.
  • whitepoint (array_like) – RGB colourspace whitepoint.
  • illuminant (unicode, optional) – RGB colourspace whitepoint name as illuminant.
  • RGB_to_XYZ_matrix (array_like, optional) – Transformation matrix from colourspace to CIE XYZ tristimulus values.
  • XYZ_to_RGB_matrix (array_like, optional) – Transformation matrix from CIE XYZ tristimulus values to colourspace.
  • transfer_function (object, optional) – RGB colourspace opto-electronic conversion function from linear to colourspace.
  • inverse_transfer_function (object, optional) – RGB colourspace inverse opto-electronic conversion function from colourspace to linear.
RGB_to_XYZ_matrix[source]

Property for self.__to_XYZ private attribute.

Returns:self.__to_XYZ.
Return type:array_like, (3, 3)
XYZ_to_RGB_matrix[source]

Property for self.__to_RGB private attribute.

Returns:self.__to_RGB.
Return type:array_like, (3, 3)
illuminant[source]

Property for self.__illuminant private attribute.

Returns:self.__illuminant.
Return type:unicode
inverse_transfer_function[source]

Property for self.__inverse_transfer_function private attribute.

Returns:self.__inverse_transfer_function.
Return type:object
name[source]

Property for self.__name private attribute.

Returns:self.__name.
Return type:unicode
primaries[source]

Property for self.__primaries private attribute.

Returns:self.__primaries.
Return type:array_like, (3, 2)
transfer_function[source]

Property for self.__transfer_function private attribute.

Returns:self.__transfer_function.
Return type:object
whitepoint[source]

Property for self.__whitepoint private attribute.

Returns:self.__whitepoint.
Return type:array_like
colour.models.rgb.XYZ_to_RGB(XYZ, illuminant_XYZ, illuminant_RGB, XYZ_to_RGB_matrix, chromatic_adaptation_transform=u'CAT02', transfer_function=None)[source]

Converts from CIE XYZ tristimulus values to given RGB colourspace.

Parameters:
  • XYZ (array_like) – CIE XYZ tristimulus values
  • illuminant_XYZ (array_like) – CIE XYZ tristimulus values illuminant xy chromaticity coordinates.
  • illuminant_RGB (array_like) – RGB colourspace illuminant xy chromaticity coordinates.
  • XYZ_to_RGB_matrix (array_like) – Normalised primary matrix.
  • chromatic_adaptation_transform (unicode, optional) – {‘CAT02’, ‘XYZ Scaling’, ‘Von Kries’, ‘Bradford’, ‘Sharp’, ‘Fairchild, ‘CMCCAT97’, ‘CMCCAT2000’, ‘CAT02_BRILL_CAT’, ‘Bianco’, ‘Bianco PC’}, Chromatic adaptation transform.
  • transfer_function (object, optional) – Transfer function.
Returns:

RGB colourspace array.

Return type:

ndarray

Notes

  • Input CIE XYZ tristimulus values are 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 array is in domain [0, 1].

Examples

>>> XYZ = np.array([0.07049534, 0.10080000, 0.09558313])
>>> illuminant_XYZ = np.array([0.34567, 0.35850])
>>> illuminant_RGB = np.array([0.31271, 0.32902])
>>> chromatic_adaptation_transform = 'Bradford'
>>> XYZ_to_RGB_matrix = np.array([
...     [3.24100326, -1.53739899, -0.49861587],
...     [-0.96922426, 1.87592999, 0.04155422],
...     [0.05563942, -0.20401120, 1.05714897]])
>>> XYZ_to_RGB(
...     XYZ,
...     illuminant_XYZ,
...     illuminant_RGB,
...     XYZ_to_RGB_matrix,
...     chromatic_adaptation_transform)  
array([ 0.0110360...,  0.1273446...,  0.1163103...])
colour.models.rgb.RGB_to_XYZ(RGB, illuminant_RGB, illuminant_XYZ, RGB_to_XYZ_matrix, chromatic_adaptation_transform=u'CAT02', inverse_transfer_function=None)[source]

Converts from given RGB colourspace to CIE XYZ tristimulus values.

Parameters:
  • RGB (array_like) – RGB colourspace array.
  • illuminant_RGB (array_like) – RGB colourspace illuminant chromaticity coordinates.
  • illuminant_XYZ (array_like) – CIE XYZ tristimulus values illuminant chromaticity coordinates.
  • RGB_to_XYZ_matrix (array_like) – Normalised primary matrix.
  • chromatic_adaptation_transform (unicode, optional) – {‘CAT02’, ‘XYZ Scaling’, ‘Von Kries’, ‘Bradford’, ‘Sharp’, ‘Fairchild, ‘CMCCAT97’, ‘CMCCAT2000’, ‘CAT02_BRILL_CAT’, ‘Bianco’, ‘Bianco PC’}, Chromatic adaptation transform.
  • inverse_transfer_function (object, optional) – Inverse transfer function.
Returns:

CIE XYZ tristimulus values.

Return type:

ndarray

Notes

  • Input RGB colourspace array 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 tristimulus values are in domain [0, 1].

Examples

>>> RGB = np.array([0.01103604, 0.12734466, 0.11631037])
>>> illuminant_RGB = np.array([0.31271, 0.32902])
>>> illuminant_XYZ = np.array([0.34567, 0.35850])
>>> chromatic_adaptation_transform = 'Bradford'
>>> RGB_to_XYZ_matrix = np.array([
...     [0.41238656, 0.35759149, 0.18045049],
...     [0.21263682, 0.71518298, 0.07218020],
...     [0.01933062, 0.11919716, 0.95037259]])
>>> RGB_to_XYZ(
...     RGB,
...     illuminant_RGB,
...     illuminant_XYZ,
...     RGB_to_XYZ_matrix,
...     chromatic_adaptation_transform)  
array([ 0.0704953...,  0.1008    ,  0.0955831...])
colour.models.rgb.RGB_to_RGB(RGB, input_colourspace, output_colourspace, chromatic_adaptation_transform=u'CAT02')[source]

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

Parameters:
  • RGB (array_like) – RGB colourspace array.
  • input_colourspace (RGB_Colourspace) – RGB input colourspace.
  • output_colourspace (RGB_Colourspace) – RGB output colourspace.
  • chromatic_adaptation_transform (unicode, optional) – {‘CAT02’, ‘XYZ Scaling’, ‘Von Kries’, ‘Bradford’, ‘Sharp’, ‘Fairchild, ‘CMCCAT97’, ‘CMCCAT2000’, ‘CAT02_BRILL_CAT’, ‘Bianco’, ‘Bianco PC’}, Chromatic adaptation transform.
  • ndarrayRGB colourspace array.

Notes

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

Examples

>>> from colour import sRGB_COLOURSPACE, PROPHOTO_RGB_COLOURSPACE
>>> RGB = np.array([0.01103604, 0.12734466, 0.11631037])
>>> RGB_to_RGB(
...     RGB,
...     sRGB_COLOURSPACE,
...     PROPHOTO_RGB_COLOURSPACE)  
array([ 0.0643338...,  0.1157362...,  0.1157614...])