colour.models.rgb.derivation Module

RGB Colourspace Derivation

Defines objects related to RGB colourspace derivation, essentially calculating the normalised primary matrix for given RGB colourspace primaries and whitepoint:

References

[1]Society of Motion Picture and Television Engineers. (1993). Derivation of Basic Television Color Equations. In RP 177:1993 (Vol. RP 177:199). doi:10.5594/S9781614821915
colour.models.rgb.derivation.xy_to_z(xy)[source]

Returns the z coordinate using given \(xy\) chromaticity coordinates.

Parameters:xy (array_like) – \(xy\) chromaticity coordinates.
Returns:z coordinate.
Return type:numeric

Examples

>>> xy_to_z(np.array([0.25, 0.25]))
0.5
colour.models.rgb.derivation.normalised_primary_matrix(primaries, whitepoint)[source]

Returns the normalised primary matrix using given primaries and whitepoint \(xy\) chromaticity coordinates.

Parameters:
  • primaries (array_like, (3, 2)) – Primaries \(xy\) chromaticity coordinates.
  • whitepoint (array_like) – Illuminant / whitepoint \(xy\) chromaticity coordinates.
Returns:

Normalised primary matrix.

Return type:

ndarray, (3, 3)

Examples

>>> p = np.array([0.73470, 0.26530, 0.00000, 1.00000, 0.00010, -0.07700])
>>> whitepoint = np.array([0.32168, 0.33767])
>>> normalised_primary_matrix(p, whitepoint)  
array([[  9.5255239...e-01,   0.0000000...e+00,   9.3678631...e-05],
       [  3.4396645...e-01,   7.2816609...e-01,  -7.2132546...e-02],
       [  0.0000000...e+00,   0.0000000...e+00,   1.0088251...e+00]])
colour.models.rgb.derivation.chromatically_adapted_primaries(primaries, whitepoint_t, whitepoint_r, chromatic_adaptation_transform=u'CAT02')[source]

Chromatically adapts given primaries \(xy\) chromaticity coordinates from test whitepoint_t to reference whitepoint_r.

Parameters:
  • primaries (array_like, (3, 2)) – Primaries \(xy\) chromaticity coordinates.
  • whitepoint_t (array_like) – Test illuminant / whitepoint \(xy\) chromaticity coordinates.
  • whitepoint_r (array_like) – Reference illuminant / whitepoint \(xy\) chromaticity coordinates.
  • chromatic_adaptation_transform (unicode, optional) – {‘CAT02’, ‘XYZ Scaling’, ‘Von Kries’, ‘Bradford’, ‘Sharp’, ‘Fairchild’, ‘CMCCAT97’, ‘CMCCAT2000’, ‘CAT02_BRILL_CAT’, ‘Bianco’, ‘Bianco PC’}, Chromatic adaptation transform.
Returns:

Chromatically adapted primaries \(xy\) chromaticity coordinates.

Return type:

ndarray

Examples

>>> p = np.array([0.64, 0.33, 0.30, 0.60, 0.15, 0.06])
>>> whitepoint_t = np.array([0.31270, 0.32900])
>>> whitepoint_r = np.array([0.34570, 0.35850])
>>> chromatic_adaptation_transform = 'Bradford'
>>> chromatically_adapted_primaries(  
...     p,
...     whitepoint_t,
...     whitepoint_r,
...     chromatic_adaptation_transform)
array([[ 0.6484414...,  0.3308533...],
       [ 0.3211951...,  0.5978443...],
       [ 0.1558932...,  0.0660492...]])
colour.models.rgb.derivation.primaries_whitepoint(npm)[source]

Returns the primaries and whitepoint \(xy\) chromaticity coordinates using given normalised primary matrix.

Parameters:npm (array_like, (3, 3)) – Normalised primary matrix.
Returns:Primaries and whitepoint \(xy\) chromaticity coordinates.
Return type:tuple

References

[2]Trieu, T. (2015). Private Discussion with Mansencal, T.

Examples

>>> npm = np.array([[9.52552396e-01, 0.00000000e+00, 9.36786317e-05],
...                 [3.43966450e-01, 7.28166097e-01, -7.21325464e-02],
...                 [0.00000000e+00, 0.00000000e+00, 1.00882518e+00]])
>>> p, w = primaries_whitepoint(npm)
>>> p  
array([[  7.3470000...e-01,   2.6530000...e-01],
       [  0.0000000...e+00,   1.0000000...e+00],
       [  1.0000000...e-04,  -7.7000000...e-02]])
>>> w 
array([ 0.32168,  0.33767])
colour.models.rgb.derivation.RGB_luminance_equation(primaries, whitepoint)[source]

Returns the luminance equation from given primaries and whitepoint.

Parameters:
  • primaries (array_like, (3, 2)) – Primaries chromaticity coordinates.
  • whitepoint (array_like) – Illuminant / whitepoint chromaticity coordinates.
Returns:

Luminance equation.

Return type:

unicode

Examples

>>> p = np.array([0.73470, 0.26530, 0.00000, 1.00000, 0.00010, -0.07700])
>>> whitepoint = np.array([0.32168, 0.33767])
>>> # Doctests skip for Python 2.x compatibility.
>>> RGB_luminance_equation(p, whitepoint)  
'Y = 0.3439664...(R) + 0.7281660...(G) + -0.0721325...(B)'
colour.models.rgb.derivation.RGB_luminance(RGB, primaries, whitepoint)[source]

Returns the luminance \(Y\) of given RGB components from given primaries and whitepoint.

Parameters:
  • RGB (array_like) – RGB chromaticity coordinate matrix.
  • primaries (array_like, (3, 2)) – Primaries chromaticity coordinate matrix.
  • whitepoint (array_like) – Illuminant / whitepoint chromaticity coordinates.
Returns:

Luminance \(Y\).

Return type:

numeric or ndarray

Examples

>>> RGB = np.array([40.6, 4.2, 67.4])
>>> p = np.array([0.73470, 0.26530, 0.00000, 1.00000, 0.00010, -0.07700])
>>> whitepoint = np.array([0.32168, 0.33767])
>>> RGB_luminance(RGB, p, whitepoint)  
12.1616018...