colour.LUT3x1D#

class colour.LUT3x1D(table: Optional[ArrayLike] = None, name: Optional[str] = None, domain: Optional[ArrayLike] = None, size: Optional[IntegerOrArrayLike] = None, comments: Optional[Sequence] = None)[source]#

Bases: colour.io.luts.lut.AbstractLUT

Define the base class for a 3x1D LUT.

Parameters
  • table (Optional[ArrayLike]) – Underlying LUT table.

  • name (Optional[str]) – LUT name.

  • domain (Optional[ArrayLike]) – LUT domain, also used to define the instantiation time default table domain.

  • size (Optional[IntegerOrArrayLike]) – Size of the instantiation time default table, default to 10.

  • comments (Optional[Sequence]) – Comments to add to the LUT.

Methods

Examples

Instantiating a unity LUT with a table with 16x3 elements:

>>> print(LUT3x1D(size=16))
LUT3x1D - Unity 16
------------------

Dimensions : 2
Domain     : [[ 0.  0.  0.]
              [ 1.  1.  1.]]
Size       : (16, 3)

Instantiating a LUT using a custom table with 16x3 elements:

>>> print(LUT3x1D(LUT3x1D.linear_table(16) ** (1 / 2.2)))
... 
LUT3x1D - ...
----------...

Dimensions : 2
Domain     : [[ 0.  0.  0.]
              [ 1.  1.  1.]]
Size       : (16, 3)

Instantiating a LUT using a custom table with 16x3 elements, custom name, custom domain and comments:

>>> from colour.algebra import spow
>>> domain = np.array([[-0.1, -0.2, -0.4], [1.5, 3.0, 6.0]])
>>> print(LUT3x1D(
...     spow(LUT3x1D.linear_table(16), 1 / 2.2),
...     'My LUT',
...     domain,
...     comments=['A first comment.', 'A second comment.']))
LUT3x1D - My LUT
----------------

Dimensions : 2
Domain     : [[-0.1 -0.2 -0.4]
              [ 1.5  3.   6. ]]
Size       : (16, 3)
Comment 01 : A first comment.
Comment 02 : A second comment.
__init__(table: Optional[ArrayLike] = None, name: Optional[str] = None, domain: Optional[ArrayLike] = None, size: Optional[IntegerOrArrayLike] = None, comments: Optional[Sequence] = None)[source]#
Parameters
  • table (Optional[ArrayLike]) –

  • name (Optional[str]) –

  • domain (Optional[ArrayLike]) –

  • size (Optional[IntegerOrArrayLike]) –

  • comments (Optional[Sequence]) –

is_domain_explicit() bool[source]#

Return whether the LUT domain is explicit (or implicit).

An implicit domain is defined by its shape only:

[[0 1]
 [0 1]
 [0 1]]

While an explicit domain defines every single discrete samples:

[[0.0 0.0 0.0]
 [0.1 0.1 0.1]
 [0.2 0.2 0.2]
 [0.3 0.3 0.3]
 [0.4 0.4 0.4]
 [0.8 0.8 0.8]
 [1.0 1.0 1.0]]
Returns

Is LUT domain explicit.

Return type

bool

Examples

>>> LUT3x1D().is_domain_explicit()
False
>>> samples = np.linspace(0, 1, 10)
>>> table = domain = tstack([samples, samples, samples])
>>> LUT3x1D(table, domain=domain).is_domain_explicit()
True
static linear_table(size: Optional[IntegerOrArrayLike] = None, domain: Optional[ArrayLike] = None) NDArray[source]#

Return a linear table, the number of output samples \(n\) is equal to size * 3 or size[0] + size[1] + size[2].

Parameters
  • size (Optional[IntegerOrArrayLike]) – Expected table size, default to 10.

  • domain (Optional[ArrayLike]) – Domain of the table.

Returns

Linear table with size * 3 or size[0] + size[1] + size[2] samples.

Return type

numpy.ndarray

Warning

If size is non uniform, the linear table will be padded accordingly.

Examples

>>> LUT3x1D.linear_table(
...     5, np.array([[-0.1, -0.2, -0.4], [1.5, 3.0, 6.0]]))
array([[-0.1, -0.2, -0.4],
       [ 0.3,  0.6,  1.2],
       [ 0.7,  1.4,  2.8],
       [ 1.1,  2.2,  4.4],
       [ 1.5,  3. ,  6. ]])
>>> LUT3x1D.linear_table(
...     np.array([5, 3, 2]),
...     np.array([[-0.1, -0.2, -0.4], [1.5, 3.0, 6.0]]))
array([[-0.1, -0.2, -0.4],
       [ 0.3,  1.4,  6. ],
       [ 0.7,  3. ,  nan],
       [ 1.1,  nan,  nan],
       [ 1.5,  nan,  nan]])
>>> domain = np.array([[-0.1, -0.2, -0.4],
...                    [0.3, 1.4, 6.0],
...                    [0.7, 3.0, np.nan],
...                    [1.1, np.nan, np.nan],
...                    [1.5, np.nan, np.nan]])
>>> LUT3x1D.linear_table(domain=domain)
array([[-0.1, -0.2, -0.4],
       [ 0.3,  1.4,  6. ],
       [ 0.7,  3. ,  nan],
       [ 1.1,  nan,  nan],
       [ 1.5,  nan,  nan]])
invert(**kwargs: Any) colour.io.luts.lut.LUT3x1D[source]#

Compute and returns an inverse copy of the LUT.

Parameters

kwargs (Any) – Keywords arguments, only given for signature compatibility with the AbstractLUT.invert() method.

Returns

Inverse LUT class instance.

Return type

colour.LUT3x1D

Examples

>>> LUT = LUT3x1D(LUT3x1D.linear_table() ** (1 / 2.2))
>>> print(LUT.table)
[[ 0.          0.          0.        ]
 [ 0.36834383  0.36834383  0.36834383]
 [ 0.50476034  0.50476034  0.50476034]
 [ 0.60691337  0.60691337  0.60691337]
 [ 0.69169882  0.69169882  0.69169882]
 [ 0.76553851  0.76553851  0.76553851]
 [ 0.83168433  0.83168433  0.83168433]
 [ 0.89204934  0.89204934  0.89204934]
 [ 0.94787016  0.94787016  0.94787016]
 [ 1.          1.          1.        ]]
>>> print(LUT.invert())  
LUT3x1D - ... - Inverse
----------...----------

Dimensions : 2
Domain     : [[ 0.       ...  0.       ...  0.       ...]
              [ 0.3683438...  0.3683438...  0.3683438...]
              [ 0.5047603...  0.5047603...  0.5047603...]
              [ 0.6069133...  0.6069133...  0.6069133...]
              [ 0.6916988...  0.6916988...  0.6916988...]
              [ 0.7655385...  0.7655385...  0.7655385...]
              [ 0.8316843...  0.8316843...  0.8316843...]
              [ 0.8920493...  0.8920493...  0.8920493...]
              [ 0.9478701...  0.9478701...  0.9478701...]
              [ 1.       ...  1.       ...  1.       ...]]
Size       : (10, 3)
>>> print(LUT.invert().table)  
[[ 0.       ...  0.       ...  0.       ...]
 [ 0.1111111...  0.1111111...  0.1111111...]
 [ 0.2222222...  0.2222222...  0.2222222...]
 [ 0.3333333...  0.3333333...  0.3333333...]
 [ 0.4444444...  0.4444444...  0.4444444...]
 [ 0.5555555...  0.5555555...  0.5555555...]
 [ 0.6666666...  0.6666666...  0.6666666...]
 [ 0.7777777...  0.7777777...  0.7777777...]
 [ 0.8888888...  0.8888888...  0.8888888...]
 [ 1.       ...  1.       ...  1.       ...]]
apply(RGB: ArrayLike, **kwargs: Any) numpy.ndarray[source]#

Apply the LUT to given RGB colourspace array using given method.

Parameters
  • RGB (ArrayLike) – RGB colourspace array to apply the LUT onto.

  • direction – Whether the LUT should be applied in the forward or inverse direction.

  • extrapolator – Extrapolator class type or object to use as extrapolating function.

  • extrapolator_kwargs – Arguments to use when instantiating or calling the extrapolating function.

  • interpolator – Interpolator class type to use as interpolating function.

  • interpolator_kwargs – Arguments to use when instantiating the interpolating function.

  • kwargs (Any) –

Returns

Interpolated RGB colourspace array.

Return type

numpy.ndarray

Examples

>>> LUT = LUT3x1D(LUT3x1D.linear_table() ** (1 / 2.2))
>>> RGB = np.array([0.18, 0.18, 0.18])
>>> LUT.apply(RGB)  
array([ 0.4529220...,  0.4529220...,  0.4529220...])
>>> LUT.apply(LUT.apply(RGB), direction='Inverse')
... 
array([ 0.18...,  0.18...,  0.18...])
>>> from colour.algebra import spow
>>> domain = np.array([[-0.1, -0.2, -0.4], [1.5, 3.0, 6.0]])
>>> table = spow(LUT3x1D.linear_table(domain=domain), 1 / 2.2)
>>> LUT = LUT3x1D(table, domain=domain)
>>> RGB = np.array([0.18, 0.18, 0.18])
>>> LUT.apply(RGB)  
array([ 0.4423903...,  0.4503801...,  0.3581625...])
>>> domain = np.array([[-0.1, -0.2, -0.4],
...                    [0.3, 1.4, 6.0],
...                    [0.7, 3.0, np.nan],
...                    [1.1, np.nan, np.nan],
...                    [1.5, np.nan, np.nan]])
>>> table = spow(LUT3x1D.linear_table(domain=domain), 1 / 2.2)
>>> LUT = LUT3x1D(table, domain=domain)
>>> RGB = np.array([0.18, 0.18, 0.18])
>>> LUT.apply(RGB)  
array([ 0.2996370..., -0.0901332..., -0.3949770...])
convert(cls: Type[colour.io.luts.lut.AbstractLUT], force_conversion: bool = False, **kwargs: Any) colour.io.luts.lut.AbstractLUT[source]#

Convert the LUT to given cls class instance.

Parameters
  • cls (Type[colour.io.luts.lut.AbstractLUT]) – LUT class instance.

  • force_conversion (bool) – Whether to force the conversion as it might be destructive.

  • interpolator – Interpolator class type to use as interpolating function.

  • interpolator_kwargs – Arguments to use when instantiating the interpolating function.

  • size – Expected table size in case of an upcast to a LUT3D class instance.

  • kwargs (Any) –

Returns

Converted LUT class instance.

Return type

colour.LUT1D or colour.LUT3x1D or colour.LUT3D

Warning

Some conversions are destructive and raise a ValueError exception by default.

Raises

ValueError – If the conversion is destructive.

Parameters
  • cls (Type[colour.io.luts.lut.AbstractLUT]) –

  • force_conversion (bool) –

  • kwargs (Any) –

Return type

colour.io.luts.lut.AbstractLUT

Examples

>>> LUT = LUT3x1D()
>>> print(LUT.convert(LUT1D, force_conversion=True))
LUT1D - Unity 10 - Converted 3x1D to 1D
---------------------------------------

Dimensions : 1
Domain     : [ 0.  1.]
Size       : (10,)
>>> print(LUT.convert(LUT3x1D))
LUT3x1D - Unity 10 - Converted 3x1D to 3x1D
-------------------------------------------

Dimensions : 2
Domain     : [[ 0.  0.  0.]
              [ 1.  1.  1.]]
Size       : (10, 3)
>>> print(LUT.convert(LUT3D, force_conversion=True))
LUT3D - Unity 10 - Converted 3x1D to 3D
---------------------------------------

Dimensions : 3
Domain     : [[ 0.  0.  0.]
              [ 1.  1.  1.]]
Size       : (33, 33, 33, 3)