def read_LUT_UnorderedSonySPI3D(path): title = path_to_title(path) domain_min, domain_max = np.array([0, 0, 0]), np.array([1, 1, 1]) size = 2 indexes = [] table = [] comments = [] with open(path) as spi3d_file: lines = filter(None, (line.strip() for line in spi3d_file.readlines())) for line in lines: if line.startswith('#'): comments.append(line[1:].strip()) continue tokens = line.split() if len(tokens) == 3: assert len(set(tokens)) == 1, ( 'Non-uniform "LUT" shape is unsupported!') size = DEFAULT_INT_DTYPE(tokens[0]) if len(tokens) == 6: indexes.append(as_int_array(tokens[:3])) table.append(as_float_array(tokens[3:])) indexes = as_int_array(indexes) sorting_indexes = np.lexsort((indexes[:, 2], indexes[:, 1], indexes[:, 0])) #print(sorting_indexes) assert np.array_equal( indexes[sorting_indexes], DEFAULT_INT_DTYPE(np.around( LUT3D.linear_table(size) * (size - 1))).reshape( (-1, 3))), 'Indexes do not match expected "LUT3D" indexes!' table = as_float_array(table)[sorting_indexes].reshape( [size, size, size, 3]) return LUT3D(table, title, np.vstack([domain_min, domain_max]), comments=comments)
def setUp(self): """Initialise the common tests attributes.""" self._LUT_1 = LUT1D(LUT1D.linear_table(16) + 0.125, "Nemo 1D") self._LUT_2 = LUT3D(LUT3D.linear_table(16)**(1 / 2.2), "Nemo 3D") self._LUT_3 = LUT3x1D(LUT3x1D.linear_table(16) * 0.750, "Nemo 3x1D") self._LUT_sequence = LUTSequence(self._LUT_1, self._LUT_2, self._LUT_3) samples = np.linspace(0, 1, 5) self._RGB = tstack([samples, samples, samples])
def read_unordered_LUT_SonySPI3D(path): """ Reads given unordered *.spi3d* *LUT* file. Parameters ---------- path : unicode *LUT* path. Returns ------- LUT3D or LUT3x1D :class:`LUT3D` or :class:`LUT3x1D` class instance. """ title = path_to_title(path) domain_min, domain_max = np.array([0, 0, 0]), np.array([1, 1, 1]) indexes = [] comments = [] table_unordered = [] table_ordered = [] with open(path) as spi3d_file: lines = filter(None, (line.strip() for line in spi3d_file.readlines())) for line in lines: if line.startswith('#'): comments.append(line[1:].strip()) continue tokens = line.split() if len(tokens) == 3: size = DEFAULT_INT_DTYPE(tokens[0]) if len(tokens) == 6: indexes.append(as_int_array(tokens[:3])) table_unordered.append(as_float_array(tokens[3:])) test_indexes = np.around(LUT3D.linear_table(size) * (size - 1)).reshape( (-1, 3)) for i in range(64): for j in range(64): if (np.array_equal(test_indexes[i], indexes[j])): table_ordered.append(table_unordered[j]) table_ordered = as_float_array(table_ordered).reshape( [size, size, size, 3]) return LUT3D(table_ordered, title, np.vstack([domain_min, domain_max]), comments=comments)
def read_LUT_SonySPI3D(path): """ Reads given *Sony* *.spi3d* *LUT* file. Parameters ---------- path : unicode *LUT* path. Returns ------- LUT3D or LUT3x1D :class:`LUT3D` or :class:`LUT3x1D` class instance. Examples -------- Reading a 3D *Sony* *.spi3d* *LUT*: >>> import os >>> path = os.path.join( ... os.path.dirname(__file__), 'tests', 'resources', 'sony_spi3d', ... 'ColourCorrect.spi3d') >>> print(read_LUT_SonySPI3D(path)) LUT3D - ColourCorrect --------------------- <BLANKLINE> Dimensions : 3 Domain : [[ 0. 0. 0.] [ 1. 1. 1.]] Size : (4, 4, 4, 3) Comment 01 : Adapted from a LUT generated by Foundry::LUT. """ title = path_to_title(path) domain_min, domain_max = np.array([0, 0, 0]), np.array([1, 1, 1]) size = 2 indexes = [] table = [] comments = [] with open(path) as spi3d_file: lines = spi3d_file.readlines() for line in lines: line = line.strip() if len(line) == 0: continue if line.startswith('#'): comments.append(line[1:].strip()) continue tokens = line.split() if len(tokens) == 3: assert len(set(tokens)) == 1, ( 'Non-uniform "LUT" shape is unsupported!') size = DEFAULT_INT_DTYPE(tokens[0]) if len(tokens) == 6: indexes.append(parse_array(tokens[:3])) table.append(parse_array(tokens[3:])) assert np.array_equal( indexes, DEFAULT_INT_DTYPE(LUT3D.linear_table(size) * (size - 1)).reshape( (-1, 3))), 'Indexes do not match expected "LUT3D" indexes!' table = as_float_array(table).reshape([size, size, size, 3]) return LUT3D(table, title, np.vstack([domain_min, domain_max]), comments=comments)
def test__repr__(self): """Test :class:`colour.io.luts.sequence.LUTSequence.__repr__` method.""" LUT_sequence = self._LUT_sequence.copy() LUT_sequence[1].table = LUT3D.linear_table(5) self.assertEqual( repr(LUT_sequence), textwrap.dedent(""" LUTSequence( LUT1D([ 0.125 , 0.19166667, 0.25833333, 0.325 , \ 0.39166667, 0.45833333, 0.525 , 0.59166667, 0.65833333, \ 0.725 , 0.79166667, 0.85833333, 0.925 , 0.99166667, \ 1.05833333, 1.125 ], name='Nemo 1D', domain=[ 0., 1.]), LUT3D([[[[ 0. , 0. , 0. ], [ 0. , 0. , 0.25], [ 0. , 0. , 0.5 ], [ 0. , 0. , 0.75], [ 0. , 0. , 1. ]], [[ 0. , 0.25, 0. ], [ 0. , 0.25, 0.25], [ 0. , 0.25, 0.5 ], [ 0. , 0.25, 0.75], [ 0. , 0.25, 1. ]], [[ 0. , 0.5 , 0. ], [ 0. , 0.5 , 0.25], [ 0. , 0.5 , 0.5 ], [ 0. , 0.5 , 0.75], [ 0. , 0.5 , 1. ]], [[ 0. , 0.75, 0. ], [ 0. , 0.75, 0.25], [ 0. , 0.75, 0.5 ], [ 0. , 0.75, 0.75], [ 0. , 0.75, 1. ]], [[ 0. , 1. , 0. ], [ 0. , 1. , 0.25], [ 0. , 1. , 0.5 ], [ 0. , 1. , 0.75], [ 0. , 1. , 1. ]]], [[[ 0.25, 0. , 0. ], [ 0.25, 0. , 0.25], [ 0.25, 0. , 0.5 ], [ 0.25, 0. , 0.75], [ 0.25, 0. , 1. ]], [[ 0.25, 0.25, 0. ], [ 0.25, 0.25, 0.25], [ 0.25, 0.25, 0.5 ], [ 0.25, 0.25, 0.75], [ 0.25, 0.25, 1. ]], [[ 0.25, 0.5 , 0. ], [ 0.25, 0.5 , 0.25], [ 0.25, 0.5 , 0.5 ], [ 0.25, 0.5 , 0.75], [ 0.25, 0.5 , 1. ]], [[ 0.25, 0.75, 0. ], [ 0.25, 0.75, 0.25], [ 0.25, 0.75, 0.5 ], [ 0.25, 0.75, 0.75], [ 0.25, 0.75, 1. ]], [[ 0.25, 1. , 0. ], [ 0.25, 1. , 0.25], [ 0.25, 1. , 0.5 ], [ 0.25, 1. , 0.75], [ 0.25, 1. , 1. ]]], [[[ 0.5 , 0. , 0. ], [ 0.5 , 0. , 0.25], [ 0.5 , 0. , 0.5 ], [ 0.5 , 0. , 0.75], [ 0.5 , 0. , 1. ]], [[ 0.5 , 0.25, 0. ], [ 0.5 , 0.25, 0.25], [ 0.5 , 0.25, 0.5 ], [ 0.5 , 0.25, 0.75], [ 0.5 , 0.25, 1. ]], [[ 0.5 , 0.5 , 0. ], [ 0.5 , 0.5 , 0.25], [ 0.5 , 0.5 , 0.5 ], [ 0.5 , 0.5 , 0.75], [ 0.5 , 0.5 , 1. ]], [[ 0.5 , 0.75, 0. ], [ 0.5 , 0.75, 0.25], [ 0.5 , 0.75, 0.5 ], [ 0.5 , 0.75, 0.75], [ 0.5 , 0.75, 1. ]], [[ 0.5 , 1. , 0. ], [ 0.5 , 1. , 0.25], [ 0.5 , 1. , 0.5 ], [ 0.5 , 1. , 0.75], [ 0.5 , 1. , 1. ]]], [[[ 0.75, 0. , 0. ], [ 0.75, 0. , 0.25], [ 0.75, 0. , 0.5 ], [ 0.75, 0. , 0.75], [ 0.75, 0. , 1. ]], [[ 0.75, 0.25, 0. ], [ 0.75, 0.25, 0.25], [ 0.75, 0.25, 0.5 ], [ 0.75, 0.25, 0.75], [ 0.75, 0.25, 1. ]], [[ 0.75, 0.5 , 0. ], [ 0.75, 0.5 , 0.25], [ 0.75, 0.5 , 0.5 ], [ 0.75, 0.5 , 0.75], [ 0.75, 0.5 , 1. ]], [[ 0.75, 0.75, 0. ], [ 0.75, 0.75, 0.25], [ 0.75, 0.75, 0.5 ], [ 0.75, 0.75, 0.75], [ 0.75, 0.75, 1. ]], [[ 0.75, 1. , 0. ], [ 0.75, 1. , 0.25], [ 0.75, 1. , 0.5 ], [ 0.75, 1. , 0.75], [ 0.75, 1. , 1. ]]], [[[ 1. , 0. , 0. ], [ 1. , 0. , 0.25], [ 1. , 0. , 0.5 ], [ 1. , 0. , 0.75], [ 1. , 0. , 1. ]], [[ 1. , 0.25, 0. ], [ 1. , 0.25, 0.25], [ 1. , 0.25, 0.5 ], [ 1. , 0.25, 0.75], [ 1. , 0.25, 1. ]], [[ 1. , 0.5 , 0. ], [ 1. , 0.5 , 0.25], [ 1. , 0.5 , 0.5 ], [ 1. , 0.5 , 0.75], [ 1. , 0.5 , 1. ]], [[ 1. , 0.75, 0. ], [ 1. , 0.75, 0.25], [ 1. , 0.75, 0.5 ], [ 1. , 0.75, 0.75], [ 1. , 0.75, 1. ]], [[ 1. , 1. , 0. ], [ 1. , 1. , 0.25], [ 1. , 1. , 0.5 ], [ 1. , 1. , 0.75], [ 1. , 1. , 1. ]]]], name='Nemo 3D', domain=[[ 0., 0., 0.], [ 1., 1., 1.]]), LUT3x1D([[ 0. , 0. , 0. ], [ 0.05, 0.05, 0.05], [ 0.1 , 0.1 , 0.1 ], [ 0.15, 0.15, 0.15], [ 0.2 , 0.2 , 0.2 ], [ 0.25, 0.25, 0.25], [ 0.3 , 0.3 , 0.3 ], [ 0.35, 0.35, 0.35], [ 0.4 , 0.4 , 0.4 ], [ 0.45, 0.45, 0.45], [ 0.5 , 0.5 , 0.5 ], [ 0.55, 0.55, 0.55], [ 0.6 , 0.6 , 0.6 ], [ 0.65, 0.65, 0.65], [ 0.7 , 0.7 , 0.7 ], [ 0.75, 0.75, 0.75]], name='Nemo 3x1D', domain=[[ 0., 0., 0.], [ 1., 1., 1.]]) )"""[1:]), )
def read_LUT_SonySPI3D(path): """ Reads given *Sony* *.spi3d* *LUT* file. Parameters ---------- path : unicode *LUT* path. Returns ------- LUT3D or LUT3x1D :class:`LUT3D` or :class:`LUT3x1D` class instance. Examples -------- Reading a 3D *Sony* *.spi3d* *LUT*: >>> import os >>> path = os.path.join( ... os.path.dirname(__file__), 'tests', 'resources', 'sony_spi3d', ... 'ColourCorrect.spi3d') >>> print(read_LUT_SonySPI3D(path)) LUT3D - ColourCorrect --------------------- <BLANKLINE> Dimensions : 3 Domain : [[ 0. 0. 0.] [ 1. 1. 1.]] Size : (4, 4, 4, 3) Comment 01 : Adapted from a LUT generated by Foundry::LUT. """ title = path_to_title(path) domain_min, domain_max = np.array([0, 0, 0]), np.array([1, 1, 1]) size = 2 indexes = [] table = [] comments = [] with open(path) as spi3d_file: lines = spi3d_file.readlines() for line in lines: line = line.strip() if len(line) == 0: continue if line.startswith('#'): comments.append(line[1:].strip()) continue tokens = line.split() if len(tokens) == 3: assert len(set(tokens)) == 1, ( 'Non-uniform "LUT" shape is unsupported!') size = DEFAULT_INT_DTYPE(tokens[0]) if len(tokens) == 6: indexes.append(parse_array(tokens[:3])) table.append(parse_array(tokens[3:])) assert np.array_equal( indexes, DEFAULT_INT_DTYPE(LUT3D.linear_table(size) * (size - 1)).reshape( (-1, 3))), 'Indexes do not match expected "LUT3D" indexes!' table = as_float_array(table).reshape([size, size, size, 3]) return LUT3D( table, title, np.vstack([domain_min, domain_max]), comments=comments)