colour.LUT1D

class colour.LUT1D(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 1D 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 16 elements:

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

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

Instantiating a LUT using a custom table with 16 elements:

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

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

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

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

Dimensions : 1
Domain     : [-0.1  1.5]
Size       : (16,)
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]

While an explicit domain defines every single discrete samples:

[0.0 0.1 0.2 0.4 0.8 1.0]
Returns

Is LUT domain explicit.

Return type

bool

Examples

>>> LUT1D().is_domain_explicit()
False
>>> table = domain = np.linspace(0, 1, 10)
>>> LUT1D(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.

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

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

Returns

Linear table with size samples.

Return type

numpy.ndarray

Examples

>>> LUT1D.linear_table(5, np.array([-0.1, 1.5]))
array([-0.1,  0.3,  0.7,  1.1,  1.5])
>>> LUT1D.linear_table(domain=np.linspace(-0.1, 1.5, 5))
array([-0.1,  0.3,  0.7,  1.1,  1.5])
invert(**kwargs: Any) colour.io.luts.lut.LUT1D[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.LUT1D

Examples

>>> LUT = LUT1D(LUT1D.linear_table() ** (1 / 2.2))
>>> print(LUT.table)  
[ 0.       ...  0.3683438...  0.5047603...  0.6069133...  0.6916988...  0.7655385...
  0.8316843...  0.8920493...  0.9478701...  1.        ]
>>> print(LUT.invert())  
LUT1D - ... - Inverse
--------...----------

Dimensions : 1
Domain     : [ 0.          0.3683438...  0.5047603...  0.6069133...  0.6916988...  0.7655385...
  0.8316843...  0.8920493...  0.9478701...  1.        ]
Size       : (10,)
>>> print(LUT.invert().table)  
[ 0.       ...  0.1111111...  0.2222222...  0.3333333...  0.4444444...  0.5555555...
  0.6666666...  0.7777777...  0.8888888...  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 = LUT1D(LUT1D.linear_table() ** (1 / 2.2))
>>> RGB = np.array([0.18, 0.18, 0.18])

LUT applied to the given RGB colourspace in the forward direction:

>>> LUT.apply(RGB)  
array([ 0.4529220...,  0.4529220...,  0.4529220...])

LUT applied to the modified RGB colourspace in the inverse direction:

>>> LUT.apply(LUT.apply(RGB), direction='Inverse')
... 
array([ 0.18...,  0.18...,  0.18...])
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 = LUT1D()
>>> print(LUT.convert(LUT1D))
LUT1D - Unity 10 - Converted 1D to 1D
-------------------------------------

Dimensions : 1
Domain     : [ 0.  1.]
Size       : (10,)
>>> print(LUT.convert(LUT3x1D))
LUT3x1D - Unity 10 - Converted 1D 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 1D to 3D
-------------------------------------

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