colour.LUTOperatorMatrix

class colour.LUTOperatorMatrix(matrix=None, offset=None, *args, **kwargs)[source]

Bases: colour.io.luts.operator.AbstractLUTSequenceOperator

Defines the LUT operator supporting a 3x3 or 4x4 matrix and an offset vector.

Parameters
  • matrix (array_like, optional) – 3x3 or 4x4 matrix for the operator.

  • offset (array_like, optional) – Offset for the operator.

  • name (str, optional) – LUT operator name.

  • comments (array_like, optional) – Comments to add to the LUT operator.

Attributes

Methods

Notes

  • The internal colour.io.Matrix.matrix and colour.io.Matrix.offset attributes are reshaped to (4, 4) and (4, ) respectively.

Examples

Instantiating an identity matrix:

>>> print(LUTOperatorMatrix(name='Identity'))
LUTOperatorMatrix - Identity
----------------------------

Matrix     : [[ 1.  0.  0.  0.]
              [ 0.  1.  0.  0.]
              [ 0.  0.  1.  0.]
              [ 0.  0.  0.  1.]]
Offset     : [ 0.  0.  0.  0.]

Instantiating a matrix with comments:

>>> matrix = np.array([[ 1.45143932, -0.23651075, -0.21492857],
...                    [-0.07655377,  1.1762297 , -0.09967593],
...                    [ 0.00831615, -0.00603245,  0.9977163 ]])
>>> print(LUTOperatorMatrix(
...         matrix,
...         name='AP0 to AP1',
...         comments=['A first comment.', 'A second comment.']))
LUTOperatorMatrix - AP0 to AP1
------------------------------

Matrix     : [[ 1.45143932 -0.23651075 -0.21492857  0.        ]
              [-0.07655377  1.1762297  -0.09967593  0.        ]
              [ 0.00831615 -0.00603245  0.9977163   0.        ]
              [ 0.          0.          0.          1.        ]]
Offset     : [ 0.  0.  0.  0.]

A first comment.
A second comment.
__init__(matrix=None, offset=None, *args, **kwargs)[source]
__hash__ = None
property matrix

Getter and setter property for the LUT operator matrix.

Parameters

value (str) – Value to set the LUT operator matrix with.

Returns

Operator matrix.

Return type

str

property offset

Getter and setter property for the LUT operator offset.

Parameters

value (str) – Value to set the LUT operator offset with.

Returns

Operator offset.

Return type

str

__str__()[source]

Returns a formatted string representation of the LUT operator.

Returns

Formatted string representation.

Return type

str

Examples

>>> print(LUTOperatorMatrix())  
LUTOperatorMatrix - LUT Sequence Operator ...
------------------------------------------...

Matrix     : [[ 1.  0.  0.  0.]
              [ 0.  1.  0.  0.]
              [ 0.  0.  1.  0.]
              [ 0.  0.  0.  1.]]
Offset     : [ 0.  0.  0.  0.]
__repr__()[source]

Returns an evaluable string representation of the LUT operator.

Returns

Evaluable string representation.

Return type

str

Examples

>>> LUTOperatorMatrix(
...     comments=['A first comment.', 'A second comment.'])
... 
LUTOperatorMatrix([[ 1.,  0.,  0.,  0.],
                   [ 0.,  1.,  0.,  0.],
                   [ 0.,  0.,  1.,  0.],
                   [ 0.,  0.,  0.,  1.]],
                  [ 0.,  0.,  0.,  0.],
                  name='LUT Sequence Operator ...',
                  comments=['A first comment.', 'A second comment.'])
__eq__(other)[source]

Returns whether the LUT operator is equal to given other object.

Parameters

other (object) – Object to test whether it is equal to the LUT operator.

Returns

Is given object equal to the LUT operator.

Return type

bool

Examples

>>> LUTOperatorMatrix() == LUTOperatorMatrix()
True
__ne__(other)[source]

Returns whether the LUT operator is not equal to given other object.

Parameters

other (object) – Object to test whether it is not equal to the LUT operator.

Returns

Is given object not equal to the LUT operator.

Return type

bool

Examples

>>> LUTOperatorMatrix() != LUTOperatorMatrix(
...     np.linspace(0, 1, 16).reshape([4, 4]))
True
apply(RGB, apply_offset_first=False)[source]

Applies the LUT operator to given RGB array.

Parameters
  • RGB (array_like) – RGB array to apply the LUT operator transform to.

  • apply_offset_first (bool, optional) – Whether to apply the offset first and then the matrix.

Returns

Transformed RGB array.

Return type

ndarray

Examples

>>> matrix = np.array([[ 1.45143932, -0.23651075, -0.21492857],
...                    [-0.07655377,  1.1762297 , -0.09967593],
...                    [ 0.00831615, -0.00603245,  0.9977163 ]])
>>> M = LUTOperatorMatrix(matrix)
>>> RGB = np.array([0.3, 0.4, 0.5])
>>> M.apply(RGB)  
array([ 0.2333632...,  0.3976877...,  0.4989400...])