示例#1
0
    def test_n_dimensional_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition n-dimensional arrays support.
        """

        XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
        XYZ_w = np.array([0.95045593, 1.00000000, 1.08905775])
        XYZ_wr = np.array([0.96429568, 1.00000000, 0.82510460])
        XYZ_a = chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr)

        XYZ = np.tile(XYZ, (6, 1))
        XYZ_w = np.tile(XYZ_w, (6, 1))
        XYZ_wr = np.tile(XYZ_wr, (6, 1))
        XYZ_a = np.tile(XYZ_a, (6, 1))
        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr),
            XYZ_a,
            decimal=7)

        XYZ = np.reshape(XYZ, (2, 3, 3))
        XYZ_w = np.reshape(XYZ_w, (2, 3, 3))
        XYZ_wr = np.reshape(XYZ_wr, (2, 3, 3))
        XYZ_a = np.reshape(XYZ_a, (2, 3, 3))
        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr),
            XYZ_a,
            decimal=7)
示例#2
0
    def test_n_dimensional_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition n-dimensional arrays support.
        """

        XYZ = np.array([0.07049534, 0.10080000, 0.09558313])
        XYZ_w = np.array([1.09846607, 1.00000000, 0.35582280])
        XYZ_wr = np.array([0.95042855, 1.00000000, 1.08890037])
        XYZ_a = np.array([0.08397461, 0.11413219, 0.28625545])
        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr),
            XYZ_a,
            decimal=7)

        XYZ = np.tile(XYZ, (6, 1))
        XYZ_w = np.tile(XYZ_w, (6, 1))
        XYZ_wr = np.tile(XYZ_wr, (6, 1))
        XYZ_a = np.tile(XYZ_a, (6, 1))
        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr),
            XYZ_a,
            decimal=7)

        XYZ = np.reshape(XYZ, (2, 3, 3))
        XYZ_w = np.reshape(XYZ_w, (2, 3, 3))
        XYZ_wr = np.reshape(XYZ_wr, (2, 3, 3))
        XYZ_a = np.reshape(XYZ_a, (2, 3, 3))
        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr),
            XYZ_a,
            decimal=7)
示例#3
0
    def test_n_dimensional_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition n-dimensional arrays support.
        """

        XYZ = np.array([0.07049534, 0.10080000, 0.09558313])
        XYZ_w = np.array([1.09846607, 1.00000000, 0.35582280])
        XYZ_wr = np.array([0.95042855, 1.00000000, 1.08890037])
        XYZ_a = np.array([0.08397461, 0.11413219, 0.28625545])
        np.testing.assert_almost_equal(chromatic_adaptation_VonKries(
            XYZ, XYZ_w, XYZ_wr),
                                       XYZ_a,
                                       decimal=7)

        XYZ = np.tile(XYZ, (6, 1))
        XYZ_w = np.tile(XYZ_w, (6, 1))
        XYZ_wr = np.tile(XYZ_wr, (6, 1))
        XYZ_a = np.tile(XYZ_a, (6, 1))
        np.testing.assert_almost_equal(chromatic_adaptation_VonKries(
            XYZ, XYZ_w, XYZ_wr),
                                       XYZ_a,
                                       decimal=7)

        XYZ = np.reshape(XYZ, (2, 3, 3))
        XYZ_w = np.reshape(XYZ_w, (2, 3, 3))
        XYZ_wr = np.reshape(XYZ_wr, (2, 3, 3))
        XYZ_a = np.reshape(XYZ_a, (2, 3, 3))
        np.testing.assert_almost_equal(chromatic_adaptation_VonKries(
            XYZ, XYZ_w, XYZ_wr),
                                       XYZ_a,
                                       decimal=7)
示例#4
0
    def test_n_dimensional_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition n-dimensional arrays support.
        """

        XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
        XYZ_w = np.array([0.95045593, 1.00000000, 1.08905775])
        XYZ_wr = np.array([0.96429568, 1.00000000, 0.82510460])
        XYZ_a = chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr)

        XYZ = np.tile(XYZ, (6, 1))
        XYZ_w = np.tile(XYZ_w, (6, 1))
        XYZ_wr = np.tile(XYZ_wr, (6, 1))
        XYZ_a = np.tile(XYZ_a, (6, 1))
        np.testing.assert_almost_equal(chromatic_adaptation_VonKries(
            XYZ, XYZ_w, XYZ_wr),
                                       XYZ_a,
                                       decimal=7)

        XYZ = np.reshape(XYZ, (2, 3, 3))
        XYZ_w = np.reshape(XYZ_w, (2, 3, 3))
        XYZ_wr = np.reshape(XYZ_wr, (2, 3, 3))
        XYZ_a = np.reshape(XYZ_a, (2, 3, 3))
        np.testing.assert_almost_equal(chromatic_adaptation_VonKries(
            XYZ, XYZ_w, XYZ_wr),
                                       XYZ_a,
                                       decimal=7)
示例#5
0
    def test_nan_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition nan support.
        """

        cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
        cases = set(permutations(cases * 3, r=3))
        for case in cases:
            XYZ = np.array(case)
            XYZ_w = np.array(case)
            XYZ_wr = np.array(case)
            chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr)
示例#6
0
    def test_nan_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition nan support.
        """

        cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
        cases = set(permutations(cases * 3, r=3))
        for case in cases:
            XYZ = np.array(case)
            XYZ_w = np.array(case)
            XYZ_wr = np.array(case)
            chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr)
示例#7
0
def corresponding_chromaticities_prediction_VonKries(experiment=1,
                                                     transform='CAT02'):
    """
    Returns the corresponding chromaticities prediction for Von Kries
    chromatic adaptation model using given transform.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        Breneman (1987) experiment number.
    transform : unicode, optional
        {'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild,
        'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco', 'Bianco PC'},
        Chromatic adaptation transform.

    Returns
    -------
    tuple
        Corresponding chromaticities prediction.

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_VonKries(2, 'Bradford')
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.20820148430638033, 0.47229226819364528)),
     ((0.449, 0.511), (0.44891022948064191, 0.50716028901449561)),
     ((0.263, 0.505), (0.26435459360846608, 0.49596314494922683)),
     ((0.322, 0.545), (0.33487309037107632, 0.54712207251983425)),
     ((0.316, 0.537), (0.32487581236911361, 0.53905899356457776)),
     ((0.265, 0.553), (0.27331050571632376, 0.55550280647813977)),
     ((0.221, 0.538), (0.22714800102072819, 0.53313179748041983)),
     ((0.135, 0.532), (0.14427303768336433, 0.52268044497913713)),
     ((0.145, 0.472), (0.14987451889726533, 0.45507852741116867)),
     ((0.163, 0.331), (0.15649757464732098, 0.31487959772753954)),
     ((0.176, 0.431), (0.17605936460371163, 0.41037722722471409)),
     ((0.244, 0.349), (0.22598059059292835, 0.34652914678030416))]
    """

    experiment_results = list(BRENEMAN_EXPERIMENTS.get(experiment))

    illuminants = experiment_results.pop(0)
    XYZ_w = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_t))
    XYZ_wr = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_m))
    xy_wr = XYZ_to_xy(XYZ_wr)

    prediction = []
    for result in experiment_results:
        XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t))
        XYZ_2 = chromatic_adaptation_VonKries(XYZ_1, XYZ_w, XYZ_wr, transform)
        uvp = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_wr), xy_wr)
        prediction.append(CorrespondingChromaticitiesPrediction(
            result.name,
            result.uvp_t,
            result.uvp_m,
            uvp))

    return tuple(prediction)
示例#8
0
def vs_colorimetry_data(spd_test,
                        spd_reference,
                        spds_vs,
                        cmfs,
                        chromatic_adaptation=False):

    XYZ_t = spectral_to_XYZ(spd_test, cmfs)
    XYZ_t /= XYZ_t[1]

    XYZ_r = spectral_to_XYZ(spd_reference, cmfs)
    XYZ_r /= XYZ_r[1]
    xy_r = XYZ_to_xy(XYZ_r)

    vs_data = []
    for _key, value in sorted(VS_INDEXES_TO_NAMES.items()):
        spd_vs = spds_vs.get(value)
        XYZ_vs = spectral_to_XYZ(spd_vs, cmfs, spd_test)
        XYZ_vs /= 100

        if chromatic_adaptation:
            XYZ_vs = chromatic_adaptation_VonKries(XYZ_vs,
                                                   XYZ_t,
                                                   XYZ_r,
                                                   transform='CMCCAT2000')

        Lab_vs = XYZ_to_Lab(XYZ_vs, illuminant=xy_r)
        _L_vs, C_vs, _Hab = Lab_to_LCHab(Lab_vs)

        vs_data.append(VS_ColorimetryData(spd_vs.name, XYZ_vs, Lab_vs, C_vs))
    return vs_data
示例#9
0
def CCT_factor(reference_data, XYZ_r):
    """
    Returns the correlated colour temperature factor penalizing lamps with
    extremely low correlated colour temperatures.

    Parameters
    ----------
    reference_data : VS_ColorimetryData
        Reference colorimetry data.
    XYZ_r : array_like
        *CIE XYZ* tristimulus values for reference.

    Returns
    -------
    numeric
        Correlated colour temperature factor.
    """

    xy_w = ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
    XYZ_w = xy_to_XYZ(xy_w)

    Labs = []
    for vs_colorimetry_data_ in reference_data:
        _name, XYZ, _Lab, _C = vs_colorimetry_data_
        XYZ_a = chromatic_adaptation_VonKries(
            XYZ, XYZ_r, XYZ_w, transform='CMCCAT2000')

        Lab = XYZ_to_Lab(XYZ_a, illuminant=xy_w)
        Labs.append(Lab)

    G_r = gamut_area(Labs) / D65_GAMUT_AREA
    CCT_f = 1 if G_r > 1 else G_r

    return CCT_f
示例#10
0
def corresponding_chromaticities_prediction_VonKries(experiment=1,
                                                     transform='CAT02'):
    """
    Returns the corresponding chromaticities prediction for *Von Kries*
    chromatic adaptation model using given transform.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        *Breneman (1987)* experiment number.
    transform : unicode, optional
        **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp',
        'Fairchild', 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco',
        'Bianco PC'}**,
        Chromatic adaptation transform.

    Returns
    -------
    tuple
        Corresponding chromaticities prediction.

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_VonKries(2, 'Bradford')
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.2082014..., 0.4722922...)),
     ((0.449, 0.511), (0.4489102..., 0.5071602...)),
     ((0.263, 0.505), (0.2643545..., 0.4959631...)),
     ((0.322, 0.545), (0.3348730..., 0.5471220...)),
     ((0.316, 0.537), (0.3248758..., 0.5390589...)),
     ((0.265, 0.553), (0.2733105..., 0.5555028...)),
     ((0.221, 0.538), (0.2271480..., 0.5331317...)),
     ((0.135, 0.532), (0.1442730..., 0.5226804...)),
     ((0.145, 0.472), (0.1498745..., 0.4550785...)),
     ((0.163, 0.331), (0.1564975..., 0.3148795...)),
     ((0.176, 0.431), (0.1760593..., 0.4103772...)),
     ((0.244, 0.349), (0.2259805..., 0.3465291...))]
    """

    experiment_results = list(BRENEMAN_EXPERIMENTS[experiment])

    illuminants = experiment_results.pop(0)
    XYZ_w = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_t))
    XYZ_wr = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_m))
    xy_wr = XYZ_to_xy(XYZ_wr)

    prediction = []
    for result in experiment_results:
        XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t))
        XYZ_2 = chromatic_adaptation_VonKries(XYZ_1, XYZ_w, XYZ_wr, transform)
        uvp = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_wr), xy_wr)
        prediction.append(
            CorrespondingChromaticitiesPrediction(result.name, result.uvp_t,
                                                  result.uvp_m, uvp))

    return tuple(prediction)
示例#11
0
def chromatically_adapted_primaries(
    primaries: ArrayLike,
    whitepoint_t: ArrayLike,
    whitepoint_r: ArrayLike,
    chromatic_adaptation_transform: Union[Literal["Bianco 2010",
                                                  "Bianco PC 2010", "Bradford",
                                                  "CAT02 Brill 2008", "CAT02",
                                                  "CAT16", "CMCCAT2000",
                                                  "CMCCAT97", "Fairchild",
                                                  "Sharp", "Von Kries",
                                                  "XYZ Scaling", ],
                                          str, ] = "CAT02",
) -> NDArray:
    """
    Chromatically adapt given *primaries* :math:`xy` chromaticity coordinates
    from test ``whitepoint_t`` to reference ``whitepoint_r``.

    Parameters
    ----------
    primaries
        Primaries :math:`xy` chromaticity coordinates.
    whitepoint_t
        Test illuminant / whitepoint :math:`xy` chromaticity coordinates.
    whitepoint_r
        Reference illuminant / whitepoint :math:`xy` chromaticity coordinates.
    chromatic_adaptation_transform
        *Chromatic adaptation* transform.

    Returns
    -------
    :class:`numpy.ndarray`
        Chromatically adapted primaries :math:`xy` chromaticity coordinates.

    Examples
    --------
    >>> p = np.array([0.64, 0.33, 0.30, 0.60, 0.15, 0.06])
    >>> w_t = np.array([0.31270, 0.32900])
    >>> w_r = np.array([0.34570, 0.35850])
    >>> chromatic_adaptation_transform = 'Bradford'
    >>> chromatically_adapted_primaries(p, w_t, w_r,
    ...                                 chromatic_adaptation_transform)
    ... # doctest: +ELLIPSIS
    array([[ 0.6484414...,  0.3308533...],
           [ 0.3211951...,  0.5978443...],
           [ 0.1558932...,  0.0660492...]])
    """

    primaries = np.reshape(primaries, (3, 2))

    XYZ_a = chromatic_adaptation_VonKries(
        xy_to_XYZ(primaries),
        xy_to_XYZ(whitepoint_t),
        xy_to_XYZ(whitepoint_r),
        chromatic_adaptation_transform,
    )

    P_a = XYZ_to_xyY(XYZ_a)[..., 0:2]

    return P_a
示例#12
0
    def test_domain_range_scale_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition domain and range scale support.
        """

        XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
        XYZ_w = np.array([0.95045593, 1.00000000, 1.08905775])
        XYZ_wr = np.array([0.96429568, 1.00000000, 0.82510460])
        XYZ_a = chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr)

        d_r = (('reference', 1), (1, 1), (100, 0.01))
        for scale, factor in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(chromatic_adaptation_VonKries(
                    XYZ * factor, XYZ_w * factor, XYZ_wr * factor),
                                               XYZ_a * factor,
                                               decimal=7)
示例#13
0
    def test_domain_range_scale_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition domain and range scale support.
        """

        XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
        XYZ_w = np.array([0.95045593, 1.00000000, 1.08905775])
        XYZ_wr = np.array([0.96429568, 1.00000000, 0.82510460])
        XYZ_a = chromatic_adaptation_VonKries(XYZ, XYZ_w, XYZ_wr)

        d_r = (('reference', 1), (1, 1), (100, 0.01))
        for scale, factor in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(
                    chromatic_adaptation_VonKries(XYZ * factor, XYZ_w * factor,
                                                  XYZ_wr * factor),
                    XYZ_a * factor,
                    decimal=7)
示例#14
0
def vs_colorimetry_data(
    sd_test: SpectralDistribution,
    sd_reference: SpectralDistribution,
    sds_vs: Dict[str, SpectralDistribution],
    cmfs: MultiSpectralDistributions,
    chromatic_adaptation: Boolean = False,
) -> Tuple[VS_ColorimetryData, ...]:
    """
    Return the *VS test colour samples* colorimetry data.

    Parameters
    ----------
    sd_test
        Test spectral distribution.
    sd_reference
        Reference spectral distribution.
    sds_vs
        *VS test colour samples* spectral distributions.
    cmfs
        Standard observer colour matching functions.
    chromatic_adaptation
        Whether to perform chromatic adaptation.

    Returns
    -------
    :class:`tuple`
        *VS test colour samples* colorimetry data.
    """

    XYZ_t = sd_to_XYZ(sd_test, cmfs)
    XYZ_t /= XYZ_t[1]

    XYZ_r = sd_to_XYZ(sd_reference, cmfs)
    XYZ_r /= XYZ_r[1]
    xy_r = XYZ_to_xy(XYZ_r)

    vs_data = []
    for _key, value in sorted(INDEXES_TO_NAMES_VS.items()):
        sd_vs = sds_vs[value]

        with domain_range_scale("1"):
            XYZ_vs = sd_to_XYZ(sd_vs, cmfs, sd_test)

        if chromatic_adaptation:
            XYZ_vs = chromatic_adaptation_VonKries(XYZ_vs,
                                                   XYZ_t,
                                                   XYZ_r,
                                                   transform="CMCCAT2000")

        Lab_vs = XYZ_to_Lab(XYZ_vs, illuminant=xy_r)
        _L_vs, C_vs, _Hab = Lab_to_LCHab(Lab_vs)

        vs_data.append(VS_ColorimetryData(sd_vs.name, XYZ_vs, Lab_vs, C_vs))

    return tuple(vs_data)
示例#15
0
文件: cqs.py 项目: Nick-Shaw/colour
def vs_colorimetry_data(spd_test,
                        spd_reference,
                        spds_vs,
                        cmfs,
                        chromatic_adaptation=False):
    """
    Returns the *VS test colour samples* colorimetry data.

    Parameters
    ----------
    spd_test : SpectralPowerDistribution
        Test spectral power distribution.
    spd_reference : SpectralPowerDistribution
        Reference spectral power distribution.
    spds_vs : dict
        *VS test colour samples* spectral power distributions.
    cmfs : XYZ_ColourMatchingFunctions
        Standard observer colour matching functions.
    chromatic_adaptation : bool, optional
        Perform chromatic adaptation.

    Returns
    -------
    list
        *VS test colour samples* colorimetry data.
    """

    XYZ_t = spectral_to_XYZ(spd_test, cmfs)
    XYZ_t /= XYZ_t[1]

    XYZ_r = spectral_to_XYZ(spd_reference, cmfs)
    XYZ_r /= XYZ_r[1]
    xy_r = XYZ_to_xy(XYZ_r)

    vs_data = []
    for _key, value in sorted(VS_INDEXES_TO_NAMES.items()):
        spd_vs = spds_vs.get(value)
        XYZ_vs = spectral_to_XYZ(spd_vs, cmfs, spd_test)
        XYZ_vs /= 100

        if chromatic_adaptation:
            XYZ_vs = chromatic_adaptation_VonKries(XYZ_vs,
                                                   XYZ_t,
                                                   XYZ_r,
                                                   transform='CMCCAT2000')

        Lab_vs = XYZ_to_Lab(XYZ_vs, illuminant=xy_r)
        _L_vs, C_vs, _Hab = Lab_to_LCHab(Lab_vs)

        vs_data.append(
            VS_ColorimetryData(spd_vs.name,
                               XYZ_vs,
                               Lab_vs,
                               C_vs))
    return vs_data
示例#16
0
def chromatically_adapted_primaries(primaries,
                                    whitepoint_t,
                                    whitepoint_r,
                                    chromatic_adaptation_transform='CAT02'):
    """
    Chromatically adapts given *primaries* :math:`xy` chromaticity coordinates
    from test `whitepoint_t` to reference `whitepoint_r`.


    Parameters
    ----------
    primaries : array_like, (3, 2)
        Primaries :math:`xy` chromaticity coordinates.
    whitepoint_t : array_like
        Test illuminant / whitepoint :math:`xy` chromaticity coordinates.
    whitepoint_r : array_like
        Reference illuminant / whitepoint :math:`xy` 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.

    Returns
    -------
    ndarray
        Chromatically adapted primaries :math:`xy` chromaticity coordinates.

    Examples
    --------
    >>> p = np.array([0.64, 0.33, 0.30, 0.60, 0.15, 0.06])
    >>> whitepoint_t = np.array([0.31271, 0.32902])
    >>> whitepoint_r = np.array([0.34567, 0.35850])
    >>> chromatic_adaptation_transform = 'Bradford'
    >>> chromatically_adapted_primaries(  # doctest: +ELLIPSIS
    ...     p,
    ...     whitepoint_t,
    ...     whitepoint_r,
    ...     chromatic_adaptation_transform)
    array([[ 0.6484318...,  0.3308548...],
           [ 0.3211603...,  0.5978620...],
           [ 0.1558860...,  0.0660431...]])
    """

    primaries = np.reshape(primaries, (3, 2))

    XYZ_a = chromatic_adaptation_VonKries(
        xy_to_XYZ(primaries),
        xy_to_XYZ(whitepoint_t),
        xy_to_XYZ(whitepoint_r),
        chromatic_adaptation_transform)

    P_a = XYZ_to_xyY(XYZ_a)[..., 0:2]

    return P_a
示例#17
0
def vs_colorimetry_data(sd_test,
                        sd_reference,
                        sds_vs,
                        cmfs,
                        chromatic_adaptation=False):
    """
    Returns the *VS test colour samples* colorimetry data.

    Parameters
    ----------
    sd_test : SpectralDistribution
        Test spectral distribution.
    sd_reference : SpectralDistribution
        Reference spectral distribution.
    sds_vs : dict
        *VS test colour samples* spectral distributions.
    cmfs : XYZ_ColourMatchingFunctions
        Standard observer colour matching functions.
    chromatic_adaptation : bool, optional
        Perform chromatic adaptation.

    Returns
    -------
    list
        *VS test colour samples* colorimetry data.
    """

    XYZ_t = sd_to_XYZ(sd_test, cmfs)
    XYZ_t /= XYZ_t[1]

    XYZ_r = sd_to_XYZ(sd_reference, cmfs)
    XYZ_r /= XYZ_r[1]
    xy_r = XYZ_to_xy(XYZ_r)

    vs_data = []
    for _key, value in sorted(VS_INDEXES_TO_NAMES.items()):
        sd_vs = sds_vs[value]

        with domain_range_scale('1'):
            XYZ_vs = sd_to_XYZ(sd_vs, cmfs, sd_test)

        if chromatic_adaptation:
            XYZ_vs = chromatic_adaptation_VonKries(XYZ_vs,
                                                   XYZ_t,
                                                   XYZ_r,
                                                   transform='CMCCAT2000')

        Lab_vs = XYZ_to_Lab(XYZ_vs, illuminant=xy_r)
        _L_vs, C_vs, _Hab = Lab_to_LCHab(Lab_vs)

        vs_data.append(VS_ColorimetryData(sd_vs.name, XYZ_vs, Lab_vs, C_vs))
    return vs_data
示例#18
0
def chromatically_adapted_primaries(primaries,
                                    whitepoint_t,
                                    whitepoint_r,
                                    chromatic_adaptation_transform='CAT02'):
    """
    Chromatically adapts given *primaries* :math:`xy` chromaticity coordinates
    from test ``whitepoint_t`` to reference ``whitepoint_r``.

    Parameters
    ----------
    primaries : array_like, (3, 2)
        Primaries :math:`xy` chromaticity coordinates.
    whitepoint_t : array_like
        Test illuminant / whitepoint :math:`xy` chromaticity coordinates.
    whitepoint_r : array_like
        Reference illuminant / whitepoint :math:`xy` chromaticity coordinates.
    chromatic_adaptation_transform : unicode, optional
        **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp',
        'Fairchild', 'CMCCAT97', 'CMCCAT2000', 'CAT02 Brill 2008',
        'Bianco 2010', 'Bianco PC 2010'}**,
        *Chromatic adaptation* transform.

    Returns
    -------
    ndarray
        Chromatically adapted primaries :math:`xy` chromaticity coordinates.

    Examples
    --------
    >>> p = np.array([0.64, 0.33, 0.30, 0.60, 0.15, 0.06])
    >>> w_t = np.array([0.31270, 0.32900])
    >>> w_r = np.array([0.34570, 0.35850])
    >>> chromatic_adaptation_transform = 'Bradford'
    >>> chromatically_adapted_primaries(p, w_t, w_r,
    ...                                 chromatic_adaptation_transform)
    ... # doctest: +ELLIPSIS
    array([[ 0.6484414...,  0.3308533...],
           [ 0.3211951...,  0.5978443...],
           [ 0.1558932...,  0.0660492...]])
    """

    primaries = np.reshape(primaries, (3, 2))

    XYZ_a = chromatic_adaptation_VonKries(xy_to_XYZ(primaries),
                                          xy_to_XYZ(whitepoint_t),
                                          xy_to_XYZ(whitepoint_r),
                                          chromatic_adaptation_transform)

    P_a = XYZ_to_xyY(XYZ_a)[..., 0:2]

    return P_a
示例#19
0
def chromatically_adapted_primaries(primaries,
                                    whitepoint_t,
                                    whitepoint_r,
                                    chromatic_adaptation_transform='CAT02'):
    """
    Chromatically adapts given *primaries* :math:`xy` chromaticity coordinates
    from test ``whitepoint_t`` to reference ``whitepoint_r``.

    Parameters
    ----------
    primaries : array_like, (3, 2)
        Primaries :math:`xy` chromaticity coordinates.
    whitepoint_t : array_like
        Test illuminant / whitepoint :math:`xy` chromaticity coordinates.
    whitepoint_r : array_like
        Reference illuminant / whitepoint :math:`xy` 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.

    Returns
    -------
    ndarray
        Chromatically adapted primaries :math:`xy` chromaticity coordinates.

    Examples
    --------
    >>> p = np.array([0.64, 0.33, 0.30, 0.60, 0.15, 0.06])
    >>> w_t = np.array([0.31270, 0.32900])
    >>> w_r = np.array([0.34570, 0.35850])
    >>> chromatic_adaptation_transform = 'Bradford'
    >>> chromatically_adapted_primaries(p, w_t, w_r,
    ...                                 chromatic_adaptation_transform)
    ... # doctest: +ELLIPSIS
    array([[ 0.6484414...,  0.3308533...],
           [ 0.3211951...,  0.5978443...],
           [ 0.1558932...,  0.0660492...]])
    """

    primaries = np.reshape(primaries, (3, 2))

    XYZ_a = chromatic_adaptation_VonKries(
        xy_to_XYZ(primaries), xy_to_XYZ(whitepoint_t), xy_to_XYZ(whitepoint_r),
        chromatic_adaptation_transform)

    P_a = XYZ_to_xyY(XYZ_a)[..., 0:2]

    return P_a
示例#20
0
    def test_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition.
        """

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.20654008, 0.12197225, 0.05136952]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.96429568, 1.00000000, 0.82510460])),
            np.array([0.21638819, 0.12570000, 0.03847494]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.14222010, 0.23042768, 0.10495772]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([1.09846607, 1.00000000, 0.35582280])),
            np.array([0.18673833, 0.23111171, 0.03285972]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07818780, 0.06157201, 0.28099326]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.99144661, 1.00000000, 0.67315942])),
            np.array([0.06385467, 0.05509729, 0.17506386]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.20654008, 0.12197225, 0.05136952]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.96429568, 1.00000000, 0.82510460]),
                transform='XYZ Scaling'),
            np.array([0.20954755, 0.12197225, 0.03891917]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.20654008, 0.12197225, 0.05136952]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.96429568, 1.00000000, 0.82510460]),
                transform='Bradford'),
            np.array([0.21666003, 0.12604777, 0.03855068]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.20654008, 0.12197225, 0.05136952]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.96429568, 1.00000000, 0.82510460]),
                transform='Von Kries'),
            np.array([0.21394049, 0.12262315, 0.03891917]),
            decimal=7)
示例#21
0
    def test_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition.
        """

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07049534, 0.10080000, 0.09558313]),
                np.array([1.09846607, 1.00000000, 0.35582280]),
                np.array([0.95042855, 1.00000000, 1.08890037])),
            np.array([0.08397461, 0.11413219, 0.28625545]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.47097710, 0.34950000, 0.11301649]),
                np.array([0.99092745, 1.00000000, 0.85313273]),
                np.array([1.01679082, 1.00000000, 0.67610122])),
            np.array([0.49253636, 0.35555812, 0.08860435]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.25506814, 0.19150000, 0.08849752]),
                np.array([0.98070597, 1.00000000, 1.18224949]),
                np.array([0.92833635, 1.00000000, 1.03664720])),
            np.array([0.24731314, 0.19137674, 0.07734837]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07049534, 0.10080000, 0.09558313]),
                np.array([1.09846607, 1.00000000, 0.35582280]),
                np.array([0.95042855, 1.00000000, 1.08890037]),
                transform='XYZ Scaling'),
            np.array([0.06099486, 0.10080000, 0.29250657]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07049534, 0.10080000, 0.09558313]),
                np.array([1.09846607, 1.00000000, 0.35582280]),
                np.array([0.95042855, 1.00000000, 1.08890037]),
                transform='Bradford'),
            np.array([0.08540328, 0.11401229, 0.29721491]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07049534, 0.10080000, 0.09558313]),
                np.array([1.09846607, 1.00000000, 0.35582280]),
                np.array([0.95042855, 1.00000000, 1.08890037]),
                transform='Von Kries'),
            np.array([0.08357823, 0.10214289, 0.29250657]),
            decimal=7)
示例#22
0
    def test_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonrkies.chromatic_adaptation_VonKries`
        definition.
        """

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07049534, 0.1008, 0.09558313]),
                np.array([1.09846607, 1., 0.3558228]),
                np.array([0.95042855, 1., 1.08890037])),
            np.array([0.08397461, 0.11413219, 0.28625545]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.4709771, 0.3495, 0.11301649]),
                np.array([0.99092745, 1., 0.85313273]),
                np.array([1.01679082, 1., 0.67610122])),
            np.array([0.49253636, 0.35555812, 0.08860435]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.25506814, 0.1915, 0.08849752]),
                np.array([0.98070597, 1., 1.18224949]),
                np.array([0.92833635, 1., 1.0366472])),
            np.array([0.24731314, 0.19137674, 0.07734837]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07049534, 0.1008, 0.09558313]),
                np.array([1.09846607, 1., 0.3558228]),
                np.array([0.95042855, 1., 1.08890037]),
                transform='XYZ Scaling'),
            np.array([0.06099486, 0.1008, 0.29250657]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07049534, 0.1008, 0.09558313]),
                np.array([1.09846607, 1., 0.3558228]),
                np.array([0.95042855, 1., 1.08890037]),
                transform='Bradford'),
            np.array([0.08540328, 0.11401229, 0.29721491]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07049534, 0.1008, 0.09558313]),
                np.array([1.09846607, 1., 0.3558228]),
                np.array([0.95042855, 1., 1.08890037]),
                transform='Von Kries'),
            np.array([0.08357823, 0.10214289, 0.29250657]),
            decimal=7)
示例#23
0
    def test_chromatic_adaptation_VonKries(self):
        """
        Tests :func:`colour.adaptation.vonkries.chromatic_adaptation_VonKries`
        definition.
        """

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.20654008, 0.12197225, 0.05136952]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.96429568, 1.00000000, 0.82510460])),
            np.array([0.21638819, 0.12570000, 0.03847494]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.14222010, 0.23042768, 0.10495772]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([1.09846607, 1.00000000, 0.35582280])),
            np.array([0.18673833, 0.23111171, 0.03285972]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.07818780, 0.06157201, 0.28099326]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.99144661, 1.00000000, 0.67315942])),
            np.array([0.06385467, 0.05509729, 0.17506386]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.20654008, 0.12197225, 0.05136952]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.96429568, 1.00000000, 0.82510460]),
                transform='XYZ Scaling'),
            np.array([0.20954755, 0.12197225, 0.03891917]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.20654008, 0.12197225, 0.05136952]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.96429568, 1.00000000, 0.82510460]),
                transform='Bradford'),
            np.array([0.21666003, 0.12604777, 0.03855068]),
            decimal=7)

        np.testing.assert_almost_equal(
            chromatic_adaptation_VonKries(
                np.array([0.20654008, 0.12197225, 0.05136952]),
                np.array([0.95045593, 1.00000000, 1.08905775]),
                np.array([0.96429568, 1.00000000, 0.82510460]),
                transform='Von Kries'),
            np.array([0.21394049, 0.12262315, 0.03891917]),
            decimal=7)
示例#24
0
def CCT_factor(reference_data, XYZ_r):

    xy_w = ILLUMINANTS.get('CIE 1931 2 Degree Standard Observer').get('D65')
    XYZ_w = xy_to_XYZ(xy_w)

    Labs = []
    for vs_colorimetry_data_ in reference_data:
        _name, XYZ, _Lab, _C = vs_colorimetry_data_
        XYZ_a = chromatic_adaptation_VonKries(XYZ,
                                              XYZ_r,
                                              XYZ_w,
                                              transform='CMCCAT2000')

        Lab = XYZ_to_Lab(XYZ_a, illuminant=xy_w)
        Labs.append(Lab)

    G_r = gamut_area(Labs) / D65_GAMUT_AREA
    CCT_f = 1 if G_r > 1 else G_r

    return CCT_f
示例#25
0
def CCT_factor(reference_data: Tuple[VS_ColorimetryData, ...],
               XYZ_r: ArrayLike) -> Floating:
    """
    Return the correlated colour temperature factor penalizing lamps with
    extremely low correlated colour temperatures.

    Parameters
    ----------
    reference_data
        Reference colorimetry data.
    XYZ_r
        *CIE XYZ* tristimulus values for reference.

    Returns
    -------
    :class:`numpy.floating`
        Correlated colour temperature factor.
    """

    xy_w = CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"]
    XYZ_w = xy_to_XYZ(xy_w)

    Lab = XYZ_to_Lab(
        chromatic_adaptation_VonKries(
            [colorimetry_data.XYZ for colorimetry_data in reference_data],
            XYZ_r,
            XYZ_w,
            transform="CMCCAT2000",
        ),
        illuminant=xy_w,
    )

    G_r = gamut_area(Lab) / GAMUT_AREA_D65
    CCT_f = 1 if G_r > 1 else G_r

    return CCT_f
示例#26
0
def CCT_factor(reference_data, XYZ_r):
    """
    Returns the correlated colour temperature factor penalizing lamps with
    extremely low correlated colour temperatures.

    Parameters
    ----------
    reference_data : VS_ColorimetryData
        Reference colorimetry data.
    XYZ_r : array_like
        *CIE XYZ* tristimulus values for reference.

    Returns
    -------
    numeric
        Correlated colour temperature factor.
    """

    xy_w = ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
    XYZ_w = xy_to_XYZ(xy_w)

    Labs = []
    for vs_colorimetry_data_ in reference_data:
        _name, XYZ, _Lab, _C = vs_colorimetry_data_
        XYZ_a = chromatic_adaptation_VonKries(XYZ,
                                              XYZ_r,
                                              XYZ_w,
                                              transform='CMCCAT2000')

        Lab = XYZ_to_Lab(XYZ_a, illuminant=xy_w)
        Labs.append(Lab)

    G_r = gamut_area(Labs) / D65_GAMUT_AREA
    CCT_f = 1 if G_r > 1 else G_r

    return CCT_f
示例#27
0
def corresponding_chromaticities_prediction_VonKries(experiment=1,
                                                     transform='CAT02'):
    """
    Returns the corresponding chromaticities prediction for Von Kries
    chromatic adaptation model using given transform.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        Breneman (1987) experiment number.
    transform : unicode, optional
        **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp',
        'Fairchild, 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco',
        'Bianco PC'}**,
        Chromatic adaptation transform.

    Returns
    -------
    tuple
        Corresponding chromaticities prediction.

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_VonKries(2, 'Bradford')
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.20820148430638033, 0.47229226819364528)),
     ((0.449, 0.511), (0.44891022948064191, 0.50716028901449561)),
     ((0.263, 0.505), (0.26435459360846608, 0.49596314494922683)),
     ((0.322, 0.545), (0.33487309037107632, 0.54712207251983425)),
     ((0.316, 0.537), (0.32487581236911361, 0.53905899356457776)),
     ((0.265, 0.553), (0.27331050571632376, 0.55550280647813977)),
     ((0.221, 0.538), (0.22714800102072819, 0.53313179748041983)),
     ((0.135, 0.532), (0.14427303768336433, 0.52268044497913713)),
     ((0.145, 0.472), (0.14987451889726533, 0.45507852741116867)),
     ((0.163, 0.331), (0.15649757464732098, 0.31487959772753954)),
     ((0.176, 0.431), (0.17605936460371163, 0.41037722722471409)),
     ((0.244, 0.349), (0.22598059059292835, 0.34652914678030416))]
    """

    experiment_results = list(BRENEMAN_EXPERIMENTS.get(experiment))

    illuminants = experiment_results.pop(0)
    XYZ_w = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_t))
    XYZ_wr = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_m))
    xy_wr = XYZ_to_xy(XYZ_wr)

    prediction = []
    for result in experiment_results:
        XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t))
        XYZ_2 = chromatic_adaptation_VonKries(XYZ_1, XYZ_w, XYZ_wr, transform)
        uvp = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_wr), xy_wr)
        prediction.append(CorrespondingChromaticitiesPrediction(
            result.name,
            result.uvp_t,
            result.uvp_m,
            uvp))

    return tuple(prediction)
示例#28
0
def corresponding_chromaticities_prediction_VonKries(experiment=1,
                                                     transform='CAT02'):
    """
    Returns the corresponding chromaticities prediction for Von Kries
    chromatic adaptation model using given transform.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        Breneman (1987) experiment number.
    transform : unicode, optional
        **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp',
        'Fairchild', 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco',
        'Bianco PC'}**,
        Chromatic adaptation transform.

    Returns
    -------
    tuple
        Corresponding chromaticities prediction.

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_VonKries(2, 'Bradford')
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.2082014..., 0.4722922...)),
     ((0.449, 0.511), (0.4489102..., 0.5071602...)),
     ((0.263, 0.505), (0.2643545..., 0.4959631...)),
     ((0.322, 0.545), (0.3348730..., 0.5471220...)),
     ((0.316, 0.537), (0.3248758..., 0.5390589...)),
     ((0.265, 0.553), (0.2733105..., 0.5555028...)),
     ((0.221, 0.538), (0.2271480..., 0.5331317...)),
     ((0.135, 0.532), (0.1442730..., 0.5226804...)),
     ((0.145, 0.472), (0.1498745..., 0.4550785...)),
     ((0.163, 0.331), (0.1564975..., 0.3148795...)),
     ((0.176, 0.431), (0.1760593..., 0.4103772...)),
     ((0.244, 0.349), (0.2259805..., 0.3465291...))]
    """

    experiment_results = list(BRENEMAN_EXPERIMENTS.get(experiment))

    illuminants = experiment_results.pop(0)
    XYZ_w = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_t))
    XYZ_wr = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_m))
    xy_wr = XYZ_to_xy(XYZ_wr)

    prediction = []
    for result in experiment_results:
        XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t))
        XYZ_2 = chromatic_adaptation_VonKries(XYZ_1, XYZ_w, XYZ_wr, transform)
        uvp = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_wr), xy_wr)
        prediction.append(CorrespondingChromaticitiesPrediction(
            result.name,
            result.uvp_t,
            result.uvp_m,
            uvp))

    return tuple(prediction)
示例#29
0
def corresponding_chromaticities_prediction_VonKries(experiment=1,
                                                     transform='CAT02'):
    """
    Returns the corresponding chromaticities prediction for *Von Kries*
    chromatic adaptation model using given transform.

    Parameters
    ----------
    experiment : integer or CorrespondingColourDataset, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        *Breneman (1987)* experiment number or
        :class:`colour.CorrespondingColourDataset` class instance.
    transform : unicode, optional
        **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp',
        'Fairchild', 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco',
        'Bianco PC'}**,
        Chromatic adaptation transform.

    Returns
    -------
    tuple
        Corresponding chromaticities prediction.

    References
    ----------
    :cite:`Breneman1987b`, :cite:`Fairchild2013t`

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_VonKries(2, 'Bradford')
    >>> pr = [(p.uv_m, p.uv_p) for p in pr]
    >>> pprint(pr)  # doctest: +ELLIPSIS
    [(array([ 0.207,  0.486]), array([ 0.2082014...,  0.4722922...])),
     (array([ 0.449,  0.511]), array([ 0.4489102...,  0.5071602...])),
     (array([ 0.263,  0.505]), array([ 0.2643545...,  0.4959631...])),
     (array([ 0.322,  0.545]), array([ 0.3348730...,  0.5471220...])),
     (array([ 0.316,  0.537]), array([ 0.3248758...,  0.5390589...])),
     (array([ 0.265,  0.553]), array([ 0.2733105...,  0.5555028...])),
     (array([ 0.221,  0.538]), array([ 0.227148 ...,  0.5331318...)),
     (array([ 0.135,  0.532]), array([ 0.1442730...,  0.5226804...])),
     (array([ 0.145,  0.472]), array([ 0.1498745...,  0.4550785...])),
     (array([ 0.163,  0.331]), array([ 0.1564975...,  0.3148796...])),
     (array([ 0.176,  0.431]), array([ 0.1760593...,  0.4103772...])),
     (array([ 0.244,  0.349]), array([ 0.2259805...,  0.3465291...]))]
    """

    experiment_results = (convert_experiment_results_Breneman1987(experiment)
                          if is_numeric(experiment) else experiment)

    with domain_range_scale(1):
        XYZ_w, XYZ_wr = experiment_results.XYZ_t, experiment_results.XYZ_r
        xy_w, xy_wr = XYZ_to_xy([XYZ_w, XYZ_wr])

        uv_t = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_ct, xy_w), xy_w)
        uv_m = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_cr, xy_wr), xy_wr)

        XYZ_1 = experiment_results.XYZ_ct
        XYZ_2 = chromatic_adaptation_VonKries(XYZ_1, XYZ_w, XYZ_wr, transform)
        uv_p = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_wr), xy_wr)

        return tuple([
            CorrespondingChromaticitiesPrediction(experiment_results.name,
                                                  uv_t[i], uv_m[i], uv_p[i])
            for i in range(len(uv_t))
        ])
示例#30
0
def corresponding_chromaticities_prediction_VonKries(
    experiment: Union[Literal[1, 2, 3, 4, 6, 8, 9, 11, 12],
                      CorrespondingColourDataset] = 1,
    transform: Union[Literal["Bianco 2010", "Bianco PC 2010", "Bradford",
                             "CAT02 Brill 2008", "CAT02", "CAT16",
                             "CMCCAT2000", "CMCCAT97", "Fairchild", "Sharp",
                             "Von Kries", "XYZ Scaling", ], str, ] = "CAT02",
) -> Tuple[CorrespondingChromaticitiesPrediction, ...]:
    """
    Return the corresponding chromaticities prediction for *Von Kries*
    chromatic adaptation model using given transform.

    Parameters
    ----------
    experiment
        *Breneman (1987)* experiment number or
        :class:`colour.CorrespondingColourDataset` class instance.
    transform
        Chromatic adaptation transform.

    Returns
    -------
    :class:`tuple`
        Corresponding chromaticities prediction.

    References
    ----------
    :cite:`Breneman1987b`, :cite:`Fairchild2013t`

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_VonKries(2, 'Bradford')
    >>> pr = [(p.uv_m, p.uv_p) for p in pr]
    >>> pprint(pr)  # doctest: +ELLIPSIS
    [(array([ 0.207,  0.486]), array([ 0.2082014...,  0.4722922...])),
     (array([ 0.449,  0.511]), array([ 0.4489102...,  0.5071602...])),
     (array([ 0.263,  0.505]), array([ 0.2643545...,  0.4959631...])),
     (array([ 0.322,  0.545]), array([ 0.3348730...,  0.5471220...])),
     (array([ 0.316,  0.537]), array([ 0.3248758...,  0.5390589...])),
     (array([ 0.265,  0.553]), array([ 0.2733105...,  0.5555028...])),
     (array([ 0.221,  0.538]), array([ 0.227148 ...,  0.5331318...)),
     (array([ 0.135,  0.532]), array([ 0.1442730...,  0.5226804...])),
     (array([ 0.145,  0.472]), array([ 0.1498745...,  0.4550785...])),
     (array([ 0.163,  0.331]), array([ 0.1564975...,  0.3148796...])),
     (array([ 0.176,  0.431]), array([ 0.1760593...,  0.4103772...])),
     (array([ 0.244,  0.349]), array([ 0.2259805...,  0.3465291...]))]
    """

    experiment_results = (experiment if isinstance(
        experiment, CorrespondingColourDataset) else
                          convert_experiment_results_Breneman1987(experiment))

    with domain_range_scale("1"):
        XYZ_w, XYZ_wr = experiment_results.XYZ_t, experiment_results.XYZ_r
        xy_w, xy_wr = XYZ_to_xy([XYZ_w, XYZ_wr])

        uv_t = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_ct, xy_w), xy_w)
        uv_m = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_cr, xy_wr), xy_wr)

        XYZ_1 = experiment_results.XYZ_ct
        XYZ_2 = chromatic_adaptation_VonKries(XYZ_1, XYZ_w, XYZ_wr, transform)
        uv_p = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_wr), xy_wr)

        return tuple(
            CorrespondingChromaticitiesPrediction(experiment_results.name,
                                                  uv_t[i], uv_m[i], uv_p[i])
            for i in range(len(uv_t)))