def calculate_LUT(self, LUT_size=1024): self._LUT = colour.LUT1D( table=self.evaluate(np.linspace(0.0, self._radiometric_maximum, LUT_size)), name="Generic Lottes 2016 with Fixes", domain=[0.0, self._radiometric_maximum + 0.005], ) self._LUT_size = LUT_size self._linear = np.linspace(0.0, self._radiometric_maximum, self._LUT_size)
def apply(self, RGB, inverse=False, interpolator=LinearInterpolator, interpolator_kwargs=None, **kwargs): """ Applies the *LUT* to given *RGB* colourspace array using given method. Parameters ---------- RGB : array_like *RGB* colourspace array to apply the *LUT* onto. inverse : boolean, optional Checks if the LUT has to be applied in forward or backward direction. 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 ------- ndarray Interpolated *RGB* colourspace array. """ interpolator_kwargs = handle_arguments_deprecation({ 'ArgumentRenamed': [['interpolator_args', 'interpolator_kwargs']], }, **kwargs).get('interpolator_kwargs', interpolator_kwargs) if interpolator_kwargs is None: interpolator_kwargs = {} if inverse: SIZE = len(self._table) LUT_inverse = colour.LUT1D(size=SIZE) LUT_inverse.table = colour.Extrapolator( colour.LinearInterpolator(self._table, LUT_inverse.table))(LUT_inverse.table) RGB_i = LUT_inverse.apply(RGB) return RGB_i else: if self.is_domain_explicit(): samples = self.domain else: domain_min, domain_max = self.domain samples = np.linspace(domain_min, domain_max, self._table.size) RGB_interpolator = interpolator(samples, self._table, **interpolator_kwargs) return RGB_interpolator(RGB)
def calculate_LUT(self, LUT_size=1024): self._LUT = colour.LUT1D( table=self.evaluate( np.linspace(0.0, self._radiometric_maximum, LUT_size)), name="Siragusano Smith 2021", domain=[0.0, self._radiometric_maximum + 0.005], ) self._LUT_size = LUT_size self._linear = np.linspace(0.0, self._radiometric_maximum, self._LUT_size)
import numpy as np import colour def lin_to_log2_32f(lin, middleGrey, minExposure, maxExposure): if (lin <= 0.0): return 0.0 lg2 = np.log2(lin / middleGrey) logNorm = (lg2 - minExposure) / (maxExposure - minExposure) if (logNorm < 0.0): logNorm = 0 return logNorm domain = [0.18 * 2**-6.5, 0.18 * 2**6.5] shaper = colour.LUT1D(size=4096, domain=domain) shaper.table = 0.18 * 2**(np.linspace(-6.5, 6.5, 4096)) # The table values of shaper are currently linear and in the range of 0.002 to 16.297(approximately) print(shaper.table) b = [] for i in shaper.table: b.append(lin_to_log2_32f(i, 0.18, 3, 6.5)) shaper.table = b print('\n') # The table values of shaper are now converted to values in the range of 0 to 1 which symbolizes logarithmic endoing print(shaper.table)
def make_transforms(transform_path, config): sRGB_domain = numpy.array([0.0, 1.0]) sRGB_tf_to_linear_LUT = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_decoding( colour.LUT1D.linear_table(1024, sRGB_domain)), name="sRGB to Linear", domain=sRGB_domain, comments=["sRGB CCTF to Display Linear"]) sRGB_linear_to_tf_LUT = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_encoding( colour.LUT1D.linear_table(8192, sRGB_domain)), name="Linear to sRGB", domain=sRGB_domain, comments=["sRGB Display Linear to CCTF"]) path = os.path.join(transform_path, "sRGB_CCTF_to_Linear.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_tf_to_linear_LUT, path=path, decimals=10) path = os.path.join(transform_path, "sRGB_Linear_to_CCTF.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_linear_to_tf_LUT, path=path, decimals=10) # Off-domain 1D variant sRGB_domain_variant = numpy.array([-0.125, 4.875]) sRGB_tf_to_linear_LUT_variant = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_decoding( colour.LUT1D.linear_table(1024, sRGB_domain_variant)), name="sRGB to Linear Variant", domain=sRGB_domain_variant, comments=["sRGB CCTF to Display Linear"]) sRGB_linear_to_tf_LUT_variant = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_encoding( colour.LUT1D.linear_table(8192, sRGB_domain_variant)), name="Linear to sRGB Variant", domain=sRGB_domain_variant, comments=["sRGB Display Linear to CCTF"]) path = os.path.join(transform_path, "sRGB_CCTF_to_Linear_variant.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_tf_to_linear_LUT_variant, path=path, decimals=10) path = os.path.join(transform_path, "sRGB_Linear_to_CCTF_variant.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_linear_to_tf_LUT_variant, path=path, decimals=10) # Define the sRGB specification colourspace = PyOpenColorIO.ColorSpace(family="Colourspace", name="sRGB Colourspace") colourspace.setDescription("sRGB IEC 61966-2-1 Colourspace") colourspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colourspace.setAllocationVars([0.0, 1.0]) colourspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM) transform_to = PyOpenColorIO.FileTransform( "sRGB_CCTF_to_Linear.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) transform_from = PyOpenColorIO.FileTransform( "sRGB_Linear_to_CCTF.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) colourspace.setTransform( transform_to, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) colourspace.setTransform( transform_from, PyOpenColorIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(colourspace) # Define the sRGB specification for the variation colourspace = PyOpenColorIO.ColorSpace(family="Colourspace", name="sRGB Colourspace Variant") colourspace.setDescription("sRGB IEC 61966-2-1 Colourspace variant") colourspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colourspace.setAllocationVars([-0.125, 1.125]) colourspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM) transform_to = PyOpenColorIO.FileTransform( "sRGB_CCTF_to_Linear_variant.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) transform_from = PyOpenColorIO.FileTransform( "sRGB_Linear_to_CCTF_variant.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) colourspace.setTransform( transform_to, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) colourspace.setTransform( transform_from, PyOpenColorIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(colourspace) # Define the commodity sRGB transform colourspace = PyOpenColorIO.ColorSpace(family="Colourspace", name="BT.709 2.2 CCTF Colourspace") colourspace.setDescription("Commodity Display BT.709 2.2 CCTF Colourspace") colourspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colourspace.setAllocationVars([0.0, 1.0]) colourspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM) transform_to = PyOpenColorIO.ExponentTransform([2.2, 2.2, 2.2, 1.0]) transform_from = PyOpenColorIO.ExponentTransform([2.2, 2.2, 2.2, 1.0]) transform_from.setDirection(PyOpenColorIO.Constants.TRANSFORM_DIR_INVERSE) colourspace.setTransform( transform_to, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) colourspace.setTransform( transform_from, PyOpenColorIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(colourspace)
x_input = numpy.linspace(0.0, 1.0, 4096) limits_contrast = [3.0, 3.25] general_contrast = 2.0 y_LUT = AgX.equation_full_curve( x_input, AgX_x_pivot, AgX_y_pivot, general_contrast, limits_contrast ) aesthetic_LUT_name = "AgX Default Contrast" aesthetic_LUT_safe = aesthetic_LUT_name.replace(" ", "_") aesthetic_LUT = colour.LUT1D( table=y_LUT, name="AgX Default Contrast" ) try: output_directory = pathlib.Path(output_config_directory) LUTs_directory = output_directory / output_LUTs_directory LUT_filename = pathlib.Path( LUTs_directory / "{}.spi1d".format(aesthetic_LUT_safe) ) LUTs_directory.mkdir(parents=True, exist_ok=True) colour.io.luts.write_LUT(aesthetic_LUT, LUT_filename, method="Sony SPI1D") except Exception as ex: raise ex ####
def make_transforms(transform_path, config): # The canonized sRGB transform # Due to the nature of the GPU issues in OpenColorIO v1.1.1, this # 1D LUT oversamples the sRGB transfer function range to have # correct results via the GPU. # # It also adds a faster inverse transform instead of a lookup for # output processing speed. It must be larger as a result, due to # quantisation issues in the linear domain. sRGB_domain = numpy.array([-0.125, 3.0]) sRGB_tf_to_linear_LUT = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_decoding( colour.LUT1D.linear_table(1024, sRGB_domain)), name="sRGB to Linear", domain=sRGB_domain, comments=["sRGB CCTF to Display Linear"]) sRGB_linear_to_tf_LUT_variant = colour.LUT1D( table=models.sRGB_COLOURSPACE.cctf_encoding( colour.LUT1D.linear_table(8192, sRGB_domain)), name="Linear to sRGB", domain=sRGB_domain, comments=["sRGB Display Linear to CCTF"]) path = os.path.join(transform_path, "sRGB_CCTF_to_Linear.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_tf_to_linear_LUT, path=path, decimals=10) path = os.path.join(transform_path, "sRGB_Linear_to_CCTF.spi1d") create_directory(path) io.write_LUT(LUT=sRGB_linear_to_tf_LUT_variant, path=path, decimals=10) # Define the sRGB specification colourspace = PyOpenColorIO.ColorSpace(family="Colourspace", name="sRGB Colourspace") colourspace.setDescription("sRGB IEC 61966-2-1 Colourspace") colourspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colourspace.setAllocationVars([0.0, 1.0]) colourspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM) transform_to = PyOpenColorIO.FileTransform( "sRGB_CCTF_to_Linear.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) transform_from = PyOpenColorIO.FileTransform( "sRGB_Linear_to_CCTF.spi1d", interpolation=PyOpenColorIO.Constants.INTERP_NEAREST) colourspace.setTransform( transform_to, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) colourspace.setTransform( transform_from, PyOpenColorIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(colourspace) # Define the commodity sRGB transform colourspace = PyOpenColorIO.ColorSpace(family="Colourspace", name="BT.709 2.2 CCTF Colourspace") colourspace.setDescription("Commodity Display BT.709 2.2 CCTF Colourspace") colourspace.setBitDepth(PyOpenColorIO.Constants.BIT_DEPTH_F32) colourspace.setAllocationVars([0.0, 1.0]) colourspace.setAllocation(PyOpenColorIO.Constants.ALLOCATION_UNIFORM) transform_to = PyOpenColorIO.ExponentTransform([2.2, 2.2, 2.2, 1.0]) transform_from = PyOpenColorIO.ExponentTransform([2.2, 2.2, 2.2, 1.0]) transform_from.setDirection(PyOpenColorIO.Constants.TRANSFORM_DIR_INVERSE) colourspace.setTransform( transform_to, PyOpenColorIO.Constants.COLORSPACE_DIR_TO_REFERENCE) colourspace.setTransform( transform_from, PyOpenColorIO.Constants.COLORSPACE_DIR_FROM_REFERENCE) config.addColorSpace(colourspace)