colour.LUT3x1D#

class colour.LUT3x1D(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 3x1D 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 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: 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]
 [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: ArrayLike | None = None, domain: ArrayLike | None = None) NDArrayFloat[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 (ArrayLike | None) – Expected table size, default to 10.

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