colour.LUT3D¶
- class colour.LUT3D(table=None, name=None, domain=None, size=33, comments=None)[source]¶
Bases:
colour.io.luts.lut.AbstractLUT
Defines the base class for a 3D 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 16x16x16x3 elements:
>>> print(LUT3D(size=16)) LUT3D - Unity 16 ---------------- Dimensions : 3 Domain : [[ 0. 0. 0.] [ 1. 1. 1.]] Size : (16, 16, 16, 3)
Instantiating a LUT using a custom table with 16x16x16x3 elements:
>>> print(LUT3D(LUT3D.linear_table(16) ** (1 / 2.2))) LUT3D - ... --------... Dimensions : 3 Domain : [[ 0. 0. 0.] [ 1. 1. 1.]] Size : (16, 16, 16, 3)
Instantiating a LUT using a custom table with 16x16x16x3 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(LUT3D( ... spow(LUT3D.linear_table(16), 1 / 2.2), ... 'My LUT', ... domain, ... comments=['A first comment.', 'A second comment.'])) LUT3D - My LUT -------------- Dimensions : 3 Domain : [[-0.1 -0.2 -0.4] [ 1.5 3. 6. ]] Size : (16, 16, 16, 3) Comment 01 : A first comment. Comment 02 : A second comment.
- is_domain_explicit()[source]¶
Returns whether the LUT domain is explicit (or implicit).
An implicit domain is defined by its shape only:
[[0 0 0] [1 1 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
Examples
>>> LUT3D().is_domain_explicit() False >>> domain = np.array([[-0.1, -0.2, -0.4], ... [0.7, 1.4, 6.0], ... [1.5, 3.0, np.nan]]) >>> LUT3D(domain=domain).is_domain_explicit() True
- static linear_table(size=33, domain=array([[0, 0, 0], [1, 1, 1]]))[source]¶
Returns a linear table, the number of output samples \(n\) is equal to
size**3 * 3
orsize[0] * size[1] * size[2] * 3
.- Parameters
size (int or array_like, optional) – Expected table size.
domain (array_like, optional) – Domain of the table.
- Returns
Linear table with
size**3 * 3
orsize[0] * size[1] * size[2] * 3
samples.- Return type
ndarray
Examples
>>> LUT3D.linear_table( ... 3, np.array([[-0.1, -0.2, -0.4], [1.5, 3.0, 6.0]])) array([[[[-0.1, -0.2, -0.4], [-0.1, -0.2, 2.8], [-0.1, -0.2, 6. ]], [[-0.1, 1.4, -0.4], [-0.1, 1.4, 2.8], [-0.1, 1.4, 6. ]], [[-0.1, 3. , -0.4], [-0.1, 3. , 2.8], [-0.1, 3. , 6. ]]], [[[ 0.7, -0.2, -0.4], [ 0.7, -0.2, 2.8], [ 0.7, -0.2, 6. ]], [[ 0.7, 1.4, -0.4], [ 0.7, 1.4, 2.8], [ 0.7, 1.4, 6. ]], [[ 0.7, 3. , -0.4], [ 0.7, 3. , 2.8], [ 0.7, 3. , 6. ]]], [[[ 1.5, -0.2, -0.4], [ 1.5, -0.2, 2.8], [ 1.5, -0.2, 6. ]], [[ 1.5, 1.4, -0.4], [ 1.5, 1.4, 2.8], [ 1.5, 1.4, 6. ]], [[ 1.5, 3. , -0.4], [ 1.5, 3. , 2.8], [ 1.5, 3. , 6. ]]]]) >>> LUT3D.linear_table( ... np.array([3, 3, 2]), ... np.array([[-0.1, -0.2, -0.4], [1.5, 3.0, 6.0]])) array([[[[-0.1, -0.2, -0.4], [-0.1, -0.2, 6. ]], [[-0.1, 1.4, -0.4], [-0.1, 1.4, 6. ]], [[-0.1, 3. , -0.4], [-0.1, 3. , 6. ]]], [[[ 0.7, -0.2, -0.4], [ 0.7, -0.2, 6. ]], [[ 0.7, 1.4, -0.4], [ 0.7, 1.4, 6. ]], [[ 0.7, 3. , -0.4], [ 0.7, 3. , 6. ]]], [[[ 1.5, -0.2, -0.4], [ 1.5, -0.2, 6. ]], [[ 1.5, 1.4, -0.4], [ 1.5, 1.4, 6. ]], [[ 1.5, 3. , -0.4], [ 1.5, 3. , 6. ]]]]) >>> domain = np.array([[-0.1, -0.2, -0.4], ... [0.7, 1.4, 6.0], ... [1.5, 3.0, np.nan]]) >>> LUT3D.linear_table(domain=domain) array([[[[-0.1, -0.2, -0.4], [-0.1, -0.2, 6. ]], [[-0.1, 1.4, -0.4], [-0.1, 1.4, 6. ]], [[-0.1, 3. , -0.4], [-0.1, 3. , 6. ]]], [[[ 0.7, -0.2, -0.4], [ 0.7, -0.2, 6. ]], [[ 0.7, 1.4, -0.4], [ 0.7, 1.4, 6. ]], [[ 0.7, 3. , -0.4], [ 0.7, 3. , 6. ]]], [[[ 1.5, -0.2, -0.4], [ 1.5, -0.2, 6. ]], [[ 1.5, 1.4, -0.4], [ 1.5, 1.4, 6. ]], [[ 1.5, 3. , -0.4], [ 1.5, 3. , 6. ]]]])
- apply(RGB, interpolator=<function table_interpolation_trilinear>, 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 object to use as interpolating function.
interpolator_kwargs (dict_like, optional) – Arguments to use when calling the interpolating function.
**kwargs (dict, optional) – Keywords arguments for deprecation management.
- Returns
Interpolated RGB colourspace array.
- Return type
ndarray
Examples
>>> LUT = LUT3D(LUT3D.linear_table() ** (1 / 2.2)) >>> RGB = np.array([0.18, 0.18, 0.18]) >>> LUT.apply(RGB) array([ 0.4583277..., 0.4583277..., 0.4583277...]) >>> from colour.algebra import spow >>> 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(LUT3D.linear_table(domain=domain), 1 / 2.2) >>> LUT = LUT3D(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
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 a downcast from a
LUT3D
class instance.
- Returns
Converted LUT class instance.
- Return type
Warning
Some conversions are destructive and raise a
ValueError
exception by default.- Raises
ValueError – If the conversion is destructive.
Examples
>>> LUT = LUT3D() >>> print(LUT.as_LUT(LUT1D, force_conversion=True)) LUT1D - Unity 33 - Converted 3D to 1D ------------------------------------- Dimensions : 1 Domain : [ 0. 1.] Size : (10,) >>> print(LUT.as_LUT(LUT3x1D, force_conversion=True)) LUT3x1D - Unity 33 - Converted 3D to 3x1D ----------------------------------------- Dimensions : 2 Domain : [[ 0. 0. 0.] [ 1. 1. 1.]] Size : (10, 3) >>> print(LUT.as_LUT(LUT3D)) LUT3D - Unity 33 - Converted 3D to 3D ------------------------------------- Dimensions : 3 Domain : [[ 0. 0. 0.] [ 1. 1. 1.]] Size : (33, 33, 33, 3)