def test_n_dimensional_gamma_function(self): """ Tests :func:`colour.models.rgb.transfer_functions.gamma.\ gamma_function` definition n-dimensional arrays support. """ a = 0.18 a_p = 0.022993204992707 np.testing.assert_almost_equal( gamma_function(a, 2.2), a_p, decimal=7) a = np.tile(a, 6) a_p = np.tile(a_p, 6) np.testing.assert_almost_equal( gamma_function(a, 2.2), a_p, decimal=7) a = np.reshape(a, (2, 3)) a_p = np.reshape(a_p, (2, 3)) np.testing.assert_almost_equal( gamma_function(a, 2.2), a_p, decimal=7) a = np.reshape(a, (2, 3, 1)) a_p = np.reshape(a_p, (2, 3, 1)) np.testing.assert_almost_equal( gamma_function(a, 2.2), a_p, decimal=7)
def test_n_dimensional_gamma_function(self): """ Tests :func:`colour.models.rgb.transfer_functions.gamma.\ gamma_function` definition n-dimensional arrays support. """ a = 0.18 a_p = 0.022993204992707 np.testing.assert_almost_equal( gamma_function(a, 2.2), a_p, decimal=7) a = np.tile(a, 6) a_p = np.tile(a_p, 6) np.testing.assert_almost_equal( gamma_function(a, 2.2), a_p, decimal=7) a = np.reshape(a, (2, 3)) a_p = np.reshape(a_p, (2, 3)) np.testing.assert_almost_equal( gamma_function(a, 2.2), a_p, decimal=7) a = np.reshape(a, (2, 3, 1)) a_p = np.reshape(a_p, (2, 3, 1)) np.testing.assert_almost_equal( gamma_function(a, 2.2), a_p, decimal=7)
def test_nan_gamma_function(self): """ Tests :func:`colour.models.rgb.transfer_functions.gamma.\ gamma_function` definition nan support. """ cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] for case in cases: gamma_function(case, case)
def test_gamma_function(self): """ Tests :func:`colour.models.rgb.transfer_functions.gamma.\ gamma_function` definition. """ self.assertAlmostEqual(gamma_function(0.0, 2.2), 0.0, places=7) self.assertAlmostEqual(gamma_function(0.18, 2.2), 0.022993204992707, places=7) self.assertAlmostEqual(gamma_function(0.022993204992707, 1.0 / 2.2), 0.18, places=7)
def oetf_ARIBSTDB67(E, r=0.5, constants=ARIBSTDB67_CONSTANTS): """ Defines *ARIB STD-B67 (Hybrid Log-Gamma)* opto-electrical transfer function (OETF / OECF). Parameters ---------- E : numeric or array_like Voltage normalised by the reference white level and proportional to the implicit light intensity that would be detected with a reference camera color channel R, G, B. r : numeric, optional Video level corresponding to reference white level. constants : Structure, optional *ARIB STD-B67 (Hybrid Log-Gamma)* constants. Returns ------- numeric or ndarray Resulting non-linear signal :math:`E'`. Notes ----- +------------+-----------------------+---------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``E`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ +------------+-----------------------+---------------+ | **Range** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``E_p`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ - This definition uses the *mirror* negative number handling mode of :func:`colour.models.gamma_function` definition to the sign of negative numbers. References ---------- :cite:`AssociationofRadioIndustriesandBusinesses2015a` Examples -------- >>> oetf_ARIBSTDB67(0.18) # doctest: +ELLIPSIS 0.2121320... """ E = to_domain_1(E) a = constants.a b = constants.b c = constants.c E_p = np.where(E <= 1, r * gamma_function(E, 0.5, 'mirror'), a * np.log(E - b) + c) return as_float(from_range_1(E_p))
def test_gamma_function(self): """ Tests :func:`colour.models.rgb.transfer_functions.gamma.\ gamma_function` definition. """ self.assertAlmostEqual( gamma_function(0.0, 2.2), 0.0, places=7) self.assertAlmostEqual( gamma_function(0.18, 2.2), 0.022993204992707, places=7) self.assertAlmostEqual( gamma_function(0.022993204992707, 1.0 / 2.2), 0.18, places=7)
def test_gamma_function(self): """ Tests :func:`colour.models.rgb.transfer_functions.gamma.\ gamma_function` definition. """ self.assertAlmostEqual( gamma_function(0.0, 2.2), 0.0, places=7) self.assertAlmostEqual( gamma_function(0.18, 2.2), 0.022993204992707, places=7) self.assertAlmostEqual( gamma_function(0.022993204992707, 1.0 / 2.2), 0.18, places=7) self.assertAlmostEqual( gamma_function(-0.18, 2.0), 0.0323999999999998, places=7) np.testing.assert_array_equal( gamma_function(-0.18, 2.2), np.nan) self.assertAlmostEqual( gamma_function(-0.18, 2.2, 'Mirror'), -0.022993204992707, places=7) self.assertAlmostEqual( gamma_function(-0.18, 2.2, 'Preserve'), -0.18, places=7) self.assertAlmostEqual( gamma_function(-0.18, 2.2, 'Clamp'), 0, places=7)
def oetf_inverse_ARIBSTDB67(E_p, r=0.5, constants=ARIBSTDB67_CONSTANTS): """ Defines *ARIB STD-B67 (Hybrid Log-Gamma)* inverse opto-electrical transfer function (OETF / OECF). Parameters ---------- E_p : numeric or array_like Non-linear signal :math:`E'`. r : numeric, optional Video level corresponding to reference white level. constants : Structure, optional *ARIB STD-B67 (Hybrid Log-Gamma)* constants. Returns ------- numeric or ndarray Voltage :math:`E` normalised by the reference white level and proportional to the implicit light intensity that would be detected with a reference camera color channel R, G, B. Notes ----- +------------+-----------------------+---------------+ | **Domain** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``E_p`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ +------------+-----------------------+---------------+ | **Range** | **Scale - Reference** | **Scale - 1** | +============+=======================+===============+ | ``E`` | [0, 1] | [0, 1] | +------------+-----------------------+---------------+ - This definition uses the *mirror* negative number handling mode of :func:`colour.models.gamma_function` definition to the sign of negative numbers. References ---------- :cite:`AssociationofRadioIndustriesandBusinesses2015a` Examples -------- >>> oetf_inverse_ARIBSTDB67(0.212132034355964) # doctest: +ELLIPSIS 0.1799999... """ E_p = to_domain_1(E_p) a = constants.a b = constants.b c = constants.c with domain_range_scale('ignore'): E = np.where( E_p <= oetf_ARIBSTDB67(1), gamma_function((E_p / r), 2, 'mirror'), np.exp((E_p - c) / a) + b, ) return as_float(from_range_1(E))
def test_gamma_function(self): """ Tests :func:`colour.models.rgb.transfer_functions.gamma.\ gamma_function` definition. """ self.assertAlmostEqual(gamma_function(0.0, 2.2), 0.0, places=7) self.assertAlmostEqual( gamma_function(0.18, 2.2), 0.022993204992707, places=7) self.assertAlmostEqual( gamma_function(0.022993204992707, 1.0 / 2.2), 0.18, places=7) self.assertAlmostEqual( gamma_function(-0.18, 2.0), 0.0323999999999998, places=7) np.testing.assert_array_equal(gamma_function(-0.18, 2.2), np.nan) self.assertAlmostEqual( gamma_function(-0.18, 2.2, 'Mirror'), -0.022993204992707, places=7) self.assertAlmostEqual( gamma_function(-0.18, 2.2, 'Preserve'), -0.18, places=7) self.assertAlmostEqual( gamma_function(-0.18, 2.2, 'Clamp'), 0, places=7) np.testing.assert_array_equal(gamma_function(-0.18, -2.2), np.nan) self.assertAlmostEqual( gamma_function(0.0, -2.2, 'Mirror'), 0.0, places=7) self.assertAlmostEqual( gamma_function(0.0, 2.2, 'Preserve'), 0.0, places=7) self.assertAlmostEqual(gamma_function(0.0, 2.2, 'Clamp'), 0, places=7)