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:
AbstractLUTDefine the base class for a 1D LUT.
A 1D (one-dimensional) lookup table provides a mapping function from input values to output values through interpolation of discrete table entries. This class is commonly used for tone mapping, gamma correction, and other single-channel transformations where the output depends solely on the input value.
- 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]#
- 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:
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: TypeAliasForwardRef('ArrayLike') | None = None, domain: TypeAliasForwardRef('ArrayLike') | None = None) NDArrayFloat[source]#
Generate a linear table with the specified number of output samples \(n\).
The table contains linearly spaced values across the specified domain. If no domain is provided, the default domain [0, 1] is used.
- Parameters:
size (TypeAliasForwardRef('ArrayLike') | None) – Number of samples in the output table. Default is 10.
domain (TypeAliasForwardRef('ArrayLike') | None) – Domain boundaries of the table as a 2-element array [min, max] or an array of values whose minimum and maximum define the domain. Default is [0, 1].
- Returns:
Linear table containing
sizeevenly spaced samples across the specified domain.- Return type:
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 return an inverse copy of the LUT.
- Parameters:
kwargs (Any) – Keywords arguments, only specified for signature compatibility with the
AbstractLUT.invert()method.- Returns:
Inverse LUT class instance.
- Return type:
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 the specified RGB colourspace array using the specified 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:
Examples
>>> LUT = LUT1D(LUT1D.linear_table() ** (1 / 2.2)) >>> RGB = np.array([0.18, 0.18, 0.18])
LUT applied to the specified 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...])