colour.LUT1D

class colour.LUT1D(table=None, name=None, domain=None, size=10, comments=None)[source]

Bases: colour.io.luts.lut.AbstractLUT

Defines the base class for a 1D LUT.

Parameters
  • table (array_like, optional) – Underlying LUT table.

  • name (unicode, optional) – LUT name.

  • domain (unicode, optional) – LUT domain, also used to define the instantiation time default table domain.

  • size (int, optional) – Size of the instantiation time default table.

  • comments (array_like, optional) – 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=None, name=None, domain=None, size=10, comments=None)[source]
is_domain_explicit()[source]

Returns 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=10, domain=array([0, 1]))[source]

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

Parameters
  • size (int, optional) – Expected table size.

  • domain (array_like, optional) – Domain of the table.

Returns

Linear table with size samples.

Return type

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])
apply(RGB, interpolator=<class 'colour.algebra.interpolation.LinearInterpolator'>, interpolator_kwargs=None, **kwargs)[source]

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

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

  • interpolator (object, optional) – Interpolator class type to use as interpolating function.

  • interpolator_kwargs (dict_like, optional) – Arguments to use when instantiating the interpolating function.

  • **kwargs (dict, optional) – Keywords arguments for deprecation management.

Returns

Interpolated RGB colourspace array.

Return type

ndarray

Examples

>>> LUT = LUT1D(LUT1D.linear_table() ** (1 / 2.2))
>>> RGB = np.array([0.18, 0.18, 0.18])
>>> LUT.apply(RGB)  
array([ 0.4529220...,  0.4529220...,  0.4529220...])
as_LUT(cls, force_conversion=False, **kwargs)[source]

Converts the LUT to given cls class instance.

Parameters
  • cls (LUT1D or LUT3x1D or LUT3D) – LUT class instance.

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

  • interpolator (object, optional) – Interpolator class type to use as interpolating function.

  • interpolator_kwargs (dict_like, optional) – Arguments to use when instantiating the interpolating function.

  • size (int, optional) – Expected table size in case of an upcast to a LUT3D class instance.

Returns

Converted LUT class instance.

Return type

LUT1D or LUT3x1D or LUT3D

Warning

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

Raises

ValueError – If the conversion is destructive.

Examples

>>> LUT = LUT1D()
>>> print(LUT.as_LUT(LUT1D))
LUT1D - Unity 10 - Converted 1D to 1D
-------------------------------------

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

Dimensions : 2
Domain     : [[ 0.  0.  0.]
              [ 1.  1.  1.]]
Size       : (10, 3)
>>> print(LUT.as_LUT(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)