colour.LUT1D#

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

Bases: AbstractLUT

Define the base class for a 1D LUT.

Parameters:
  • table (ArrayLike | None) – Underlying LUT table.

  • name (str | None) – LUT name.

  • domain (ArrayLike | None) – LUT domain, also used to define the instantiation time default table domain.

  • size (ArrayLike | None) – Size of the instantiation time default table, default to 10.

  • comments (Sequence | None) – 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: ArrayLike | None = None, name: str | None = None, domain: ArrayLike | None = None, size: ArrayLike | None = None, comments: Sequence | None = None) None[source]#
Parameters:
  • table (ArrayLike | None)

  • name (str | None)

  • domain (ArrayLike | None)

  • size (ArrayLike | None)

  • comments (Sequence | None)

Return type:

None

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: ArrayLike | None = None, domain: ArrayLike | None = None) NDArrayFloat[source]#

Return a linear table, the number of output samples \(n\) is equal to size.

Parameters:
  • size (ArrayLike | None) – Expected table size, default to 10.

  • domain (ArrayLike | None) – 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) 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) NDArrayFloat[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...])