Beispiel #1
0
    def test_n_dimensional_Luv_to_uv(self):
        """
        Tests :func:`colour.models.cie_luv.Luv_to_uv` definition n-dimensional
        support.
        """

        Luv = np.array([41.52787529, 96.83626054, 17.75210149])
        illuminant = np.array([0.31270, 0.32900])
        uv = Luv_to_uv(Luv, illuminant)

        Luv = np.tile(Luv, (6, 1))
        uv = np.tile(uv, (6, 1))
        np.testing.assert_almost_equal(Luv_to_uv(Luv, illuminant),
                                       uv,
                                       decimal=7)

        illuminant = np.tile(illuminant, (6, 1))
        np.testing.assert_almost_equal(Luv_to_uv(Luv, illuminant),
                                       uv,
                                       decimal=7)

        Luv = np.reshape(Luv, (2, 3, 3))
        illuminant = np.reshape(illuminant, (2, 3, 2))
        uv = np.reshape(uv, (2, 3, 2))
        np.testing.assert_almost_equal(Luv_to_uv(Luv, illuminant),
                                       uv,
                                       decimal=7)
Beispiel #2
0
    def test_n_dimensional_Luv_to_uv(self):
        """
        Tests :func:`colour.models.cie_luv.Luv_to_uv` definition n-dimensions
        support.
        """

        Luv = np.array([37.98562910, -28.80219593, -1.35800706])
        illuminant = np.array([0.34570, 0.35850])
        uv = np.array([0.15085310, 0.48532971])
        np.testing.assert_almost_equal(
            Luv_to_uv(Luv, illuminant),
            uv,
            decimal=7)

        Luv = np.tile(Luv, (6, 1))
        uv = np.tile(uv, (6, 1))
        np.testing.assert_almost_equal(
            Luv_to_uv(Luv, illuminant),
            uv,
            decimal=7)

        illuminant = np.tile(illuminant, (6, 1))
        np.testing.assert_almost_equal(
            Luv_to_uv(Luv, illuminant),
            uv,
            decimal=7)

        Luv = np.reshape(Luv, (2, 3, 3))
        illuminant = np.reshape(illuminant, (2, 3, 2))
        uv = np.reshape(uv, (2, 3, 2))
        np.testing.assert_almost_equal(
            Luv_to_uv(Luv, illuminant),
            uv,
            decimal=7)
Beispiel #3
0
def corresponding_chromaticities_prediction_Fairchild1990(experiment=1,
                                                          **kwargs):
    """
    Returns the corresponding chromaticities prediction for Fairchild (1990)
    chromatic adaptation model.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        Breneman (1987) experiment number.
    \**kwargs : dict, optional
        Keywords arguments.

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

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_Fairchild1990(2)
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.2089528677990308, 0.47240345174230519)),
     ((0.449, 0.511), (0.43756528098582792, 0.51210303139041924)),
     ((0.263, 0.505), (0.26213623665658092, 0.49725385033264224)),
     ((0.322, 0.545), (0.3235312762825191, 0.54756652922585702)),
     ((0.316, 0.537), (0.3151390992740366, 0.53983332031574016)),
     ((0.265, 0.553), (0.26347459238415272, 0.55443357809543037)),
     ((0.221, 0.538), (0.22115956537655593, 0.53244703908294599)),
     ((0.135, 0.532), (0.13969494108553854, 0.52072342107668024)),
     ((0.145, 0.472), (0.1512288710743511, 0.45330415352961834)),
     ((0.163, 0.331), (0.17156913711903982, 0.30262647410866889)),
     ((0.176, 0.431), (0.18257922398137369, 0.40778921192793854)),
     ((0.244, 0.349), (0.24189049501108895, 0.34134012046930529))]
    """

    experiment_results = list(BRENEMAN_EXPERIMENTS.get(experiment))

    illuminants = experiment_results.pop(0)
    XYZ_n = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_t)) * 100
    XYZ_r = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_m)) * 100
    xy_r = XYZ_to_xy(XYZ_r)
    Y_n = BRENEMAN_EXPERIMENTS_PRIMARIES_CHROMATICITIES.get(experiment).Y

    prediction = []
    for result in experiment_results:
        XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t)) * 100
        XYZ_2 = chromatic_adaptation_Fairchild1990(
            XYZ_1, XYZ_n, XYZ_r, Y_n)
        uvp = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_r), xy_r)
        prediction.append(CorrespondingChromaticitiesPrediction(
            result.name,
            result.uvp_t,
            result.uvp_m,
            uvp))

    return tuple(prediction)
Beispiel #4
0
def corresponding_chromaticities_prediction_CMCCAT2000(experiment=1, **kwargs):
    """
    Returns the corresponding chromaticities prediction for CMCCAT2000
    chromatic adaptation model.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        Breneman (1987) experiment number.
    \**kwargs : dict, optional
        Keywords arguments.

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

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_CMCCAT2000(2)
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.20832101929657834, 0.47271680534693694)),
     ((0.449, 0.511), (0.44592707020371486, 0.50777351504395707)),
     ((0.263, 0.505), (0.26402624712986333, 0.4955361681706304)),
     ((0.322, 0.545), (0.33168840090358015, 0.54315801981008516)),
     ((0.316, 0.537), (0.32226245779851387, 0.53576245377085929)),
     ((0.265, 0.553), (0.27107058097430181, 0.5501997842556422)),
     ((0.221, 0.538), (0.22618269421847523, 0.52947407170848704)),
     ((0.135, 0.532), (0.14396930475660724, 0.51909841743126817)),
     ((0.145, 0.472), (0.14948357434418671, 0.45567605010224305)),
     ((0.163, 0.331), (0.15631720730028753, 0.31641514460738623)),
     ((0.176, 0.431), (0.17631993066748047, 0.41275893424542082)),
     ((0.244, 0.349), (0.22876382018951744, 0.3499324084859976))]
    """

    experiment_results = list(BRENEMAN_EXPERIMENTS.get(experiment))

    illuminants = experiment_results.pop(0)
    XYZ_w = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_t)) * 100
    XYZ_wr = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_m)) * 100
    xy_wr = XYZ_to_xy(XYZ_wr)
    L_A1 = L_A2 = BRENEMAN_EXPERIMENTS_PRIMARIES_CHROMATICITIES.get(
        experiment).Y

    prediction = []
    for result in experiment_results:
        XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t)) * 100
        XYZ_2 = chromatic_adaptation_CMCCAT2000(
            XYZ_1, XYZ_w, XYZ_wr, L_A1, L_A2)
        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)
Beispiel #5
0
def corresponding_chromaticities_prediction_Fairchild1990(experiment=1):
    """
    Returns the corresponding chromaticities prediction for *Fairchild (1990)*
    chromatic adaptation model.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        *Breneman (1987)* experiment number.

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

    References
    ----------
    :cite:`Breneman1987b`, :cite:`Fairchild1991a`, :cite:`Fairchild2013s`

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_Fairchild1990(2)
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.2089528..., 0.4724034...)),
     ((0.449, 0.511), (0.4375652..., 0.5121030...)),
     ((0.263, 0.505), (0.2621362..., 0.4972538...)),
     ((0.322, 0.545), (0.3235312..., 0.5475665...)),
     ((0.316, 0.537), (0.3151390..., 0.5398333...)),
     ((0.265, 0.553), (0.2634745..., 0.5544335...)),
     ((0.221, 0.538), (0.2211595..., 0.5324470...)),
     ((0.135, 0.532), (0.1396949..., 0.5207234...)),
     ((0.145, 0.472), (0.1512288..., 0.4533041...)),
     ((0.163, 0.331), (0.1715691..., 0.3026264...)),
     ((0.176, 0.431), (0.1825792..., 0.4077892...)),
     ((0.244, 0.349), (0.2418904..., 0.3413401...))]
    """

    with domain_range_scale(1):
        experiment_results = list(BRENEMAN_EXPERIMENTS[experiment])

        illuminants = experiment_results.pop(0)
        XYZ_n = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_t))
        XYZ_r = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_m))
        xy_r = XYZ_to_xy(XYZ_r)
        Y_n = BRENEMAN_EXPERIMENTS_PRIMARIES_CHROMATICITIES[experiment].Y

        prediction = []
        for result in experiment_results:
            XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t))
            XYZ_2 = chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_n, XYZ_r,
                                                       Y_n)
            uvp = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_r), xy_r)
            prediction.append(
                CorrespondingChromaticitiesPrediction(
                    result.name, result.uvp_t, result.uvp_m, uvp))

        return tuple(prediction)
Beispiel #6
0
def RGB_chromaticity_coordinates_CIE_1976_UCS_chromaticity_diagram_plot(
        RGB,
        colourspace,
        **kwargs):
    """
    Plots given *RGB* colourspace array in *CIE 1976 UCS Chromaticity Diagram*.

    Parameters
    ----------
    RGB : array_like
        *RGB* colourspace array.
    colourspace : RGB_Colourspace
        *RGB* colourspace of the *RGB* array.
    \**kwargs : dict, optional
        Keywords arguments.

    Returns
    -------
    bool
        Definition success.

    Examples
    --------
    >>> RGB = np.random.random((10, 10, 3))
    >>> c = 'Rec. 709'
    >>> RGB_chromaticity_coordinates_CIE_1976_UCS_chromaticity_diagram_plot(
    ...     RGB, c)  # doctest: +SKIP
    True
    """

    settings = {}
    settings.update(kwargs)
    settings.update({'standalone': False})

    settings['colourspaces'] = (
        [colourspace.name] + settings.get('colourspaces', []))

    RGB_colourspaces_CIE_1976_UCS_chromaticity_diagram_plot(**settings)

    alpha_p, colour_p = 0.85, 'black'

    uv = Luv_to_uv(XYZ_to_Luv(RGB_to_XYZ(RGB,
                                         colourspace.whitepoint,
                                         colourspace.whitepoint,
                                         colourspace.RGB_to_XYZ_matrix),
                              colourspace.whitepoint),
                   colourspace.whitepoint)

    pylab.scatter(uv[..., 0],
                  uv[..., 1],
                  alpha=alpha_p / 2,
                  color=colour_p,
                  marker='+')

    settings.update({'standalone': True})

    boundaries(**settings)
    decorate(**settings)

    return display(**settings)
Beispiel #7
0
        def XYZ_to_ij(XYZ):
            """
            Converts given *CIE XYZ* tristimulus values to *ij* chromaticity
            coordinates.
            """

            return Luv_to_uv(XYZ_to_Luv(XYZ))
Beispiel #8
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)
Beispiel #9
0
def chromaticity_diagram_colours_CIE1976UCS(
        samples=4096,
        cmfs='CIE 1931 2 Degree Standard Observer',
        antialiasing=True):
    """
    Plots the *CIE 1976 UCS Chromaticity Diagram* colours.

    Parameters
    ----------
    samples : numeric, optional
        Samples count on one axis.
    cmfs : unicode, optional
        Standard observer colour matching functions used for diagram bounds.
    antialiasing : bool, optional
        Whether to apply anti-aliasing to the image.

    Other Parameters
    ----------------
    \**kwargs : dict, optional
        {:func:`colour.plotting.render`},
        Please refer to the documentation of the previously listed definition.

    Returns
    -------
    Figure
        Current figure or None.

    Examples
    --------
    >>> chromaticity_diagram_colours_CIE1976UCS()  # doctest: +SKIP
    """

    cmfs = get_cmfs(cmfs)

    illuminant = DEFAULT_PLOTTING_ILLUMINANT

    triangulation = Delaunay(Luv_to_uv(XYZ_to_Luv(cmfs.values, illuminant),
                                       illuminant),
                             qhull_options='Qu QJ')
    xx, yy = np.meshgrid(np.linspace(0, 1, samples),
                         np.linspace(1, 0, samples))
    xy = tstack((xx, yy))
    mask = (triangulation.find_simplex(xy) < 0).astype(DEFAULT_FLOAT_DTYPE)
    if antialiasing:
        kernel = np.array([
            [0, 1, 0],
            [1, 2, 1],
            [0, 1, 0],
        ]).astype(DEFAULT_FLOAT_DTYPE)
        kernel /= np.sum(kernel)
        mask = convolve(mask, kernel)

    mask = 1 - mask[:, :, np.newaxis]

    XYZ = xy_to_XYZ(Luv_uv_to_xy(xy))

    RGB = normalise_maximum(XYZ_to_sRGB(XYZ, illuminant), axis=-1)

    return np.dstack([RGB, mask])
Beispiel #10
0
    def test_domain_range_scale_Luv_to_uv(self):
        """
        Tests :func:`colour.models.cie_luv.Luv_to_uv` definition
        domain and range scale support.
        """

        Luv = np.array([41.52787529, 96.83626054, 17.75210149])
        illuminant = np.array([0.31270, 0.32900])
        uv = Luv_to_uv(Luv, illuminant)

        d_r = (('reference', 1), (1, 0.01), (100, 1))
        for scale, factor in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(Luv_to_uv(
                    Luv * factor, illuminant),
                                               uv,
                                               decimal=7)
Beispiel #11
0
def corresponding_chromaticities_prediction_CIE1994(experiment=1):
    """
    Returns the corresponding chromaticities prediction for CIE 1994
    chromatic adaptation model.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        Breneman (1987) experiment number.

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

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_CIE1994(2)
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.2133909..., 0.4939794...)),
     ((0.449, 0.511), (0.4450345..., 0.5120939...)),
     ((0.263, 0.505), (0.2693262..., 0.5083212...)),
     ((0.322, 0.545), (0.3308593..., 0.5443940...)),
     ((0.316, 0.537), (0.3225195..., 0.5377826...)),
     ((0.265, 0.553), (0.2709737..., 0.5513666...)),
     ((0.221, 0.538), (0.2280786..., 0.5351592...)),
     ((0.135, 0.532), (0.1439436..., 0.5303576...)),
     ((0.145, 0.472), (0.1500743..., 0.4842895...)),
     ((0.163, 0.331), (0.1559955..., 0.3772379...)),
     ((0.176, 0.431), (0.1806318..., 0.4518475...)),
     ((0.244, 0.349), (0.2454445..., 0.4018004...))]
    """

    experiment_results = list(BRENEMAN_EXPERIMENTS.get(experiment))

    illuminants = experiment_results.pop(0)
    xy_o1 = Luv_uv_to_xy(illuminants.uvp_t)
    xy_o2 = Luv_uv_to_xy(illuminants.uvp_m)
    # :math:`Y_o` is set to an arbitrary value in domain [18, 100].
    Y_o = 18
    E_o1 = E_o2 = BRENEMAN_EXPERIMENTS_PRIMARIES_CHROMATICITIES.get(
        experiment).Y

    prediction = []
    for result in experiment_results:
        XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t)) * 100
        XYZ_2 = chromatic_adaptation_CIE1994(XYZ_1, xy_o1, xy_o2, Y_o, E_o1,
                                             E_o2)
        uvp = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_o2), xy_o2)
        prediction.append(
            CorrespondingChromaticitiesPrediction(result.name, result.uvp_t,
                                                  result.uvp_m, uvp))

    return tuple(prediction)
Beispiel #12
0
def corresponding_chromaticities_prediction_CMCCAT2000(experiment=1):
    """
    Returns the corresponding chromaticities prediction for CMCCAT2000
    chromatic adaptation model.

    Parameters
    ----------
    experiment : integer, optional
        {1, 2, 3, 4, 6, 8, 9, 11, 12}
        Breneman (1987) experiment number.

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

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_CMCCAT2000(2)
    >>> pr = [(p.uvp_m, p.uvp_p) for p in pr]
    >>> pprint(pr)  # doctest: +SKIP
    [((0.207, 0.486), (0.2083210..., 0.4727168...)),
     ((0.449, 0.511), (0.4459270..., 0.5077735...)),
     ((0.263, 0.505), (0.2640262..., 0.4955361...)),
     ((0.322, 0.545), (0.3316884..., 0.5431580...)),
     ((0.316, 0.537), (0.3222624..., 0.5357624...)),
     ((0.265, 0.553), (0.2710705..., 0.5501997...)),
     ((0.221, 0.538), (0.2261826..., 0.5294740...)),
     ((0.135, 0.532), (0.1439693..., 0.5190984...)),
     ((0.145, 0.472), (0.1494835..., 0.4556760...)),
     ((0.163, 0.331), (0.1563172..., 0.3164151...)),
     ((0.176, 0.431), (0.1763199..., 0.4127589...)),
     ((0.244, 0.349), (0.2287638..., 0.3499324...))]
    """

    experiment_results = list(BRENEMAN_EXPERIMENTS.get(experiment))

    illuminants = experiment_results.pop(0)
    XYZ_w = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_t)) * 100
    XYZ_wr = xy_to_XYZ(Luv_uv_to_xy(illuminants.uvp_m)) * 100
    xy_wr = XYZ_to_xy(XYZ_wr)
    L_A1 = L_A2 = BRENEMAN_EXPERIMENTS_PRIMARIES_CHROMATICITIES.get(
        experiment).Y

    prediction = []
    for result in experiment_results:
        XYZ_1 = xy_to_XYZ(Luv_uv_to_xy(result.uvp_t)) * 100
        XYZ_2 = chromatic_adaptation_CMCCAT2000(XYZ_1, XYZ_w, XYZ_wr, L_A1,
                                                L_A2)
        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)
Beispiel #13
0
    def test_nan_Luv_to_uv(self):
        """
        Tests :func:`colour.models.cie_luv.Luv_to_uv` 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:
            Luv = np.array(case)
            illuminant = np.array(case[0:2])
            Luv_to_uv(Luv, illuminant)
Beispiel #14
0
    def test_Luv_to_uv(self):
        """
        Tests :func:`colour.models.cie_luv.Luv_to_uv` definition.
        """

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([100, -11.27488915, -29.36041662])),
            (0.20048615433157738, 0.4654903849082484),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([100, 331.44911128, 72.55258319])),
            (0.46412000081619281, 0.54388500014670993),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([100, -36.17788915, -111.00091702])),
            (0.18133000048542355, 0.40268999998517152),
            decimal=7)

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([100, -97.02442861, -158.08546907]),
            (0.44757, 0.40745)), (0.18133000048503745, 0.40268999998707306),
                                       decimal=7)

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([100, -37.95520989, -92.29247371]),
            (1 / 3, 1 / 3)), (0.18133000048947367, 0.40268999998016192),
                                       decimal=7)

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([100, -21.44928374, -85.33481874]),
            (0.31271, 0.32902)), (0.1813300004870092, 0.4026899999798475),
                                       decimal=7)
Beispiel #15
0
    def test_Luv_to_uv(self):
        """
        Tests :func:`colour.models.cie_luv.Luv_to_uv` definition.
        """

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -28.79229446, -1.35581950])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([65.70971880, 87.21709531, 27.01490816])),
            np.array([0.31125983, 0.51970032]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([50.86223896, 60.52359443, 13.14030896])),
            np.array([0.30069387, 0.50794847]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -51.90523525, -19.24118281]),
                      np.array([0.44757, 0.40745])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -23.19754103, 8.39360940]),
                      np.array([0.31271, 0.32902])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -34.23840374, -7.09461715]),
                      np.array([0.37208, 0.37529])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -34.23840374, -7.09461715]),
                      np.array([0.37208, 0.37529, 0.10080])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)
Beispiel #16
0
    def test_Luv_to_uv(self):
        """
        Tests :func:`colour.models.cie_luv.Luv_to_uv` definition.
        """

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -28.80219593, -1.35800706])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([65.70971880, 87.19996716, 27.01112399])),
            np.array([0.31125983, 0.51970032]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([50.86223896, 60.51033649, 13.13737985])),
            np.array([0.30069387, 0.50794847]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -51.90523525, -19.24118281]),
                      np.array([0.44757, 0.40745])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -23.19781615, 8.39962073]),
                      np.array([0.31270, 0.32900])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -34.23840374, -7.09461715]),
                      np.array([0.37208, 0.37529])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)

        np.testing.assert_almost_equal(
            Luv_to_uv(np.array([37.98562910, -34.23840374, -7.09461715]),
                      np.array([0.37208, 0.37529, 0.10080])),
            np.array([0.15085310, 0.48532971]),
            decimal=7)
Beispiel #17
0
    def test_Luv_to_uv(self):
        """
        Tests :func:`colour.models.cie_luv.Luv_to_uv` definition.
        """

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([41.52787529, 96.83626054, 17.75210149])),
                                       np.array([0.37720213, 0.50120264]),
                                       decimal=7)

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([55.11636304, -37.59308176, 44.13768458])),
                                       np.array([0.14536327, 0.52992069]),
                                       decimal=7)

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([29.80565520, -10.96316802, -65.06751860])),
                                       np.array([0.16953603, 0.30039234]),
                                       decimal=7)

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([41.52787529, 65.45180940, -12.46626977]),
            np.array([0.44757, 0.40745])),
                                       np.array([0.37720213, 0.50120264]),
                                       decimal=7)

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([41.52787529, 90.70925962, 7.08455273]),
            np.array([0.34570, 0.35850])),
                                       np.array([0.37720213, 0.50120264]),
                                       decimal=7)

        np.testing.assert_almost_equal(Luv_to_uv(
            np.array([41.52787529, 90.70925962, 7.08455273]),
            np.array([0.34570, 0.35850, 1.00000])),
                                       np.array([0.37720213, 0.50120264]),
                                       decimal=7)
Beispiel #18
0
def CIE_1976_UCS_chromaticity_diagram_colours_plot(
        surface=1,
        samples=4096,
        cmfs='CIE 1931 2 Degree Standard Observer',
        **kwargs):
    """
    Plots the *CIE 1976 UCS Chromaticity Diagram* colours.

    Parameters
    ----------
    surface : numeric, optional
        Generated markers surface.
    samples : numeric, optional
        Samples count on one axis.
    cmfs : unicode, optional
        Standard observer colour matching functions used for diagram bounds.

    Other Parameters
    ----------------
    \**kwargs : dict, optional
        {:func:`boundaries`, :func:`canvas`, :func:`decorate`,
        :func:`display`},
        Please refer to the documentation of the previously listed definitions.

    Returns
    -------
    Figure
        Current figure or None.

    Examples
    --------
    >>> CIE_1976_UCS_chromaticity_diagram_colours_plot()  # doctest: +SKIP
    """

    settings = {'figure_size': (64, 64)}
    settings.update(kwargs)

    canvas(**settings)

    cmfs = get_cmfs(cmfs)

    illuminant = DEFAULT_PLOTTING_ILLUMINANT

    triangulation = Delaunay(Luv_to_uv(XYZ_to_Luv(cmfs.values, illuminant),
                                       illuminant),
                             qhull_options='QJ Qf')
    xx, yy = np.meshgrid(np.linspace(0, 1, samples),
                         np.linspace(0, 1, samples))
    xy = tstack((xx, yy))
    xy = xy[triangulation.find_simplex(xy) > 0]

    XYZ = xy_to_XYZ(Luv_uv_to_xy(xy))

    RGB = normalise_maximum(XYZ_to_sRGB(XYZ, illuminant), axis=-1)

    x_dot, y_dot = tsplit(xy)

    pylab.scatter(x_dot, y_dot, color=RGB, s=surface)

    settings.update({
        'x_ticker': False,
        'y_ticker': False,
        'bounding_box': (0, 1, 0, 1)
    })
    settings.update(kwargs)

    ax = matplotlib.pyplot.gca()
    matplotlib.pyplot.setp(ax, frame_on=False)

    boundaries(**settings)
    decorate(**settings)

    return display(**settings)
Beispiel #19
0
def plot_spectral_locus(cmfs='CIE 1931 2 Degree Standard Observer',
                        spectral_locus_colours=None,
                        spectral_locus_labels=None,
                        method='CIE 1931',
                        **kwargs):
    """
    Plots the *Spectral Locus* according to given method.

    Parameters
    ----------
    cmfs : unicode, optional
        Standard observer colour matching functions defining the
        *Spectral Locus*.
    spectral_locus_colours : array_like or unicode, optional
        *Spectral Locus* colours, if ``spectral_locus_colours`` is set to
        *RGB*, the colours will be computed according to the corresponding
        chromaticity coordinates.
    spectral_locus_labels : array_like, optional
        Array of wavelength labels used to customise which labels will be drawn
        around the spectral locus. Passing an empty array will result in no
        wavelength labels being drawn.
    method : unicode, optional
        **{'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}**,
        *Chromaticity Diagram* method.

    Other Parameters
    ----------------
    \\**kwargs : dict, optional
        {:func:`colour.plotting.artist`, :func:`colour.plotting.render`},
        Please refer to the documentation of the previously listed definitions.

    Returns
    -------
    tuple
        Current figure and axes.

    Examples
    --------
    >>> plot_spectral_locus(spectral_locus_colours='RGB')  # doctest: +SKIP

    .. image:: ../_static/Plotting_Plot_Spectral_Locus.png
        :align: center
        :alt: plot_spectral_locus
    """

    if spectral_locus_colours is None:
        spectral_locus_colours = COLOUR_STYLE_CONSTANTS.colour.dark

    settings = {'uniform': True}
    settings.update(kwargs)

    figure, axes = artist(**settings)

    method = method.upper()

    cmfs = first_item(filter_cmfs(cmfs).values())

    illuminant = COLOUR_STYLE_CONSTANTS.colour.colourspace.whitepoint

    wavelengths = cmfs.wavelengths
    equal_energy = np.array([1 / 3] * 2)

    if method == 'CIE 1931':
        ij = XYZ_to_xy(cmfs.values, illuminant)
        labels = ((390, 460, 470, 480, 490, 500, 510, 520, 540, 560, 580, 600,
                   620, 700)
                  if spectral_locus_labels is None else spectral_locus_labels)
    elif method == 'CIE 1960 UCS':
        ij = UCS_to_uv(XYZ_to_UCS(cmfs.values))
        labels = ((420, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540,
                   550, 560, 570, 580, 590, 600, 610, 620, 630, 645, 680)
                  if spectral_locus_labels is None else spectral_locus_labels)
    elif method == 'CIE 1976 UCS':
        ij = Luv_to_uv(XYZ_to_Luv(cmfs.values, illuminant), illuminant)
        labels = ((420, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540,
                   550, 560, 570, 580, 590, 600, 610, 620, 630, 645, 680)
                  if spectral_locus_labels is None else spectral_locus_labels)
    else:
        raise ValueError(
            'Invalid method: "{0}", must be one of '
            '{\'CIE 1931\', \'CIE 1960 UCS\', \'CIE 1976 UCS\'}'.format(
                method))

    pl_ij = tstack([
        np.linspace(ij[0][0], ij[-1][0], 20),
        np.linspace(ij[0][1], ij[-1][1], 20)
    ]).reshape(-1, 1, 2)
    sl_ij = np.copy(ij).reshape(-1, 1, 2)

    if spectral_locus_colours.upper() == 'RGB':
        spectral_locus_colours = normalise_maximum(
            XYZ_to_plotting_colourspace(cmfs.values), axis=-1)

        if method == 'CIE 1931':
            XYZ = xy_to_XYZ(pl_ij)
        elif method == 'CIE 1960 UCS':
            XYZ = xy_to_XYZ(UCS_uv_to_xy(pl_ij))
        elif method == 'CIE 1976 UCS':
            XYZ = xy_to_XYZ(Luv_uv_to_xy(pl_ij))
        purple_line_colours = normalise_maximum(
            XYZ_to_plotting_colourspace(XYZ.reshape(-1, 3)), axis=-1)
    else:
        purple_line_colours = spectral_locus_colours

    for slp_ij, slp_colours in ((pl_ij, purple_line_colours),
                                (sl_ij, spectral_locus_colours)):
        line_collection = LineCollection(
            np.concatenate([slp_ij[:-1], slp_ij[1:]], axis=1),
            colors=slp_colours)
        axes.add_collection(line_collection)

    wl_ij = dict(tuple(zip(wavelengths, ij)))
    for label in labels:
        i, j = wl_ij[label]

        index = bisect.bisect(wavelengths, label)
        left = wavelengths[index - 1] if index >= 0 else wavelengths[index]
        right = (wavelengths[index]
                 if index < len(wavelengths) else wavelengths[-1])

        dx = wl_ij[right][0] - wl_ij[left][0]
        dy = wl_ij[right][1] - wl_ij[left][1]

        ij = np.array([i, j])
        direction = np.array([-dy, dx])

        normal = (np.array([-dy, dx]) if np.dot(
            normalise_vector(ij - equal_energy), normalise_vector(direction)) >
                  0 else np.array([dy, -dx]))
        normal = normalise_vector(normal) / 30

        label_colour = (spectral_locus_colours
                        if is_string(spectral_locus_colours) else
                        spectral_locus_colours[index])
        axes.plot(
            (i, i + normal[0] * 0.75), (j, j + normal[1] * 0.75),
            color=label_colour)

        axes.plot(i, j, 'o', color=label_colour)

        axes.text(
            i + normal[0],
            j + normal[1],
            label,
            clip_on=True,
            ha='left' if normal[0] >= 0 else 'right',
            va='center',
            fontdict={'size': 'small'})

    settings = {'axes': axes}
    settings.update(kwargs)

    return render(**kwargs)
Beispiel #20
0
def plot_chromaticity_diagram_colours(
        samples=256,
        diagram_opacity=1.0,
        diagram_clipping_path=None,
        cmfs='CIE 1931 2 Degree Standard Observer',
        method='CIE 1931',
        **kwargs):
    """
    Plots the *Chromaticity Diagram* colours according to given method.

    Parameters
    ----------
    samples : numeric, optional
        Samples count on one axis.
    diagram_opacity : numeric, optional
        Opacity of the *Chromaticity Diagram* colours.
    diagram_clipping_path : array_like, optional
        Path of points used to clip the *Chromaticity Diagram* colours.
    cmfs : unicode, optional
        Standard observer colour matching functions used for
        *Chromaticity Diagram* bounds.
    method : unicode, optional
        **{'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}**,
        *Chromaticity Diagram* method.

    Other Parameters
    ----------------
    \\**kwargs : dict, optional
        {:func:`colour.plotting.artist`, :func:`colour.plotting.render`},
        Please refer to the documentation of the previously listed definitions.

    Returns
    -------
    tuple
        Current figure and axes.

    Examples
    --------
    >>> plot_chromaticity_diagram_colours()  # doctest: +SKIP

    .. image:: ../_static/Plotting_Plot_Chromaticity_Diagram_Colours.png
        :align: center
        :alt: plot_chromaticity_diagram_colours
    """

    settings = {'uniform': True}
    settings.update(kwargs)

    figure, axes = artist(**settings)

    method = method.upper()

    cmfs = first_item(filter_cmfs(cmfs).values())

    illuminant = COLOUR_STYLE_CONSTANTS.colour.colourspace.whitepoint

    ii, jj = np.meshgrid(
        np.linspace(0, 1, samples), np.linspace(1, 0, samples))
    ij = tstack([ii, jj])

    if method == 'CIE 1931':
        XYZ = xy_to_XYZ(ij)
        spectral_locus = XYZ_to_xy(cmfs.values, illuminant)
    elif method == 'CIE 1960 UCS':
        XYZ = xy_to_XYZ(UCS_uv_to_xy(ij))
        spectral_locus = UCS_to_uv(XYZ_to_UCS(cmfs.values))
    elif method == 'CIE 1976 UCS':
        XYZ = xy_to_XYZ(Luv_uv_to_xy(ij))
        spectral_locus = Luv_to_uv(
            XYZ_to_Luv(cmfs.values, illuminant), illuminant)
    else:
        raise ValueError(
            'Invalid method: "{0}", must be one of '
            '{\'CIE 1931\', \'CIE 1960 UCS\', \'CIE 1976 UCS\'}'.format(
                method))

    RGB = normalise_maximum(
        XYZ_to_plotting_colourspace(XYZ, illuminant), axis=-1)

    polygon = Polygon(
        spectral_locus
        if diagram_clipping_path is None else diagram_clipping_path,
        facecolor='none',
        edgecolor='none')
    axes.add_patch(polygon)
    # Preventing bounding box related issues as per
    # https://github.com/matplotlib/matplotlib/issues/10529
    image = axes.imshow(
        RGB,
        interpolation='bilinear',
        extent=(0, 1, 0, 1),
        clip_path=None,
        alpha=diagram_opacity)
    image.set_clip_path(polygon)

    settings = {'axes': axes}
    settings.update(kwargs)

    return render(**kwargs)
Beispiel #21
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))
        ])
Beispiel #22
0
def corresponding_chromaticities_prediction_CMCCAT2000(experiment=1):
    """
    Returns the corresponding chromaticities prediction for *CMCCAT2000*
    chromatic adaptation model.

    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.

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

    References
    ----------
    :cite:`Breneman1987b`, :cite:`Li2002a`, :cite:`Westland2012k`

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_CMCCAT2000(2)
    >>> pr = [(p.uv_m, p.uv_p) for p in pr]
    >>> pprint(pr)  # doctest: +ELLIPSIS
    [(array([ 0.207,  0.486]), array([ 0.2083210...,  0.4727168...])),
     (array([ 0.449,  0.511]), array([ 0.4459270...,  0.5077735...])),
     (array([ 0.263,  0.505]), array([ 0.2640262...,  0.4955361...])),
     (array([ 0.322,  0.545]), array([ 0.3316884...,  0.5431580...])),
     (array([ 0.316,  0.537]), array([ 0.3222624...,  0.5357624...])),
     (array([ 0.265,  0.553]), array([ 0.2710705...,  0.5501997...])),
     (array([ 0.221,  0.538]), array([ 0.2261826...,  0.5294740...])),
     (array([ 0.135,  0.532]), array([ 0.1439693...,  0.5190984...])),
     (array([ 0.145,  0.472]), array([ 0.1494835...,  0.4556760...])),
     (array([ 0.163,  0.331]), array([ 0.1563172...,  0.3164151...])),
     (array([ 0.176,  0.431]), array([ 0.1763199...,  0.4127589...])),
     (array([ 0.244,  0.349]), array([ 0.2287638...,  0.3499324...]))]
    """

    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)

        L_A1 = experiment_results.Y_t
        L_A2 = experiment_results.Y_r

        XYZ_1 = experiment_results.XYZ_ct
        XYZ_2 = chromatic_adaptation_CMCCAT2000(XYZ_1, XYZ_w, XYZ_wr, L_A1,
                                                L_A2)
        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))
        ])
Beispiel #23
0
def corresponding_chromaticities_prediction_CIE1994(experiment=1):
    """
    Returns the corresponding chromaticities prediction for *CIE 1994*
    chromatic adaptation model.

    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. Returns
    -------
    tuple
        Corresponding chromaticities prediction.

    References
    ----------
    :cite:`Breneman1987b`, :cite:`CIETC1-321994b`

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_CIE1994(2)
    >>> pr = [(p.uv_m, p.uv_p) for p in pr]
    >>> pprint(pr)  # doctest: +ELLIPSIS
    [(array([ 0.207,  0.486]), array([ 0.2273130...,  0.5267609...])),
     (array([ 0.449,  0.511]), array([ 0.4612181...,  0.5191849...])),
     (array([ 0.263,  0.505]), array([ 0.2872404...,  0.5306938...])),
     (array([ 0.322,  0.545]), array([ 0.3489822...,  0.5454398...])),
     (array([ 0.316,  0.537]), array([ 0.3371612...,  0.5421567...])),
     (array([ 0.265,  0.553]), array([ 0.2889416...,  0.5534074...])),
     (array([ 0.221,  0.538]), array([ 0.2412195...,  0.5464301...])),
     (array([ 0.135,  0.532]), array([ 0.1530344...,  0.5488239...])),
     (array([ 0.145,  0.472]), array([ 0.1568709...,  0.5258835...])),
     (array([ 0.163,  0.331]), array([ 0.1499762...,  0.4401747...])),
     (array([ 0.176,  0.431]), array([ 0.1876711...,  0.5039627...])),
     (array([ 0.244,  0.349]), array([ 0.2560012...,  0.4546263...]))]
    """

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

    with domain_range_scale(1):
        XYZ_t, XYZ_r = experiment_results.XYZ_t, experiment_results.XYZ_r
        xy_o1, xy_o2 = XYZ_to_xy([XYZ_t, XYZ_r])

        uv_t = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_ct, xy_o1), xy_o1)
        uv_m = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_cr, xy_o2), xy_o2)

        Y_r = experiment_results.B_r
        E_o1, E_o2 = experiment_results.Y_t, experiment_results.Y_r

        XYZ_1 = experiment_results.XYZ_ct
        XYZ_2 = chromatic_adaptation_CIE1994(XYZ_1, xy_o1, xy_o2, Y_r, E_o1,
                                             E_o2)
        uv_p = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_o2), xy_o2)

        return tuple([
            CorrespondingChromaticitiesPrediction(experiment_results.name,
                                                  uv_t[i], uv_m[i], uv_p[i])
            for i in range(len(uv_t))
        ])
Beispiel #24
0
def corresponding_chromaticities_prediction_Fairchild1990(experiment=1):
    """
    Returns the corresponding chromaticities prediction for *Fairchild (1990)*
    chromatic adaptation model.

    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.

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

    References
    ----------
    :cite:`Breneman1987b`, :cite:`Fairchild1991a`, :cite:`Fairchild2013s`

    Examples
    --------
    >>> from pprint import pprint
    >>> pr = corresponding_chromaticities_prediction_Fairchild1990(2)
    >>> pr = [(p.uv_m, p.uv_p) for p in pr]
    >>> pprint(pr)  # doctest: +ELLIPSIS
    [(array([ 0.207,  0.486]), array([ 0.2089528...,  0.4724034...])),
     (array([ 0.449,  0.511]), array([ 0.4375652...,  0.5121030...])),
     (array([ 0.263,  0.505]), array([ 0.2621362...,  0.4972538...])),
     (array([ 0.322,  0.545]), array([ 0.3235312...,  0.5475665...])),
     (array([ 0.316,  0.537]), array([ 0.3151391...,  0.5398333...])),
     (array([ 0.265,  0.553]), array([ 0.2634745...,  0.5544335...])),
     (array([ 0.221,  0.538]), array([ 0.2211595...,  0.5324470...])),
     (array([ 0.135,  0.532]), array([ 0.1396949...,  0.5207234...])),
     (array([ 0.145,  0.472]), array([ 0.1512288...,  0.4533041...])),
     (array([ 0.163,  0.331]), array([ 0.1715691...,  0.3026264...])),
     (array([ 0.176,  0.431]), array([ 0.1825792...,  0.4077892...])),
     (array([ 0.244,  0.349]), array([ 0.2418905...,  0.3413401...]))]
    """

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

    with domain_range_scale(1):
        XYZ_t, XYZ_r = experiment_results.XYZ_t, experiment_results.XYZ_r
        xy_t, xy_r = XYZ_to_xy([XYZ_t, XYZ_r])

        uv_t = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_ct, xy_t), xy_t)
        uv_m = Luv_to_uv(XYZ_to_Luv(experiment_results.XYZ_cr, xy_r), xy_r)

        Y_n = experiment_results.Y_t

        XYZ_1 = experiment_results.XYZ_ct
        XYZ_2 = chromatic_adaptation_Fairchild1990(XYZ_1, XYZ_t, XYZ_r, Y_n)
        uv_p = Luv_to_uv(XYZ_to_Luv(XYZ_2, xy_r), xy_r)

        return tuple([
            CorrespondingChromaticitiesPrediction(experiment_results.name,
                                                  uv_t[i], uv_m[i], uv_p[i])
            for i in range(len(uv_t))
        ])
Beispiel #25
0
def XYZ_to_colourspace_model(XYZ, illuminant, model, **kwargs):
    """
    Converts from *CIE XYZ* tristimulus values to given colourspace model.

    Parameters
    ----------
    XYZ : array_like
        *CIE XYZ* tristimulus values.
    illuminant : array_like
        *CIE XYZ* tristimulus values *illuminant* *xy* chromaticity
        coordinates.
    model : unicode
        **{'CIE XYZ', 'CIE xyY', 'CIE xy', 'CIE Lab', 'CIE LCHab', 'CIE Luv',
        'CIE Luv uv', 'CIE LCHuv', 'CIE UCS', 'CIE UCS uv', 'CIE UVW',
        'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'IPT', 'JzAzBz, 'OSA UCS',
        'hdr-CIELAB', 'hdr-IPT'}**,
        Colourspace model to convert the *CIE XYZ* tristimulus values to.

    Other Parameters
    ----------------
    \\**kwargs : dict, optional
        Keywords arguments.

    Returns
    -------
    ndarray
        Colourspace model values.

    Examples
    --------
    >>> import numpy as np
    >>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
    >>> W = np.array([0.31270, 0.32900])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE XYZ')
    array([ 0.2065400...,  0.1219722...,  0.0513695...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE xyY')
    array([ 0.5436955...,  0.3210794...,  0.1219722...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE xy')
    array([ 0.5436955...,  0.3210794...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE Lab')
    array([ 0.4152787...,  0.5263858...,  0.2692317...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE LCHab')
    array([ 0.4152787...,  0.5912425...,  0.0752458...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE Luv')
    array([ 0.4152787...,  0.9683626...,  0.1775210...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE Luv uv')
    array([ 0.3772021...,  0.5012026...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE LCHuv')
    array([ 0.4152787...,  0.9844997...,  0.0288560...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE UCS uv')
    array([ 0.3772021...,  0.3341350...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE UVW')
    array([ 0.9455035...,  0.1155536...,  0.4054757...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'DIN 99')
    array([ 0.5322822...,  0.2841634...,  0.0389839...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'Hunter Lab')
    array([ 0.3492452...,  0.4703302...,  0.1439330...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'Hunter Rdab')
    array([ 0.1219722...,  0.5709032...,  0.1747109...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'IPT')
    array([ 0.3842619...,  0.3848730...,  0.1888683...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'JzAzBz')
    array([ 0.0053504...,  0.0092430...,  0.0052600...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'OSA UCS')
    array([-0.0300499...,  0.0299713..., -0.0966784...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'hdr-CIELAB')
    array([ 0.5187002...,  0.6047633...,  0.3214551...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'hdr-IPT')
    array([ 0.4839376...,  0.4244990...,  0.2201954...])
    """

    with domain_range_scale(1):
        values = None
        if model == 'CIE XYZ':
            values = XYZ
        elif model == 'CIE xyY':
            values = XYZ_to_xyY(XYZ, illuminant)
        elif model == 'CIE xy':
            values = XYZ_to_xy(XYZ, illuminant)
        elif model == 'CIE Lab':
            values = XYZ_to_Lab(XYZ, illuminant)
        elif model == 'CIE LCHab':
            values = Lab_to_LCHab(XYZ_to_Lab(XYZ, illuminant))
        elif model == 'CIE Luv':
            values = XYZ_to_Luv(XYZ, illuminant)
        elif model == 'CIE Luv uv':
            values = Luv_to_uv(XYZ_to_Luv(XYZ, illuminant), illuminant)
        elif model == 'CIE LCHuv':
            values = Luv_to_LCHuv(XYZ_to_Luv(XYZ, illuminant))
        elif model == 'CIE UCS':
            values = XYZ_to_UCS(XYZ)
        elif model == 'CIE UCS uv':
            values = UCS_to_uv(XYZ_to_UCS(XYZ))
        elif model == 'CIE UVW':
            values = XYZ_to_UVW(XYZ, illuminant)
        elif model == 'DIN 99':
            values = Lab_to_DIN99(XYZ_to_Lab(XYZ, illuminant))
        elif model == 'Hunter Lab':
            values = XYZ_to_Hunter_Lab(XYZ, xy_to_XYZ(illuminant))
        elif model == 'Hunter Rdab':
            values = XYZ_to_Hunter_Rdab(XYZ, xy_to_XYZ(illuminant))
        elif model == 'IPT':
            values = XYZ_to_IPT(XYZ)
        elif model == 'JzAzBz':
            values = XYZ_to_JzAzBz(XYZ)
        elif model == 'OSA UCS':
            values = XYZ_to_OSA_UCS(XYZ)
        elif model == 'hdr-CIELAB':
            values = XYZ_to_hdr_CIELab(XYZ, illuminant, **kwargs)
        elif model == 'hdr-IPT':
            values = XYZ_to_hdr_IPT(XYZ, **kwargs)

        if values is None:
            raise ValueError(
                '"{0}" not found in colourspace models: "{1}".'.format(
                    model, ', '.join(COLOURSPACE_MODELS)))

        return values
Beispiel #26
0
def plot_chromaticity_diagram_colours(
        samples=256,
        diagram_opacity=1.0,
        diagram_clipping_path=None,
        cmfs='CIE 1931 2 Degree Standard Observer',
        method='CIE 1931',
        **kwargs):
    """
    Plots the *Chromaticity Diagram* colours according to given method.

    Parameters
    ----------
    samples : numeric, optional
        Samples count on one axis.
    diagram_opacity : numeric, optional
        Opacity of the *Chromaticity Diagram* colours.
    diagram_clipping_path : array_like, optional
        Path of points used to clip the *Chromaticity Diagram* colours.
    cmfs : unicode or XYZ_ColourMatchingFunctions, optional
        Standard observer colour matching functions used for computing the
        spectral locus boundaries. ``cmfs`` can be of any type or form
        supported by the :func:`colour.plotting.filter_cmfs` definition.
    method : unicode, optional
        **{'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}**,
        *Chromaticity Diagram* method.

    Other Parameters
    ----------------
    \\**kwargs : dict, optional
        {:func:`colour.plotting.artist`, :func:`colour.plotting.render`},
        Please refer to the documentation of the previously listed definitions.

    Returns
    -------
    tuple
        Current figure and axes.

    Examples
    --------
    >>> plot_chromaticity_diagram_colours()  # doctest: +ELLIPSIS
    (<Figure size ... with 1 Axes>, <...AxesSubplot...>)

    .. image:: ../_static/Plotting_Plot_Chromaticity_Diagram_Colours.png
        :align: center
        :alt: plot_chromaticity_diagram_colours
    """

    settings = {'uniform': True}
    settings.update(kwargs)

    _figure, axes = artist(**settings)

    method = method.upper()

    cmfs = first_item(filter_cmfs(cmfs).values())

    illuminant = CONSTANTS_COLOUR_STYLE.colour.colourspace.whitepoint

    ii, jj = np.meshgrid(np.linspace(0, 1, samples),
                         np.linspace(1, 0, samples))
    ij = tstack([ii, jj])

    # NOTE: Various values in the grid have potential to generate
    # zero-divisions, they could be avoided by perturbing the grid, e.g. adding
    # a small epsilon. It was decided instead to disable warnings.
    with suppress_warnings(python_warnings=True):
        if method == 'CIE 1931':
            XYZ = xy_to_XYZ(ij)
            spectral_locus = XYZ_to_xy(cmfs.values, illuminant)
        elif method == 'CIE 1960 UCS':
            XYZ = xy_to_XYZ(UCS_uv_to_xy(ij))
            spectral_locus = UCS_to_uv(XYZ_to_UCS(cmfs.values))
        elif method == 'CIE 1976 UCS':
            XYZ = xy_to_XYZ(Luv_uv_to_xy(ij))
            spectral_locus = Luv_to_uv(XYZ_to_Luv(cmfs.values, illuminant),
                                       illuminant)
        else:
            raise ValueError(
                'Invalid method: "{0}", must be one of '
                '[\'CIE 1931\', \'CIE 1960 UCS\', \'CIE 1976 UCS\']'.format(
                    method))

    RGB = normalise_maximum(XYZ_to_plotting_colourspace(XYZ, illuminant),
                            axis=-1)

    polygon = Polygon(spectral_locus if diagram_clipping_path is None else
                      diagram_clipping_path,
                      facecolor='none',
                      edgecolor='none')
    axes.add_patch(polygon)
    # Preventing bounding box related issues as per
    # https://github.com/matplotlib/matplotlib/issues/10529
    image = axes.imshow(RGB,
                        interpolation='bilinear',
                        extent=(0, 1, 0, 1),
                        clip_path=None,
                        alpha=diagram_opacity)
    image.set_clip_path(polygon)

    settings = {'axes': axes}
    settings.update(kwargs)

    return render(**kwargs)
Beispiel #27
0
def _full_report(spec, source, date, manufacturer, model, notes=None):
    figure = plt.figure(figsize=(8.27, 11.69))

    figure.text(0.5,
                0.97,
                'TM-30-18 Color Rendition Report',
                ha='center',
                size='x-large')

    figure.text(0.250,
                0.935,
                'Source: ',
                ha='right',
                size='large',
                weight='bold')
    figure.text(0.250, 0.935, source, size='large')
    figure.text(0.250,
                0.907,
                'Date: ',
                ha='right',
                size='large',
                weight='bold')
    figure.text(0.250, 0.907, date, size='large')

    figure.text(0.700,
                0.935,
                'Manufacturer: ',
                ha='right',
                size='large',
                weight='bold')
    figure.text(0.700, 0.935, manufacturer, ha='left', size='large')
    figure.text(0.700,
                0.907,
                'Model: ',
                ha='right',
                size='large',
                weight='bold')
    figure.text(0.700, 0.907, model, size='large')

    ax = figure.add_axes((0.057, 0.767, 0.385, 0.112))
    plot_spectra_TM_30_18(ax, spec)

    ax = figure.add_axes((0.036, 0.385, 0.428, 0.333))
    plot_color_vector_graphic(ax, spec)

    ax = figure.add_axes((0.554, 0.736, 0.409, 0.141))
    plot_local_chroma_shifts(ax, spec)

    ax = figure.add_axes((0.554, 0.576, 0.409, 0.141))
    plot_local_hue_shifts(ax, spec)

    ax = figure.add_axes((0.554, 0.401, 0.409, 0.141))
    plot_local_color_fidelities(ax, spec)

    ax = figure.add_axes((0.094, 0.195, 0.870, 0.161))
    plot_colour_fidelity_indexes(ax, spec)

    if notes:
        figure.text(0.139,
                    0.114,
                    'Notes: ',
                    ha='right',
                    size='large',
                    weight='bold')
        figure.text(0.139, 0.114, notes, size='large')

    XYZ = sd_to_XYZ(spec.sd_test)
    xy = XYZ_to_xy(XYZ)
    Luv = XYZ_to_Luv(XYZ, xy)
    up, vp = Luv_to_uv(Luv, xy)

    figure.text(0.712, 0.111, '$x$  {:.4f}'.format(xy[0]), ha='center')
    figure.text(0.712, 0.091, '$y$  {:.4f}'.format(xy[1]), ha='center')
    figure.text(0.712, 0.071, '$u\'$  {:.4f}'.format(up), ha='center')
    figure.text(0.712, 0.051, '$v\'$  {:.4f}'.format(vp), ha='center')

    rect = plt.Rectangle((0.814, 0.035),
                         0.144,
                         0.096,
                         color='black',
                         fill=False)
    figure.add_artist(rect)

    CRI_spec = colour_rendering_index(spec.sd_test, additional_data=True)

    figure.text(0.886, 0.111, 'CIE 13.31-1995', ha='center')
    figure.text(0.886, 0.091, '(CRI)', ha='center')
    figure.text(0.886,
                0.071,
                '$R_a$  {:.0f}'.format(CRI_spec.Q_a),
                ha='center',
                weight='bold')
    figure.text(0.886,
                0.051,
                '$R_9$  {:.0f}'.format(CRI_spec.Q_as[8].Q_a),
                ha='center',
                weight='bold')

    figure.text(0.500,
                0.010,
                'Created with Colour ' + colour.__version__,
                ha='center')
Beispiel #28
0
def CIE_1976_UCS_chromaticity_diagram_plot(
        cmfs='CIE 1931 2 Degree Standard Observer',
        show_diagram_colours=True,
        **kwargs):
    """
    Plots the *CIE 1976 UCS Chromaticity Diagram*.

    Parameters
    ----------
    cmfs : unicode, optional
        Standard observer colour matching functions used for diagram bounds.
    show_diagram_colours : bool, optional
        Whether to display the chromaticity diagram background colours.

    Other Parameters
    ----------------
    \**kwargs : dict, optional
        {:func:`boundaries`, :func:`canvas`, :func:`decorate`,
        :func:`display`},
        Please refer to the documentation of the previously listed definitions.

    Returns
    -------
    Figure
        Current figure or None.

    Examples
    --------
    >>> CIE_1976_UCS_chromaticity_diagram_plot()  # doctest: +SKIP
    """

    settings = {'figure_size': (DEFAULT_FIGURE_WIDTH, DEFAULT_FIGURE_WIDTH)}
    settings.update(kwargs)

    canvas(**settings)

    cmfs = get_cmfs(cmfs)

    illuminant = DEFAULT_PLOTTING_ILLUMINANT

    if show_diagram_colours:
        image = matplotlib.image.imread(
            os.path.join(
                PLOTTING_RESOURCES_DIRECTORY,
                'CIE_1976_UCS_Chromaticity_Diagram_{0}.png'.format(
                    cmfs.name.replace(' ', '_'))))
        pylab.imshow(image, interpolation=None, extent=(0, 1, 0, 1))

    labels = (420, 430, 440, 450, 460, 470, 480, 490, 500, 510, 520, 530, 540,
              550, 560, 570, 580, 590, 600, 610, 620, 630, 640, 680)

    wavelengths = cmfs.wavelengths
    equal_energy = np.array([1 / 3] * 2)

    uv = Luv_to_uv(XYZ_to_Luv(cmfs.values, illuminant), illuminant)

    wavelengths_chromaticity_coordinates = dict(zip(wavelengths, uv))

    pylab.plot(uv[..., 0], uv[..., 1], color='black', linewidth=2)
    pylab.plot((uv[-1][0], uv[0][0]), (uv[-1][1], uv[0][1]),
               color='black',
               linewidth=2)

    for label in labels:
        u, v = wavelengths_chromaticity_coordinates[label]
        pylab.plot(u, v, 'o', color='black', linewidth=2)

        index = bisect.bisect(wavelengths, label)
        left = wavelengths[index - 1] if index >= 0 else wavelengths[index]
        right = (wavelengths[index]
                 if index < len(wavelengths) else wavelengths[-1])

        dx = (wavelengths_chromaticity_coordinates[right][0] -
              wavelengths_chromaticity_coordinates[left][0])
        dy = (wavelengths_chromaticity_coordinates[right][1] -
              wavelengths_chromaticity_coordinates[left][1])

        uv = np.array([u, v])
        direction = np.array([-dy, dx])

        normal = (np.array([
            -dy, dx
        ]) if np.dot(normalise_vector(uv - equal_energy),
                     normalise_vector(direction)) > 0 else np.array([dy, -dx]))
        normal = normalise_vector(normal)
        normal /= 25

        pylab.plot((u, u + normal[0] * 0.75), (v, v + normal[1] * 0.75),
                   color='black',
                   linewidth=1.5)
        pylab.text(u + normal[0],
                   v + normal[1],
                   label,
                   color='black',
                   clip_on=True,
                   ha='left' if normal[0] >= 0 else 'right',
                   va='center',
                   fontdict={'size': 'small'})

    ticks = np.arange(-10, 10, 0.1)

    pylab.xticks(ticks)
    pylab.yticks(ticks)

    settings.update({
        'title':
        'CIE 1976 UCS Chromaticity Diagram - {0}'.format(cmfs.title),
        'x_label':
        'CIE u\'',
        'y_label':
        'CIE v\'',
        'grid':
        True,
        'bounding_box': (0, 1, 0, 1)
    })
    settings.update(kwargs)

    boundaries(**settings)
    decorate(**settings)

    return display(**settings)
Beispiel #29
0
def spds_CIE_1976_UCS_chromaticity_diagram_plot(
        spds,
        cmfs='CIE 1931 2 Degree Standard Observer',
        annotate=True,
        **kwargs):
    """
    Plots given spectral power distribution chromaticity coordinates into the
    *CIE 1976 UCS Chromaticity Diagram*.

    Parameters
    ----------
    spds : array_like, optional
        Spectral power distributions to plot.
    cmfs : unicode, optional
        Standard observer colour matching functions used for diagram bounds.
    annotate : bool
        Should resulting chromaticity coordinates annotated with their
        respective spectral power distribution names.

    Other Parameters
    ----------------
    \**kwargs : dict, optional
        {:func:`boundaries`, :func:`canvas`, :func:`decorate`,
        :func:`display`},
        Please refer to the documentation of the previously listed definitions.
    show_diagram_colours : bool, optional
        {:func:`CIE_1976_UCS_chromaticity_diagram_plot`},
        Whether to display the chromaticity diagram background colours.

    Returns
    -------
    Figure
        Current figure or None.

    Examples
    --------
    >>> from colour import ILLUMINANTS_RELATIVE_SPDS
    >>> A = ILLUMINANTS_RELATIVE_SPDS['A']
    >>> D65 = ILLUMINANTS_RELATIVE_SPDS['D65']
    >>> spds_CIE_1976_UCS_chromaticity_diagram_plot([A, D65])  # doctest: +SKIP
    """

    settings = {}
    settings.update(kwargs)
    settings.update({'standalone': False})

    CIE_1976_UCS_chromaticity_diagram_plot(cmfs=cmfs, **settings)

    for spd in spds:
        XYZ = spectral_to_XYZ(spd) / 100
        uv = Luv_to_uv(XYZ_to_Luv(XYZ))

        pylab.plot(uv[0], uv[1], 'o', color='white')

        if spd.name is not None and annotate:
            pylab.annotate(spd.name,
                           xy=uv,
                           xytext=(50, 30),
                           color='black',
                           textcoords='offset points',
                           arrowprops=dict(arrowstyle='->',
                                           connectionstyle='arc3, rad=0.2'))

    settings.update({
        'x_tighten': True,
        'y_tighten': True,
        'limits': (-0.1, 0.7, -0.1, 0.7),
        'standalone': True
    })
    settings.update(kwargs)

    boundaries(**settings)
    decorate(**settings)

    return display(**settings)
Beispiel #30
0
def XYZ_to_colourspace_model(XYZ, illuminant, model, **kwargs):
    """
    Converts from *CIE XYZ* tristimulus values to given colourspace model.

    Parameters
    ----------
    XYZ : array_like
        *CIE XYZ* tristimulus values.
    illuminant : array_like
        Reference *illuminant* *CIE xy* chromaticity coordinates or *CIE xyY*
        colourspace array.
    model : unicode
        **{'CIE XYZ', 'CIE xyY', 'CIE xy', 'CIE Lab', 'CIE LCHab', 'CIE Luv',
        'CIE Luv uv', 'CIE LCHuv', 'CIE UCS', 'CIE UCS uv', 'CIE UVW',
        'DIN 99', 'Hunter Lab', 'Hunter Rdab', 'IPT', 'JzAzBz, 'OSA UCS',
        'hdr-CIELAB', 'hdr-IPT'}**,
        Colourspace model to convert the *CIE XYZ* tristimulus values to.

    Other Parameters
    ----------------
    \\**kwargs : dict, optional
        Keywords arguments.

    Returns
    -------
    ndarray
        Colourspace model values.

    Warnings
    --------
    This definition is is deprecated and will be removed in a future release.
    :func:`colour.convert` definition should be used instead.

    Examples
    --------
    >>> import numpy as np
    >>> XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
    >>> W = np.array([0.31270, 0.32900])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE XYZ')
    array([ 0.2065400...,  0.1219722...,  0.0513695...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE xyY')
    array([ 0.5436955...,  0.3210794...,  0.1219722...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE xy')
    array([ 0.5436955...,  0.3210794...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE Lab')
    array([ 0.4152787...,  0.5263858...,  0.2692317...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE LCHab')
    array([ 0.4152787...,  0.5912425...,  0.0752458...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE Luv')
    array([ 0.4152787...,  0.9683626...,  0.1775210...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE Luv uv')
    array([ 0.3772021...,  0.5012026...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE LCHuv')
    array([ 0.4152787...,  0.9844997...,  0.0288560...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE UCS')
    array([ 0.1376933...,  0.1219722...,  0.1053731...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE UCS uv')
    array([ 0.3772021...,  0.3341350...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'CIE UVW')
    array([ 0.9455035...,  0.1155536...,  0.4054757...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'DIN 99')
    array([ 0.5322822...,  0.2841634...,  0.0389839...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'Hunter Lab')
    array([ 0.3492452...,  0.4703302...,  0.1439330...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'Hunter Rdab')
    array([ 0.1219722...,  0.5709032...,  0.1747109...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'IPT')
    array([ 0.3842619...,  0.3848730...,  0.1888683...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'JzAzBz')
    array([ 0.0053504...,  0.0092430...,  0.0052600...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'OSA UCS')
    array([-0.0300499...,  0.0299713..., -0.0966784...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'hdr-CIELAB')
    array([ 0.5187002...,  0.6047633...,  0.3214551...])
    >>> XYZ_to_colourspace_model(  # doctest: +ELLIPSIS
    ... XYZ, W, 'hdr-IPT')
    array([ 0.4839376...,  0.4244990...,  0.2201954...])
    >>> try:
    ...     XYZ_to_colourspace_model(XYZ, W, 'Undefined')
    ... except ValueError as error:
    ...     print(error)
    "Undefined" not found in colourspace models: "CIE XYZ, CIE xyY, CIE Lab, \
CIE LCHab, CIE Luv, CIE Luv uv, CIE LCHuv, CIE UCS, CIE UCS uv, CIE UVW, \
DIN 99, Hunter Lab, Hunter Rdab, IPT, JzAzBz, OSA UCS, hdr-CIELAB, hdr-IPT".
    """

    from colour.models import (
        Lab_to_DIN99, Lab_to_LCHab, Luv_to_LCHuv, Luv_to_uv, UCS_to_uv,
        XYZ_to_IPT, XYZ_to_Hunter_Lab, XYZ_to_Hunter_Rdab, XYZ_to_Lab,
        XYZ_to_Luv, XYZ_to_OSA_UCS, XYZ_to_UCS, XYZ_to_UVW, XYZ_to_hdr_CIELab,
        XYZ_to_hdr_IPT, XYZ_to_JzAzBz, XYZ_to_xy, XYZ_to_xyY, xy_to_XYZ)

    with domain_range_scale(1):
        values = None
        if model == 'CIE XYZ':
            values = XYZ
        elif model == 'CIE xyY':
            values = XYZ_to_xyY(XYZ, illuminant)
        elif model == 'CIE xy':
            values = XYZ_to_xy(XYZ, illuminant)
        elif model == 'CIE Lab':
            values = XYZ_to_Lab(XYZ, illuminant)
        elif model == 'CIE LCHab':
            values = Lab_to_LCHab(XYZ_to_Lab(XYZ, illuminant))
        elif model == 'CIE Luv':
            values = XYZ_to_Luv(XYZ, illuminant)
        elif model == 'CIE Luv uv':
            values = Luv_to_uv(XYZ_to_Luv(XYZ, illuminant), illuminant)
        elif model == 'CIE LCHuv':
            values = Luv_to_LCHuv(XYZ_to_Luv(XYZ, illuminant))
        elif model == 'CIE UCS':
            values = XYZ_to_UCS(XYZ)
        elif model == 'CIE UCS uv':
            values = UCS_to_uv(XYZ_to_UCS(XYZ))
        elif model == 'CIE UVW':
            values = XYZ_to_UVW(XYZ, illuminant)
        elif model == 'DIN 99':
            values = Lab_to_DIN99(XYZ_to_Lab(XYZ, illuminant))
        elif model == 'Hunter Lab':
            values = XYZ_to_Hunter_Lab(XYZ, xy_to_XYZ(illuminant))
        elif model == 'Hunter Rdab':
            values = XYZ_to_Hunter_Rdab(XYZ, xy_to_XYZ(illuminant))
        elif model == 'IPT':
            values = XYZ_to_IPT(XYZ)
        elif model == 'JzAzBz':
            values = XYZ_to_JzAzBz(XYZ)
        elif model == 'OSA UCS':
            values = XYZ_to_OSA_UCS(XYZ)
        elif model == 'hdr-CIELAB':
            values = XYZ_to_hdr_CIELab(XYZ, illuminant, **kwargs)
        elif model == 'hdr-IPT':
            values = XYZ_to_hdr_IPT(XYZ, **kwargs)

        if values is None:
            raise ValueError(
                '"{0}" not found in colourspace models: "{1}".'.format(
                    model, ', '.join(COLOURSPACE_MODELS)))

        return values