Example #1
0
    def test_n_dimensional_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition n-dimensional arrays support.
        """

        Y = 12.19722535 / 100
        L_hdr = 31.996390226262736
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L_hdr, decimal=7)

        Y = np.tile(Y, 6)
        L_hdr = np.tile(L_hdr, 6)
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L_hdr, decimal=7)

        Y = np.reshape(Y, (2, 3))
        L_hdr = np.reshape(L_hdr, (2, 3))
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L_hdr, decimal=7)

        Y = np.reshape(Y, (2, 3, 1))
        L_hdr = np.reshape(L_hdr, (2, 3, 1))
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L_hdr, decimal=7)
Example #2
0
    def test_n_dimensional_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition n-dimensional arrays support.
        """

        Y = 10.08 / 100
        L = 23.10363383
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L, decimal=7)

        Y = np.tile(Y, 6)
        L = np.tile(L, 6)
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L, decimal=7)

        Y = np.reshape(Y, (2, 3))
        L = np.reshape(L, (2, 3))
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L, decimal=7)

        Y = np.reshape(Y, (2, 3, 1))
        L = np.reshape(L, (2, 3, 1))
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L, decimal=7)
Example #3
0
    def test_nan_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition nan support.
        """

        lightness_Fairchild2010(
            np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
Example #4
0
    def test_nan_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition nan support.
        """

        lightness_Fairchild2010(
            np.array([-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]))
Example #5
0
def XYZ_to_hdr_CIELab(
        XYZ,
        illuminant=ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'],
        Y_s=0.2,
        Y_abs=100):
    """
    Converts from *CIE XYZ* tristimulus values to *hdr-CIELAB* colourspace.

    Parameters
    ----------
    XYZ : array_like
        *CIE XYZ* tristimulus values.
    illuminant : array_like, optional
        Reference *illuminant* *xy* chromaticity coordinates or *CIE xyY*
        colourspace array.
    Y_s : numeric or array_like
        Relative luminance :math:`Y_s` of the surround in domain [0, 1].
    Y_abs : numeric or array_like
        Absolute luminance :math:`Y_{abs}` of the scene diffuse white in
        :math:`cd/m^2`.

    Returns
    -------
    ndarray
        *hdr-CIELAB* colourspace array.

    Notes
    -----
    -   Conversion to polar coordinates to compute the *chroma* :math:`C_{hdr}`
        and *hue* :math:`h_{hdr}` correlates can be safely performed with
        :func:`colour.Lab_to_LCHab` definition.
    -   Conversion to cartesian coordinates from the *Lightness*
        :math:`L_{hdr}`, *chroma* :math:`C_{hdr}` and *hue* :math:`h_{hdr}`
        correlates can be safely performed with :func:`colour.LCHab_to_Lab`
        definition.
    -   Input *CIE XYZ* tristimulus values are in domain [0, math:`\infty`].
    -   Input *illuminant* *xy* chromaticity coordinates or *CIE xyY*
        colourspace array are in domain [0, :math:`\infty`].

    Examples
    --------
    >>> XYZ = np.array([0.07049534, 0.10080000, 0.09558313])
    >>> XYZ_to_hdr_CIELab(XYZ)  # doctest: +ELLIPSIS
    array([ 24.9020664..., -46.8312760..., -10.14274843])
    """

    X, Y, Z = tsplit(XYZ)
    X_n, Y_n, Z_n = tsplit(xyY_to_XYZ(xy_to_xyY(illuminant)))

    e = exponent_hdr_CIELab(Y_s, Y_abs)

    L_hdr = lightness_Fairchild2010(Y / Y_n, e)
    a_hdr = 5 * (lightness_Fairchild2010(X / X_n, e) - L_hdr)
    b_hdr = 2 * (L_hdr - lightness_Fairchild2010(Z / Z_n, e))

    Lab_hdr = tstack((L_hdr, a_hdr, b_hdr))

    return Lab_hdr
Example #6
0
    def test_domain_range_scale_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition domain and range scale support.
        """

        L_hdr = lightness_Fairchild2010(12.19722535 / 100)

        d_r = (('reference', 1, 1), (1, 1, 0.01), (100, 100, 1))
        for scale, factor_a, factor_b in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(
                    lightness_Fairchild2010(12.19722535 / 100 * factor_a),
                    L_hdr * factor_b,
                    decimal=7)
Example #7
0
    def test_domain_range_scale_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition domain and range scale support.
        """

        L_hdr = lightness_Fairchild2010(12.19722535 / 100)

        d_r = (('reference', 1, 1), (1, 1, 0.01), (100, 100, 1))
        for scale, factor_a, factor_b in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(
                    lightness_Fairchild2010(12.19722535 / 100 * factor_a),
                    L_hdr * factor_b,
                    decimal=7)
Example #8
0
    def test_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition.
        """

        self.assertAlmostEqual(
            lightness_Fairchild2010(12.19722535 / 100),
            31.996390226262736,
            places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(23.04276781 / 100),
            60.203153682783302,
            places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(6.15720079 / 100),
            11.836517240976489,
            places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(12.19722535 / 100, 2.75),
            24.424283249379986,
            places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(1008), 100.019986327374240, places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(100800), 100.019999997090270, places=7)
Example #9
0
    def test_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition.
        """

        self.assertAlmostEqual(
            lightness_Fairchild2010(12.19722535 / 100),
            31.996390226262736,
            places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(23.04276781 / 100),
            60.203153682783302,
            places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(6.15720079 / 100),
            11.836517240976489,
            places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(12.19722535 / 100, 2.75),
            24.424283249379986,
            places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(1008), 100.019986327374240, places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(100800), 100.019999997090270, places=7)
Example #10
0
    def test_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition.
        """

        self.assertAlmostEqual(lightness_Fairchild2010(10.08 / 100),
                               24.90229027,
                               places=7)

        self.assertAlmostEqual(lightness_Fairchild2010(56.76 / 100),
                               88.79756887,
                               places=7)

        self.assertAlmostEqual(lightness_Fairchild2010(98.32 / 100),
                               95.61301852,
                               places=7)

        self.assertAlmostEqual(lightness_Fairchild2010(10.08 / 100, 2.75),
                               16.06420271,
                               places=7)

        self.assertAlmostEqual(lightness_Fairchild2010(1008),
                               100.019986327374240,
                               places=7)

        self.assertAlmostEqual(lightness_Fairchild2010(100800),
                               100.019999997090270,
                               places=7)
Example #11
0
    def test_n_dimensional_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition n-dimensional arrays support.
        """

        Y = 12.19722535 / 100
        L_hdr = lightness_Fairchild2010(Y)

        Y = np.tile(Y, 6)
        L_hdr = np.tile(L_hdr, 6)
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L_hdr, decimal=7)

        Y = np.reshape(Y, (2, 3))
        L_hdr = np.reshape(L_hdr, (2, 3))
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L_hdr, decimal=7)

        Y = np.reshape(Y, (2, 3, 1))
        L_hdr = np.reshape(L_hdr, (2, 3, 1))
        np.testing.assert_almost_equal(
            lightness_Fairchild2010(Y), L_hdr, decimal=7)
Example #12
0
def XYZ_to_hdr_IPT(XYZ, Y_s=0.2, Y_abs=100):
    """
    Converts from *CIE XYZ* tristimulus values to *hdr-IPT* colourspace.

    Parameters
    ----------
    XYZ : array_like
        *CIE XYZ* tristimulus values.
    Y_s : numeric or array_like
        Relative luminance :math:`Y_s` of the surround in domain [0, 1].
    Y_abs : numeric or array_like
        Absolute luminance :math:`Y_{abs}` of the scene diffuse white in
        :math:`cd/m^2`.

    Returns
    -------
    ndarray
        *hdr-IPT* colourspace array.

    Notes
    -----
    -   Input *CIE XYZ* tristimulus values needs to be adapted for
        *CIE Standard Illuminant D Series* *D65*.

    Examples
    --------
    >>> XYZ = np.array([0.96907232, 1.00000000, 1.12179215])
    >>> XYZ_to_hdr_IPT(XYZ)  # doctest: +ELLIPSIS
    array([ 94.6592917...,   0.3804177...,  -0.2673118...])
    """

    e = exponent_hdr_IPT(Y_s, Y_abs)[..., np.newaxis]

    LMS = dot_vector(IPT_XYZ_TO_LMS_MATRIX, XYZ)
    LMS_prime = np.sign(LMS) * np.abs(lightness_Fairchild2010(LMS, e))
    IPT = dot_vector(IPT_LMS_TO_IPT_MATRIX, LMS_prime)

    return IPT
Example #13
0
    def test_lightness_Fairchild2010(self):
        """
        Tests :func:`colour.colorimetry.lightness.lightness_Fairchild2010`
        definition.
        """

        self.assertAlmostEqual(
            lightness_Fairchild2010(10.08 / 100), 23.10363383, places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(56.76 / 100), 90.51057574, places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(98.32 / 100), 96.636221285, places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(10.08 / 100, 2.75), 16.06420271, places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(1008), 100.01999667, places=7)

        self.assertAlmostEqual(
            lightness_Fairchild2010(100800), 100.01999999, places=7)