def test_nan_eotf_BT2020(self): """ Tests :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\ eotf_BT2020` definition nan support. """ eotf_BT2020(np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
def test_eotf_BT2020(self): """ Tests :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\ eotf_BT2020` definition. """ self.assertAlmostEqual(eotf_BT2020(0.0), 0.0, places=7) self.assertAlmostEqual(eotf_BT2020(0.409007728864150), 0.18, places=7) self.assertAlmostEqual(eotf_BT2020(1.0), 1.0, places=7)
def test_domain_range_scale_eotf_BT2020(self): """ Tests :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\ eotf_BT2020` definition domain and range scale support. """ E_p = 0.409007728864150 E = eotf_BT2020(E_p) d_r = (('reference', 1), (1, 1), (100, 100)) for scale, factor in d_r: with domain_range_scale(scale): np.testing.assert_almost_equal( eotf_BT2020(E_p * factor), E * factor, decimal=7)
def test_n_dimensional_eotf_BT2020(self): """ Tests :func:`colour.models.rgb.transfer_functions.itur_bt_2020.\ eotf_BT2020` definition n-dimensional arrays support. """ E_p = 0.409007728864150 E = eotf_BT2020(E_p) E_p = np.tile(E_p, 6) E = np.tile(E, 6) np.testing.assert_almost_equal(eotf_BT2020(E_p), E, decimal=7) E_p = np.reshape(E_p, (2, 3)) E = np.reshape(E, (2, 3)) np.testing.assert_almost_equal(eotf_BT2020(E_p), E, decimal=7) E_p = np.reshape(E_p, (2, 3, 1)) E = np.reshape(E, (2, 3, 1)) np.testing.assert_almost_equal(eotf_BT2020(E_p), E, decimal=7)
def test_n_dimensional_eotf_BT2020(self): """ Tests :func:`colour.models.rgb.transfer_functions.bt_2020.\ eotf_BT2020` definition n-dimensional arrays support. """ V = 0.409007728864150 L = 0.18 np.testing.assert_almost_equal(eotf_BT2020(V), L, decimal=7) V = np.tile(V, 6) L = np.tile(L, 6) np.testing.assert_almost_equal(eotf_BT2020(V), L, decimal=7) V = np.reshape(V, (2, 3)) L = np.reshape(L, (2, 3)) np.testing.assert_almost_equal(eotf_BT2020(V), L, decimal=7) V = np.reshape(V, (2, 3, 1)) L = np.reshape(L, (2, 3, 1)) np.testing.assert_almost_equal(eotf_BT2020(V), L, decimal=7)
def YcCbcCrc_to_RGB(YcCbcCrc, in_bits=10, in_legal=True, in_int=False, is_12_bits_system=False, **kwargs): """ Converts an array of *Yc'Cbc'Crc'* colour encoding values to the corresponding *RGB* array of linear values. Parameters ---------- YcCbcCrc : array_like Input *Yc'Cbc'Crc'* colour encoding array of linear float values. in_bits : int, optional Bit depth for integer input, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is `235 / 255`. Default is `10`. in_legal : bool, optional Whether to treat the input values as legal range. Default is `False`. in_int : bool, optional Whether to treat the input values as `in_bits` integer code values. Default is `False`. is_12_bits_system : bool, optional *Recommendation ITU-R BT.2020* EOTF (EOCF) adopts different parameters for 10 and 12 bit systems. Default is `False`. Other Parameters ---------------- in_range : array_like, optional Array overriding the computed range such as `in_range = (Y_min, Y_max, C_min, C_max)`. If `in_range` is undefined, `Y_min`, `Y_max`, `C_min` and `C_max` will be computed using :func:`YCbCr_ranges` definition. Returns ------- ndarray *RGB* array of linear float values. Warning ------- This definition is specifically for usage with *Recommendation ITU-R BT.2020* [3]_ when adopting the constant luminance implementation. Examples -------- >>> YcCbcCrc = np.array([1689, 2048, 2048]) >>> YcCbcCrc_to_RGB( # doctest: +ELLIPSIS ... YcCbcCrc, ... in_legal=True, ... in_bits=12, ... in_int=True, ... is_12_bits_system=True) array([ 0.1800903..., 0.1800903..., 0.1800903...]) """ YcCbcCrc = np.asarray(YcCbcCrc) Yc, Cbc, Crc = tsplit(YcCbcCrc.astype(np.float_)) Y_min, Y_max, C_min, C_max = kwargs.get( 'in_range', YCbCr_ranges(in_bits, in_legal, in_int)) Yc -= Y_min Cbc -= (C_max + C_min) / 2 Crc -= (C_max + C_min) / 2 Yc *= 1 / (Y_max - Y_min) Cbc *= 1 / (C_max - C_min) Crc *= 1 / (C_max - C_min) B = np.where(Cbc <= 0, Cbc * 1.9404 + Yc, Cbc * 1.5816 + Yc) R = np.where(Crc <= 0, Crc * 1.7184 + Yc, Crc * 0.9936 + Yc) Yc = eotf_BT2020(Yc, is_12_bits_system=is_12_bits_system) B = eotf_BT2020(B, is_12_bits_system=is_12_bits_system) R = eotf_BT2020(R, is_12_bits_system=is_12_bits_system) G = (Yc - 0.0593 * B - 0.2627 * R) / 0.6780 RGB = tstack((R, G, B)) return RGB
def YcCbcCrc_to_RGB(YcCbcCrc, in_bits=10, in_legal=True, in_int=False, is_12_bits_system=False, **kwargs): """ Converts an array of *Yc'Cbc'Crc'* colour encoding values to the corresponding *RGB* array of linear values. Parameters ---------- YcCbcCrc : array_like Input *Yc'Cbc'Crc'* colour encoding array of linear float values. in_bits : int, optional Bit depth for integer input, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is *235 / 255*. Default is *10*. in_legal : bool, optional Whether to treat the input values as legal range. Default is *False*. in_int : bool, optional Whether to treat the input values as ``in_bits`` integer code values. Default is *False*. is_12_bits_system : bool, optional *Recommendation ITU-R BT.2020* EOTF (EOCF) adopts different parameters for 10 and 12 bit systems. Default is *False*. Other Parameters ---------------- in_range : array_like, optional Array overriding the computed range such as *in_range = (Y_min, Y_max, C_min, C_max)*. If ``in_range`` is undefined, *Y_min*, *Y_max*, *C_min* and *C_max* will be computed using :func:`colour.models.rgb.ycbcr.YCbCr_ranges` definition. Returns ------- ndarray *RGB* array of linear float values. Notes ----- +----------------+-----------------------+---------------+ | **Domain \\*** | **Scale - Reference** | **Scale - 1** | +================+=======================+===============+ | ``YcCbcCrc`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ +----------------+-----------------------+---------------+ | **Range \\*** | **Scale - Reference** | **Scale - 1** | +================+=======================+===============+ | ``RGB`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ \\* This definition has input and output integer switches, thus the domain-range scale information is only given for the floating point mode. Warnings -------- This definition is specifically for usage with *Recommendation ITU-R BT.2020* when adopting the constant luminance implementation. References ---------- :cite:`InternationalTelecommunicationUnion2015h`, :cite:`Wikipedia2004d` Examples -------- >>> YcCbcCrc = np.array([1689, 2048, 2048]) >>> YcCbcCrc_to_RGB(YcCbcCrc, in_legal=True, in_bits=12, in_int=True, ... is_12_bits_system=True) ... # doctest: +ELLIPSIS array([ 0.1800903..., 0.1800903..., 0.1800903...]) """ if in_int: YcCbcCrc = as_float_array(YcCbcCrc) else: YcCbcCrc = to_domain_1(YcCbcCrc) Yc, Cbc, Crc = tsplit(YcCbcCrc.astype(DEFAULT_FLOAT_DTYPE)) Y_min, Y_max, C_min, C_max = kwargs.get( 'in_range', YCbCr_ranges(in_bits, in_legal, in_int)) Yc -= Y_min Cbc -= (C_max + C_min) / 2 Crc -= (C_max + C_min) / 2 Yc *= 1 / (Y_max - Y_min) Cbc *= 1 / (C_max - C_min) Crc *= 1 / (C_max - C_min) B = np.where(Cbc <= 0, Cbc * 1.9404 + Yc, Cbc * 1.5816 + Yc) R = np.where(Crc <= 0, Crc * 1.7184 + Yc, Crc * 0.9936 + Yc) with domain_range_scale('ignore'): Yc = eotf_BT2020(Yc, is_12_bits_system=is_12_bits_system) B = eotf_BT2020(B, is_12_bits_system=is_12_bits_system) R = eotf_BT2020(R, is_12_bits_system=is_12_bits_system) G = (Yc - 0.0593 * B - 0.2627 * R) / 0.6780 RGB = tstack([R, G, B]) return from_range_1(RGB)
def YcCbcCrc_to_RGB(YcCbcCrc, in_bits=10, in_legal=True, in_int=False, is_12_bits_system=False, **kwargs): """ Converts an array of *Yc'Cbc'Crc'* colour encoding values to the corresponding *RGB* array of linear values. Parameters ---------- YcCbcCrc : array_like Input *Yc'Cbc'Crc'* colour encoding array of linear float values. in_bits : int, optional Bit depth for integer input, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is *235 / 255*. Default is *10*. in_legal : bool, optional Whether to treat the input values as legal range. Default is *False*. in_int : bool, optional Whether to treat the input values as ``in_bits`` integer code values. Default is *False*. is_12_bits_system : bool, optional *Recommendation ITU-R BT.2020* EOTF (EOCF) adopts different parameters for 10 and 12 bit systems. Default is *False*. Other Parameters ---------------- in_range : array_like, optional Array overriding the computed range such as *in_range = (Y_min, Y_max, C_min, C_max)*. If ``in_range`` is undefined, *Y_min*, *Y_max*, *C_min* and *C_max* will be computed using :func:`colour.models.rgb.ycbcr.YCbCr_ranges` definition. Returns ------- ndarray *RGB* array of linear float values. Notes ----- +----------------+-----------------------+---------------+ | **Domain \\*** | **Scale - Reference** | **Scale - 1** | +================+=======================+===============+ | ``YcCbcCrc`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ +----------------+-----------------------+---------------+ | **Range \\*** | **Scale - Reference** | **Scale - 1** | +================+=======================+===============+ | ``RGB`` | [0, 1] | [0, 1] | +----------------+-----------------------+---------------+ - \\* This definition has input and output integer switches, thus the domain-range scale information is only given for the floating point mode. Warning ------- This definition is specifically for usage with *Recommendation ITU-R BT.2020* when adopting the constant luminance implementation. References ---------- :cite:`InternationalTelecommunicationUnion2015h`, :cite:`Wikipedia2004d` Examples -------- >>> YcCbcCrc = np.array([1689, 2048, 2048]) >>> YcCbcCrc_to_RGB(YcCbcCrc, in_legal=True, in_bits=12, in_int=True, ... is_12_bits_system=True) ... # doctest: +ELLIPSIS array([ 0.1800903..., 0.1800903..., 0.1800903...]) """ if in_int: YcCbcCrc = as_float_array(YcCbcCrc) else: YcCbcCrc = to_domain_1(YcCbcCrc) Yc, Cbc, Crc = tsplit(YcCbcCrc.astype(DEFAULT_FLOAT_DTYPE)) Y_min, Y_max, C_min, C_max = kwargs.get( 'in_range', YCbCr_ranges(in_bits, in_legal, in_int)) Yc -= Y_min Cbc -= (C_max + C_min) / 2 Crc -= (C_max + C_min) / 2 Yc *= 1 / (Y_max - Y_min) Cbc *= 1 / (C_max - C_min) Crc *= 1 / (C_max - C_min) B = np.where(Cbc <= 0, Cbc * 1.9404 + Yc, Cbc * 1.5816 + Yc) R = np.where(Crc <= 0, Crc * 1.7184 + Yc, Crc * 0.9936 + Yc) with domain_range_scale('ignore'): Yc = eotf_BT2020(Yc, is_12_bits_system=is_12_bits_system) B = eotf_BT2020(B, is_12_bits_system=is_12_bits_system) R = eotf_BT2020(R, is_12_bits_system=is_12_bits_system) G = (Yc - 0.0593 * B - 0.2627 * R) / 0.6780 RGB = tstack([R, G, B]) return from_range_1(RGB)
def YcCbcCrc_to_RGB(YcCbcCrc, in_bits=10, in_legal=True, in_int=False, is_12_bits_system=False, **kwargs): """ Converts an array of *Yc'Cbc'Crc'* colour encoding values to the corresponding *RGB* array of linear values. Parameters ---------- YcCbcCrc : array_like Input *Yc'Cbc'Crc'* colour encoding array of linear float values. in_bits : int, optional Bit depth for integer input, or used in the calculation of the denominator for legal range float values, i.e. 8-bit means the float value for legal white is `235 / 255`. Default is `10`. in_legal : bool, optional Whether to treat the input values as legal range. Default is `False`. in_int : bool, optional Whether to treat the input values as `in_bits` integer code values. Default is `False`. is_12_bits_system : bool, optional *Recommendation ITU-R BT.2020* EOTF (EOCF) adopts different parameters for 10 and 12 bit systems. Default is `False`. \**kwargs : dict, optional **{'in_range'}** Keyword arguments to override the calculated ranges such as ``{'in_range' : array_like (Y_min, Y_max, C_min, C_max)}`` Returns ------- ndarray *RGB* array of linear float values. Warning ------- This definition is specifically for usage with *Recommendation ITU-R BT.2020* [3]_ when adopting the constant luminance implementation. Examples -------- >>> YcCbcCrc = np.array([1689, 2048, 2048]) >>> YcCbcCrc_to_RGB( # doctest: +ELLIPSIS ... YcCbcCrc, ... in_legal=True, ... in_bits=12, ... in_int=True, ... is_12_bits_system=True) array([ 0.1800903..., 0.1800903..., 0.1800903...]) """ YcCbcCrc = np.asarray(YcCbcCrc) Yc, Cbc, Crc = tsplit(YcCbcCrc.astype(np.float_)) Y_min, Y_max, C_min, C_max = kwargs.get( 'in_range', YCbCr_ranges(in_bits, in_legal, in_int)) Yc -= Y_min Cbc -= (C_max + C_min) / 2 Crc -= (C_max + C_min) / 2 Yc *= 1 / (Y_max - Y_min) Cbc *= 1 / (C_max - C_min) Crc *= 1 / (C_max - C_min) B = np.where(Cbc <= 0, Cbc * 1.9404 + Yc, Cbc * 1.5816 + Yc) R = np.where(Crc <= 0, Crc * 1.7184 + Yc, Crc * 0.9936 + Yc) Yc = eotf_BT2020(Yc, is_12_bits_system=is_12_bits_system) B = eotf_BT2020(B, is_12_bits_system=is_12_bits_system) R = eotf_BT2020(R, is_12_bits_system=is_12_bits_system) G = (Yc - 0.0593 * B - 0.2627 * R) / 0.6780 RGB = tstack((R, G, B)) return RGB