def test_RGB_to_RGB(self): """ Tests :func:`colour.models.rgb.RGB_to_RGB` definition. """ aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1') sRGB_colourspace = RGB_COLOURSPACES.get('sRGB') np.testing.assert_almost_equal( RGB_to_RGB(np.array([0.35521588, 0.41000000, 0.24177934]), aces_2065_1_colourspace, sRGB_colourspace), np.array([0.33658567, 0.44096335, 0.21509975]), decimal=7) np.testing.assert_almost_equal( RGB_to_RGB(np.array([0.33658567, 0.44096335, 0.21509975]), sRGB_colourspace, aces_2065_1_colourspace), np.array([0.35521588, 0.41000000, 0.24177934]), decimal=7) np.testing.assert_almost_equal( RGB_to_RGB(np.array([0.35521588, 0.41000000, 0.24177934]), aces_2065_1_colourspace, sRGB_colourspace, 'Bradford'), np.array([0.33704409, 0.44133521, 0.21429761]), decimal=7)
def test_RGB_to_RGB(self): """ Tests :func:`colour.models.rgb.rgb_colourspace.RGB_to_RGB` definition. """ aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1') sRGB_colourspace = RGB_COLOURSPACES.get('sRGB') np.testing.assert_almost_equal( RGB_to_RGB(np.array([0.35521588, 0.41000000, 0.24177934]), aces_2065_1_colourspace, sRGB_colourspace), np.array([0.33653829, 0.44097338, 0.21512063]), decimal=7) np.testing.assert_almost_equal( RGB_to_RGB(np.array([0.33653829, 0.44097338, 0.21512063]), sRGB_colourspace, aces_2065_1_colourspace), np.array([0.35521588, 0.41000000, 0.24177934]), decimal=7) np.testing.assert_almost_equal( RGB_to_RGB(np.array([0.35521588, 0.41000000, 0.24177934]), aces_2065_1_colourspace, sRGB_colourspace, 'Bradford'), np.array([0.33699675, 0.44134608, 0.21431681]), decimal=7)
def get_RGB_colourspace(colourspace): """ Returns the *RGB* colourspace with given name. Parameters ---------- colourspace : Unicode *RGB* Colourspace name. Returns ------- RGB_Colourspace *RGB* Colourspace. Raises ------ KeyError If the given colourspace is not found in the factory colourspaces. """ colourspace, name = RGB_COLOURSPACES.get(colourspace), colourspace if colourspace is None: raise KeyError( ('"{0}" colourspace not found in factory colourspaces: ' '"{1}".').format(name, sorted(RGB_COLOURSPACES.keys()))) return colourspace
def get_RGB_colourspace(colourspace): """ Returns the *RGB* colourspace with given name. Parameters ---------- colourspace : unicode *RGB* colourspace name. Returns ------- RGB_Colourspace *RGB* colourspace. Raises ------ KeyError If the given *RGB* colourspace is not found in the factory *RGB* colourspaces. """ colourspace, name = RGB_COLOURSPACES.get(colourspace), colourspace if colourspace is None: raise KeyError( ('"{0}" colourspace not found in factory RGB colourspaces: ' '"{1}".').format(name, ', '.join(sorted(RGB_COLOURSPACES.keys())))) return colourspace
def test_opto_electronic_conversion_functions(self): """ Tests opto-electronic conversion functions from the :attr:`colour.models.RGB_COLOURSPACES` attribute colourspace models. """ aces_proxy_colourspaces = ('ACESproxy', 'ACEScg') samples = np.linspace(0, 1, 1000) for colourspace in RGB_COLOURSPACES.values(): if colourspace.name in aces_proxy_colourspaces: continue samples_oecf = [colourspace.OECF(sample) for sample in samples] samples_inverse_oecf = [ colourspace.EOCF(sample) for sample in samples_oecf ] np.testing.assert_almost_equal(samples, samples_inverse_oecf, decimal=7) for colourspace in aces_proxy_colourspaces: colourspace = RGB_COLOURSPACES.get(colourspace) samples_oecf = [colourspace.OECF(sample) for sample in samples] samples_inverse_oecf = [ colourspace.EOCF(sample) for sample in samples_oecf ] np.testing.assert_allclose(samples, samples_inverse_oecf, rtol=0.01, atol=0.01)
def test_opto_electronic_conversion_functions(self): """ Tests opto-electronic conversion functions from the :attr:`colour.models.RGB_COLOURSPACES` attribute colourspace models. """ aces_proxy_colourspaces = ('ACESproxy', 'ACEScg') samples = np.linspace(0, 1, 1000) for colourspace in RGB_COLOURSPACES.values(): if colourspace.name in aces_proxy_colourspaces: continue samples_oecf = [colourspace.transfer_function(sample) for sample in samples] samples_inverse_oecf = [ colourspace.inverse_transfer_function(sample) for sample in samples_oecf] np.testing.assert_almost_equal(samples, samples_inverse_oecf, decimal=7) for colourspace in aces_proxy_colourspaces: colourspace = RGB_COLOURSPACES.get(colourspace) samples_oecf = [colourspace.transfer_function(sample) for sample in samples] samples_inverse_oecf = [ colourspace.inverse_transfer_function(sample) for sample in samples_oecf] np.testing.assert_allclose(samples, samples_inverse_oecf, rtol=0.01, atol=0.01)
def test_n_dimensional_RGB_to_RGB(self): """ Tests :func:`colour.models.rgb.RGB_to_RGB` definition n-dimensions support. """ aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1') sRGB_colourspace = RGB_COLOURSPACES.get('sRGB') RGB_i = np.array([0.35521588, 0.41000000, 0.24177934]) RGB_o = np.array([0.33658567, 0.44096335, 0.21509975]) np.testing.assert_almost_equal( RGB_to_RGB(RGB_i, aces_2065_1_colourspace, sRGB_colourspace), RGB_o, decimal=7) RGB_i = np.tile(RGB_i, (6, 1)) RGB_o = np.tile(RGB_o, (6, 1)) np.testing.assert_almost_equal( RGB_to_RGB(RGB_i, aces_2065_1_colourspace, sRGB_colourspace), RGB_o, decimal=7) RGB_i = np.reshape(RGB_i, (2, 3, 3)) RGB_o = np.reshape(RGB_o, (2, 3, 3)) np.testing.assert_almost_equal( RGB_to_RGB(RGB_i, aces_2065_1_colourspace, sRGB_colourspace), RGB_o, decimal=7)
def test_n_dimensional_RGB_to_RGB(self): """ Tests :func:`colour.models.rgb.RGB_to_RGB` definition n-dimensions support. """ aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1') sRGB_colourspace = RGB_COLOURSPACES.get('sRGB') RGB_i = np.array([0.35521588, 0.41000000, 0.24177934]) RGB_o = np.array([0.33658567, 0.44096335, 0.21509975]) np.testing.assert_almost_equal(RGB_to_RGB(RGB_i, aces_2065_1_colourspace, sRGB_colourspace), RGB_o, decimal=7) RGB_i = np.tile(RGB_i, (6, 1)) RGB_o = np.tile(RGB_o, (6, 1)) np.testing.assert_almost_equal(RGB_to_RGB(RGB_i, aces_2065_1_colourspace, sRGB_colourspace), RGB_o, decimal=7) RGB_i = np.reshape(RGB_i, (2, 3, 3)) RGB_o = np.reshape(RGB_o, (2, 3, 3)) np.testing.assert_almost_equal(RGB_to_RGB(RGB_i, aces_2065_1_colourspace, sRGB_colourspace), RGB_o, decimal=7)
def test_nan_RGB_to_RGB(self): """ Tests :func:`colour.models.rgb.RGB_to_RGB` definition nan support. """ aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1') sRGB_colourspace = RGB_COLOURSPACES.get('sRGB') cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] cases = set(permutations(cases * 3, r=3)) for case in cases: RGB = np.array(case) RGB_to_RGB(RGB, aces_2065_1_colourspace, sRGB_colourspace)
def test_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models. """ ignored_colourspaces = ('ACESproxy', ) decimals = {'DJI D-Gamut': 1, 'F-Gamut': 4} samples = np.hstack([ np.linspace(0, 1, as_int(1e5)), np.linspace(0, 65504, 65504 * 10) ]) for colourspace in RGB_COLOURSPACES.values(): if colourspace.name in ignored_colourspaces: continue cctf_encoding_s = colourspace.cctf_encoding(samples) cctf_decoding_s = colourspace.cctf_decoding(cctf_encoding_s) np.testing.assert_almost_equal(samples, cctf_decoding_s, decimal=decimals.get( colourspace.name, 7))
def test_n_dimensional_opto_electronic_conversion_functions(self): """ Tests opto-electronic conversion functions from the :attr:`colour.models.RGB_COLOURSPACES` attribute colourspace models n-dimensional arrays support. """ for colourspace in RGB_COLOURSPACES.values(): value_oecf = 0.5 value_inverse_oecf = colourspace.EOCF(colourspace.OECF(value_oecf)) np.testing.assert_almost_equal(value_oecf, value_inverse_oecf, decimal=7) value_oecf = np.tile(value_oecf, 6) value_inverse_oecf = np.tile(value_inverse_oecf, 6) np.testing.assert_almost_equal(value_oecf, value_inverse_oecf, decimal=7) value_oecf = np.reshape(value_oecf, (3, 2)) value_inverse_oecf = np.reshape(value_inverse_oecf, (3, 2)) np.testing.assert_almost_equal(value_oecf, value_inverse_oecf, decimal=7) value_oecf = np.reshape(value_oecf, (3, 2, 1)) value_inverse_oecf = np.reshape(value_inverse_oecf, (3, 2, 1)) np.testing.assert_almost_equal(value_oecf, value_inverse_oecf, decimal=7)
def test_n_dimensional_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models n-dimensional arrays support. """ for colourspace in RGB_COLOURSPACES.values(): value_encoding_cctf = 0.5 value_decoding_cctf = colourspace.decoding_cctf( colourspace.encoding_cctf(value_encoding_cctf)) np.testing.assert_almost_equal( value_encoding_cctf, value_decoding_cctf, decimal=7) value_encoding_cctf = np.tile(value_encoding_cctf, 6) value_decoding_cctf = np.tile(value_decoding_cctf, 6) np.testing.assert_almost_equal( value_encoding_cctf, value_decoding_cctf, decimal=7) value_encoding_cctf = np.reshape(value_encoding_cctf, (3, 2)) value_decoding_cctf = np.reshape(value_decoding_cctf, (3, 2)) np.testing.assert_almost_equal( value_encoding_cctf, value_decoding_cctf, decimal=7) value_encoding_cctf = np.reshape(value_encoding_cctf, (3, 2, 1)) value_decoding_cctf = np.reshape(value_decoding_cctf, (3, 2, 1)) np.testing.assert_almost_equal( value_encoding_cctf, value_decoding_cctf, decimal=7)
def test_n_dimensional_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models n-dimensional arrays support. """ for colourspace in RGB_COLOURSPACES.values(): if colourspace.name in ('DJI D-Gamut', ): decimal = 6 else: decimal = 7 value_encoding_cctf = 0.5 value_decoding_cctf = colourspace.decoding_cctf( colourspace.encoding_cctf(value_encoding_cctf)) np.testing.assert_almost_equal( value_encoding_cctf, value_decoding_cctf, decimal=decimal) value_encoding_cctf = np.tile(value_encoding_cctf, 6) value_decoding_cctf = np.tile(value_decoding_cctf, 6) np.testing.assert_almost_equal( value_encoding_cctf, value_decoding_cctf, decimal=decimal) value_encoding_cctf = np.reshape(value_encoding_cctf, (3, 2)) value_decoding_cctf = np.reshape(value_decoding_cctf, (3, 2)) np.testing.assert_almost_equal( value_encoding_cctf, value_decoding_cctf, decimal=decimal) value_encoding_cctf = np.reshape(value_encoding_cctf, (3, 2, 1)) value_decoding_cctf = np.reshape(value_decoding_cctf, (3, 2, 1)) np.testing.assert_almost_equal( value_encoding_cctf, value_decoding_cctf, decimal=decimal)
def test_transformation_matrices(self): """ Tests the transformations matrices from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models. """ XYZ_r = np.array([0.5, 0.5, 0.5]).reshape((3, 1)) for colourspace in RGB_COLOURSPACES.values(): if colourspace.name in ( 'ProPhoto RGB', 'ERIMM RGB', 'RIMM RGB', 'ROMM RGB'): tolerance = 1e-3 elif colourspace.name in ('sRGB',): tolerance = 1e-4 elif colourspace.name in ('Adobe RGB (1998)',): tolerance = 1e-5 elif colourspace.name in ('ALEXA Wide Gamut RGB', 'V-Gamut'): tolerance = 1e-6 else: tolerance = 1e-7 M = normalised_primary_matrix(colourspace.primaries, colourspace.whitepoint) np.testing.assert_allclose(colourspace.RGB_to_XYZ_matrix, M, rtol=tolerance, atol=tolerance, verbose=False) RGB = np.dot(colourspace.XYZ_to_RGB_matrix, XYZ_r) XYZ = np.dot(colourspace.RGB_to_XYZ_matrix, RGB) np.testing.assert_almost_equal(XYZ_r, XYZ, decimal=7)
def XYZ_to_sRGB(XYZ, illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint, chromatic_adaptation_transform='CAT02', apply_OECF=True): """ Converts from *CIE XYZ* tristimulus values to *sRGB* colourspace. Parameters ---------- XYZ : array_like *CIE XYZ* tristimulus values. illuminant : array_like, optional Source illuminant chromaticity coordinates. chromatic_adaptation_transform : unicode, optional **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild, 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco', 'Bianco PC'}**, *Chromatic adaptation* transform. apply_OECF : bool, optional Apply *sRGB* *opto-electronic conversion function*. Returns ------- ndarray *sRGB* colour array. Notes ----- - Input *CIE XYZ* tristimulus values are in domain [0, 1]. Examples -------- >>> import numpy as np >>> XYZ = np.array([0.07049534, 0.10080000, 0.09558313]) >>> XYZ_to_sRGB(XYZ) # doctest: +ELLIPSIS array([ 0.1750135..., 0.3881879..., 0.3216195...]) """ sRGB = RGB_COLOURSPACES.get('sRGB') return XYZ_to_RGB(XYZ, illuminant, sRGB.whitepoint, sRGB.XYZ_to_RGB_matrix, chromatic_adaptation_transform, sRGB.OECF if apply_OECF else None)
def sRGB_to_XYZ(RGB, illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint, chromatic_adaptation_method='CAT02', inverse_transfer_function=True): """ Converts from *sRGB* colourspace to *CIE XYZ* tristimulus values. Parameters ---------- RGB : array_like *sRGB* colourspace array. illuminant : array_like, optional Source illuminant chromaticity coordinates. chromatic_adaptation_method : unicode, optional {'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild, 'CMCCAT97', 'CMCCAT2000', 'Bianco', 'Bianco PC'}, *Chromatic adaptation* method. inverse_transfer_function : bool, optional Apply *sRGB* *inverse transfer function*. Returns ------- ndarray *CIE XYZ* tristimulus values. Notes ----- - Input *RGB* colourspace array is in domain [0, 1]. Examples -------- >>> import numpy as np >>> RGB = np.array([0.17501358, 0.38818795, 0.32161955]) >>> sRGB_to_XYZ(RGB) # doctest: +ELLIPSIS array([ 0.0704953..., 0.1008 , 0.0955831...]) """ sRGB = RGB_COLOURSPACES.get('sRGB') return RGB_to_XYZ(RGB, sRGB.whitepoint, illuminant, sRGB.RGB_to_XYZ_matrix, chromatic_adaptation_method, (sRGB.inverse_transfer_function if inverse_transfer_function else None))
def XYZ_to_sRGB(XYZ, illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint, chromatic_adaptation_method='CAT02', transfer_function=True): """ Converts from *CIE XYZ* colourspace to *sRGB* colourspace. Parameters ---------- XYZ : array_like, (3,) *CIE XYZ* colourspace matrix. illuminant : array_like, optional Source illuminant chromaticity coordinates. chromatic_adaptation_method : unicode, optional ('XYZ Scaling', 'Bradford', 'Von Kries', 'Fairchild', 'CAT02') *Chromatic adaptation* method. transfer_function : bool, optional Apply *sRGB* *transfer function*. Returns ------- ndarray, (3,) *sRGB* colour matrix. Notes ----- - Input *CIE XYZ* colourspace matrix is in domain [0, 1]. Examples -------- >>> XYZ = np.array([0.1180583421, 0.1034, 0.0515089229]) >>> XYZ_to_sRGB(XYZ) # doctest: +ELLIPSIS array([ 0.4822488..., 0.3165197..., 0.2207051...]) """ sRGB = RGB_COLOURSPACES.get('sRGB') return XYZ_to_RGB(XYZ, illuminant, sRGB.whitepoint, sRGB.to_RGB, chromatic_adaptation_method, sRGB.transfer_function if transfer_function else None)
def sRGB_to_XYZ(RGB, illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint, chromatic_adaptation_method='CAT02', apply_EOCF=True): """ Converts from *sRGB* colourspace to *CIE XYZ* tristimulus values. Parameters ---------- RGB : array_like *sRGB* colourspace array. illuminant : array_like, optional Source illuminant chromaticity coordinates. chromatic_adaptation_method : unicode, optional **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild, 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco', 'Bianco PC'}**, *Chromatic adaptation* method. apply_EOCF : bool, optional Apply *sRGB* *electro-optical conversion function*. Returns ------- ndarray *CIE XYZ* tristimulus values. Notes ----- - Input *RGB* colourspace array is in domain [0, 1]. Examples -------- >>> import numpy as np >>> RGB = np.array([0.17501358, 0.38818795, 0.32161955]) >>> sRGB_to_XYZ(RGB) # doctest: +ELLIPSIS array([ 0.0704953..., 0.1008 , 0.0955831...]) """ sRGB = RGB_COLOURSPACES.get('sRGB') return RGB_to_XYZ(RGB, sRGB.whitepoint, illuminant, sRGB.RGB_to_XYZ_matrix, chromatic_adaptation_method, sRGB.EOCF if apply_EOCF else None)
def test_nan_opto_electronic_conversion_functions(self): """ Tests opto-electronic conversion functions from the :attr:`colour.models.RGB_COLOURSPACES` attribute colourspace models nan support. """ cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] for colourspace in RGB_COLOURSPACES.values(): for case in cases: colourspace.OECF(case) colourspace.EOCF(case)
def test_nan_opto_electronic_conversion_functions(self): """ Tests opto-electronic conversion functions from the :attr:`colour.models.RGB_COLOURSPACES` attribute colourspace models nan support. """ cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] for colourspace in RGB_COLOURSPACES.values(): for case in cases: colourspace.transfer_function(case) colourspace.inverse_transfer_function(case)
def test_nan_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models nan support. """ cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] for colourspace in RGB_COLOURSPACES.values(): for case in cases: colourspace.cctf_encoding(case) colourspace.cctf_decoding(case)
def test_nan_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models nan support. """ cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] for colourspace in RGB_COLOURSPACES.values(): for case in cases: colourspace.encoding_cctf(case) colourspace.decoding_cctf(case)
def test_transformation_matrices(self): """ Tests the transformations matrices from the :attr:`colour.models.RGB_COLOURSPACES` attribute colourspace models. """ XYZ_r = np.array([0.5, 0.5, 0.5]).reshape((3, 1)) for colourspace in RGB_COLOURSPACES.values(): M = normalised_primary_matrix(colourspace.primaries, colourspace.whitepoint) np.testing.assert_allclose(colourspace.RGB_to_XYZ_matrix, M, rtol=0.0001, atol=0.0001, verbose=False) RGB = np.dot(colourspace.XYZ_to_RGB_matrix, XYZ_r) XYZ = np.dot(colourspace.RGB_to_XYZ_matrix, RGB) np.testing.assert_almost_equal(XYZ_r, XYZ, decimal=7)
def test_transformation_matrices(self): """ Test the transformations matrices from the :attr:`colour.models.rgb.datasets.RGB_COLOURSPACES` attribute colourspace models. """ tolerances = { "Adobe RGB (1998)": 1e-5, "ALEXA Wide Gamut": 1e-6, "DJI D-Gamut": 1e-4, "ERIMM RGB": 1e-3, "ProPhoto RGB": 1e-3, "REDWideGamutRGB": 1e-6, "RIMM RGB": 1e-3, "ROMM RGB": 1e-3, "sRGB": 1e-4, "V-Gamut": 1e-6, } XYZ_r = np.array([0.5, 0.5, 0.5]).reshape([3, 1]) for colourspace in RGB_COLOURSPACES.values(): M = normalised_primary_matrix(colourspace.primaries, colourspace.whitepoint) tolerance = tolerances.get(colourspace.name, 1e-7) np.testing.assert_allclose( colourspace.matrix_RGB_to_XYZ, M, rtol=tolerance, atol=tolerance, verbose=False, ) RGB = np.dot(colourspace.matrix_XYZ_to_RGB, XYZ_r) XYZ = np.dot(colourspace.matrix_RGB_to_XYZ, RGB) np.testing.assert_allclose(XYZ_r, XYZ, rtol=tolerance, atol=tolerance, verbose=False) # Derived transformation matrices. colourspace = deepcopy(colourspace) colourspace.use_derived_transformation_matrices(True) RGB = np.dot(colourspace.matrix_XYZ_to_RGB, XYZ_r) XYZ = np.dot(colourspace.matrix_RGB_to_XYZ, RGB) np.testing.assert_almost_equal(XYZ_r, XYZ, decimal=7)
def test_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models. """ aces_proxy_colourspaces = ('ACESproxy', 'ACEScg') samples = np.linspace(0, 1, 1000) for colourspace in RGB_COLOURSPACES.values(): encoding_cctf_s = colourspace.encoding_cctf(samples) decoding_cctf_s = colourspace.decoding_cctf(encoding_cctf_s) if colourspace.name not in aces_proxy_colourspaces: np.testing.assert_almost_equal( samples, decoding_cctf_s, decimal=7)
def test_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models. """ aces_proxy_colourspaces = ('ACESproxy', 'ACEScg') samples = np.linspace(0, 1, 1000) for colourspace in RGB_COLOURSPACES.values(): encoding_cctf_s = colourspace.encoding_cctf(samples) decoding_cctf_s = colourspace.decoding_cctf(encoding_cctf_s) if colourspace.name not in aces_proxy_colourspaces: np.testing.assert_almost_equal(samples, decoding_cctf_s, decimal=7)
def test_n_dimensional_cctf(self): """ Test colour component transfer functions from the :attr:`colour.models.rgb.datasets.RGB_COLOURSPACES` attribute colourspace models n-dimensional arrays support. """ decimals = {"DJI D-Gamut": 6, "F-Gamut": 4} for colourspace in RGB_COLOURSPACES.values(): value_cctf_encoding = 0.5 value_cctf_decoding = colourspace.cctf_decoding( colourspace.cctf_encoding(value_cctf_encoding)) np.testing.assert_almost_equal( value_cctf_encoding, value_cctf_decoding, decimal=decimals.get(colourspace.name, 7), ) value_cctf_encoding = np.tile(value_cctf_encoding, 6) value_cctf_decoding = np.tile(value_cctf_decoding, 6) np.testing.assert_almost_equal( value_cctf_encoding, value_cctf_decoding, decimal=decimals.get(colourspace.name, 7), ) value_cctf_encoding = np.reshape(value_cctf_encoding, (3, 2)) value_cctf_decoding = np.reshape(value_cctf_decoding, (3, 2)) np.testing.assert_almost_equal( value_cctf_encoding, value_cctf_decoding, decimal=decimals.get(colourspace.name, 7), ) value_cctf_encoding = np.reshape(value_cctf_encoding, (3, 2, 1)) value_cctf_decoding = np.reshape(value_cctf_decoding, (3, 2, 1)) np.testing.assert_almost_equal( value_cctf_encoding, value_cctf_decoding, decimal=decimals.get(colourspace.name, 7), )
def test_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models. """ ignored_colourspaces = ('ACESproxy', ) samples = np.hstack((np.linspace(0, 1, 1000), np.linspace( 0, 65504, 65504 * 10))) for colourspace in RGB_COLOURSPACES.values(): encoding_cctf_s = colourspace.encoding_cctf(samples) decoding_cctf_s = colourspace.decoding_cctf(encoding_cctf_s) if colourspace.name in ignored_colourspaces: continue np.testing.assert_almost_equal(samples, decoding_cctf_s, decimal=7)
def test_cctf(self): """ Tests colour component transfer functions from the :attr:`colour.models.rgb.rgb_colourspace.RGB_COLOURSPACES` attribute colourspace models. """ ignored_colourspaces = ('ACESproxy', 'DJI D-Gamut') samples = np.hstack( [np.linspace(0, 1, 1e5), np.linspace(0, 65504, 65504 * 10)]) for colourspace in RGB_COLOURSPACES.values(): if colourspace.name in ignored_colourspaces: continue encoding_cctf_s = colourspace.encoding_cctf(samples) decoding_cctf_s = colourspace.decoding_cctf(encoding_cctf_s) np.testing.assert_almost_equal(samples, decoding_cctf_s, decimal=7)
def colour_checker_plot(colour_checker='ColorChecker 2005', **kwargs): """ Plots given colour checker. Parameters ---------- colour_checker : unicode, optional Color checker name. \**kwargs : dict, optional Keywords arguments. Returns ------- bool Definition success. Raises ------ KeyError If the given colour rendition chart is not found in the factory colour rendition charts. Examples -------- >>> colour_checker_plot() # doctest: +SKIP True """ canvas(**kwargs) colour_checker, name = COLOURCHECKERS.get(colour_checker), colour_checker if colour_checker is None: raise KeyError( ('Colour checker "{0}" not found in ' 'factory colour checkers: "{1}".').format( name, sorted(COLOURCHECKERS.keys()))) _name, data, illuminant = colour_checker colour_parameters = [] for _index, label, x, y, Y in data: XYZ = xyY_to_XYZ((x, y, Y)) RGB = XYZ_to_sRGB(XYZ, illuminant) colour_parameters.append( ColourParameter(label.title(), np.clip(np.ravel(RGB), 0, 1))) background_colour = '0.1' matplotlib.pyplot.gca().patch.set_facecolor(background_colour) width = height = 1.0 spacing = 0.25 across = 6 settings = { 'standalone': False, 'width': width, 'height': height, 'spacing': spacing, 'across': across, 'text_size': 8, 'margins': (-0.125, 0.125, -0.5, 0.125)} settings.update(kwargs) multi_colour_plot(colour_parameters, **settings) text_x = width * (across / 2) + (across * (spacing / 2)) - spacing / 2 text_y = -(len(colour_parameters) / across + spacing / 2) pylab.text(text_x, text_y, '{0} - {1} - Colour Rendition Chart'.format( name, RGB_COLOURSPACES.get('sRGB').name), color='0.95', clip_on=True, ha='center') settings.update({ 'title': name, 'facecolor': background_colour, 'edgecolor': None, 'standalone': True}) boundaries(**settings) decorate(**settings) return display(**settings)
def test_pickle(self): """Test the "pickle-ability" of the *RGB* colourspaces.""" for colourspace in RGB_COLOURSPACES.values(): pickle.dumps(colourspace)