colour.LUT3x1D

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

Bases: colour.io.luts.lut.AbstractLUT

Defines the base class for a 3x1D 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 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=None, name=None, domain=None, size=10, comments=None)[source]

Initialize self. See help(type(self)) for accurate signature.

is_domain_explicit()[source]

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

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

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

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

Returns

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

Return type

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]])
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.

Other Parameters

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

Returns

Interpolated RGB colourspace array.

Return type

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...])
>>> 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...])
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.

Other Parameters
  • 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 = LUT3x1D()
>>> print(LUT.as_LUT(LUT1D, force_conversion=True))
LUT1D - Unity 10 - Converted 3x1D to 1D
---------------------------------------

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

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