27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
import os
|
|
import numpy as np
|
|
from colour.io.luts.iridas_cube import read_LUT_IridasCube, LUT3D, LUT3x1D
|
|
|
|
def read_lut(lut_path, clip=False):
|
|
"""
|
|
Reads a LUT from the specified path, returning instance of LUT3D or LUT3x1D
|
|
|
|
<lut_path>: the path to the file from which to read the LUT (
|
|
<clip>: flag indicating whether to apply clipping of LUT values, limiting all values to the domain's lower and
|
|
upper bounds
|
|
"""
|
|
lut: Union[LUT3x1D, LUT3D] = read_LUT_IridasCube(lut_path)
|
|
lut.name = os.path.splitext(os.path.basename(lut_path))[0] # use base filename instead of internal LUT name
|
|
|
|
if clip:
|
|
if lut.domain[0].max() == lut.domain[0].min() and lut.domain[1].max() == lut.domain[1].min():
|
|
lut.table = np.clip(lut.table, lut.domain[0, 0], lut.domain[1, 0])
|
|
else:
|
|
if len(lut.table.shape) == 2: # 3x1D
|
|
for dim in range(3):
|
|
lut.table[:, dim] = np.clip(lut.table[:, dim], lut.domain[0, dim], lut.domain[1, dim])
|
|
else: # 3D
|
|
for dim in range(3):
|
|
lut.table[:, :, :, dim] = np.clip(lut.table[:, :, :, dim], lut.domain[0, dim], lut.domain[1, dim])
|
|
|
|
return lut |