예제 #1
0
파일: conversion.py 프로젝트: yixw/colour
def _conversion_path(source, target):
    """
    Returns the conversion path from the source node to the target node in the
    automatic colour conversion graph.

    Parameters
    ----------
    source : unicode
        Source node.
    target : unicode
        Target node.

    Returns
    -------
    list
        Conversion path from the source node to the target node, i.e. a list of
        conversion function callables.

    Examples
    --------
    >>> _conversion_path('cie lab', 'cct')
    ... # doctest: +ELLIPSIS
    [<function Lab_to_XYZ at 0x...>, <function XYZ_to_xy at 0x...>, \
<function xy_to_CCT at 0x...>]
    """
    if is_networkx_installed(raise_exception=True):  # pragma: no cover
        path = nx.shortest_path(CONVERSION_GRAPH, source, target)

        return [
            CONVERSION_GRAPH.get_edge_data(a, b)['conversion_function']
            for a, b in zip(path[:-1], path[1:])
        ]
예제 #2
0
    def test_plot_automatic_colour_conversion_graph(self):
        """
        Tests :func:`colour.plotting.graph.\
plot_automatic_colour_conversion_graph` definition.
        """

        if is_networkx_installed(raise_exception=True):  # pragma: no cover
            return

        plot_automatic_colour_conversion_graph(  # pragma: no cover
            '{0}.png'.format(tempfile.mkstemp()[-1]))
예제 #3
0
    def test_plot_automatic_colour_conversion_graph(self):
        """
        Test :func:`colour.plotting.graph.\
plot_automatic_colour_conversion_graph` definition.
        """

        if not is_networkx_installed() or platform.system() in (
                "Windows",
                "Microsoft",
        ):  # pragma: no cover
            return

        plot_automatic_colour_conversion_graph(  # pragma: no cover
            f"{tempfile.mkstemp()[-1]}.png")
예제 #4
0
    def test_set_float_precision_enforcement(self):
        """
        Tests whether :func:`colour.utilities.array.set_float_precision` effect
        is applied through most of *Colour* public API.
        """

        if not is_networkx_installed():
            return

        from colour.appearance import (CAM_Specification_CAM16,
                                       CAM_Specification_CIECAM02)
        from colour.graph.conversion import (CONVERSION_SPECIFICATIONS_DATA,
                                             convert)

        dtype = np.float32
        set_float_precision(dtype)

        for source, target, _callable in CONVERSION_SPECIFICATIONS_DATA:
            if target in ('Hexadecimal', 'Munsell Colour'):
                continue

            # Spectral distributions are instantiated with float64 data and
            # spectral up-sampling optimization fails.
            if ('Spectral Distribution' in (source, target)
                    or target == 'Complementary Wavelength'
                    or target == 'Dominant Wavelength'):
                continue

            a = np.array([(0.25, 0.5, 0.25), (0.25, 0.5, 0.25)])

            if source == 'CAM16':
                a = CAM_Specification_CAM16(J=0.25, M=0.5, h=0.25)

            if source == 'CIECAM02':
                a = CAM_Specification_CIECAM02(J=0.25, M=0.5, h=0.25)

            if source == 'CMYK':
                a = np.array([(0.25, 0.5, 0.25, 0.5), (0.25, 0.5, 0.25, 0.5)])

            if source == 'Hexadecimal':
                a = np.array(['#FFFFFF', '#FFFFFF'])

            if source == 'Munsell Colour':
                a = ['4.2YR 8.1/5.3', '4.2YR 8.1/5.3']

            if source == 'Wavelength':
                a = 555

            if source.endswith(' xy') or source.endswith(' uv'):
                a = np.array([(0.25, 0.5), (0.25, 0.5)])

            def dtype_getter(x):
                """
                dtype getter callable.
                """

                for specification in ('ATD95', 'CIECAM02', 'CAM16', 'Hunt',
                                      'LLAB', 'Nayatani95', 'RLAB'):
                    if target.endswith(specification):
                        return x[0].dtype

                return x.dtype

            self.assertEqual(dtype_getter(convert(a, source, target)), dtype)
예제 #5
0
파일: conversion.py 프로젝트: yixw/colour
    hdr_CIELab_to_XYZ, hdr_IPT_to_XYZ, sRGB_to_XYZ, uv_to_Luv, uv_to_UCS,
    xyY_to_XYZ, xyY_to_xy, xy_to_Luv_uv, xy_to_UCS_uv, xy_to_XYZ, xy_to_xyY)
from colour.notation import (HEX_to_RGB, RGB_to_HEX, munsell_value,
                             munsell_colour_to_xyY, xyY_to_munsell_colour)
from colour.quality import colour_quality_scale, colour_rendering_index
from colour.appearance import (CAM16_Specification, CAM16_to_XYZ,
                               CIECAM02_Specification, CIECAM02_to_XYZ,
                               XYZ_to_ATD95, XYZ_to_CAM16, XYZ_to_CIECAM02,
                               XYZ_to_Hunt, XYZ_to_LLAB, XYZ_to_Nayatani95,
                               XYZ_to_RLAB)
from colour.temperature import CCT_to_uv, CCT_to_xy, uv_to_CCT, xy_to_CCT
from colour.utilities import (domain_range_scale, filter_kwargs,
                              is_networkx_installed, message_box, tsplit,
                              tstack, usage_warning)

if is_networkx_installed():  # pragma: no cover
    import networkx as nx

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2020 - Colour Developers'
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = '*****@*****.**'
__status__ = 'Production'

__all__ = [
    'ConversionSpecification', 'CIECAM02_to_JMh_CIECAM02',
    'JMh_CIECAM02_to_CIECAM02', 'CAM16_to_JMh_CAM16', 'JMh_CAM16_to_CAM16',
    'XYZ_to_luminance', 'RGB_luminance_to_RGB',
    'CONVERSION_SPECIFICATIONS_DATA', 'CONVERSION_GRAPH_NODE_LABELS',
    'CONVERSION_SPECIFICATIONS', 'CONVERSION_GRAPH',
예제 #6
0
def plot_automatic_colour_conversion_graph(filename, prog='fdp', args=''):
    """
    Plots *Colour* automatic colour conversion graph using
    `Graphviz <https://www.graphviz.org/>`_ and
    `pyraphviz <https://pygraphviz.github.io>`_.

    Parameters
    ----------
    filename : unicode
        Filename to use to save the image.
    prog : unicode, optional
        {'neato', 'dot', 'twopi', 'circo', 'fdp', 'nop'},
        *Graphviz* layout method.
    args : unicode, optional
         Additional arguments for *Graphviz*.

    Returns
    -------
    AGraph
        *Pyraphviz* graph.

    Notes
    -----
    -   This definition does not directly plot the *Colour* automatic colour
        conversion graph but instead write it to an image.

    Examples
    --------
    >>> import tempfile
    >>> import colour
    >>> from colour import read_image
    >>> from colour.plotting import plot_image
    >>> filename = '{0}.png'.format(tempfile.mkstemp()[-1])
    >>> _ = plot_automatic_colour_conversion_graph(filename, 'dot')
    ... # doctest: +SKIP
    >>> plot_image(read_image(filename))  # doctest: +SKIP

    .. image:: ../_static/Plotting_Plot_Colour_Automatic_Conversion_Graph.png
        :align: center
        :alt: plot_automatic_colour_conversion_graph
    """

    if is_networkx_installed(raise_exception=True):  # pragma: no cover
        agraph = nx.nx_agraph.to_agraph(CONVERSION_GRAPH)

        for node in agraph.nodes():
            node.attr.update(label=CONVERSION_GRAPH_NODE_LABELS[node.name])

        agraph.node_attr.update(style='filled',
                                shape='circle',
                                color='#2196F3FF',
                                fillcolor='#2196F370',
                                fontname='Helvetica',
                                fontcolor="#263238")
        agraph.edge_attr.update(color='#26323870')
        for node in ('CIE XYZ', 'RGB', 'Spectral Distribution'):
            agraph.get_node(node.lower()).attr.update(shape='doublecircle',
                                                      color='#673AB7FF',
                                                      fillcolor='#673AB770',
                                                      fontsize=30)
        for node in ('ATD95', 'CAM16', 'CIECAM02', 'Hunt', 'LLAB',
                     'Nayatani95', 'RLAB'):
            agraph.get_node(node.lower()).attr.update(color='#00BCD4FF',
                                                      fillcolor='#00BCD470')

        agraph.draw(filename, prog=prog, args=args)

        return agraph
예제 #7
0
# -*- coding: utf-8 -*-
"""
Automatic Colour Conversion Graph Plotting
==========================================

Defines the automatic colour conversion graph plotting objects:

-   :func:`colour.plotting.plot_automatic_colour_conversion_graph`
"""

from __future__ import division

from colour.graph import CONVERSION_GRAPH, CONVERSION_GRAPH_NODE_LABELS
from colour.utilities import is_networkx_installed

if is_networkx_installed():  # pragma: no cover
    import networkx as nx

__author__ = 'Colour Developers'
__copyright__ = 'Copyright (C) 2013-2019 - Colour Developers'
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause'
__maintainer__ = 'Colour Developers'
__email__ = '*****@*****.**'
__status__ = 'Production'

__all__ = ['plot_automatic_colour_conversion_graph']


def plot_automatic_colour_conversion_graph(filename, prog='fdp', args=''):
    """
    Plots *Colour* automatic colour conversion graph using
예제 #8
0
    def test_set_default_float_dtype_enforcement(self):
        """
        Test whether :func:`colour.utilities.array.set_default_float_dtype`
        effect is applied through most of *Colour* public API.
        """

        if not is_networkx_installed():  # pragma: no cover
            return

        from colour.appearance import (
            CAM_Specification_CAM16,
            CAM_Specification_CIECAM02,
            CAM_Specification_Kim2009,
            CAM_Specification_ZCAM,
        )
        from colour.graph.conversion import (
            CONVERSION_SPECIFICATIONS_DATA,
            convert,
        )

        dtype = np.float32
        set_default_float_dtype(dtype)

        for source, target, _callable in CONVERSION_SPECIFICATIONS_DATA:
            if target in ("Hexadecimal", "Munsell Colour"):
                continue

            # Spectral distributions are instantiated with float64 data and
            # spectral up-sampling optimization fails.
            if ("Spectral Distribution" in (source, target)
                    or target == "Complementary Wavelength"
                    or target == "Dominant Wavelength"):
                continue

            a = np.array([(0.25, 0.5, 0.25), (0.25, 0.5, 0.25)])

            if source == "CAM16":
                a = CAM_Specification_CAM16(J=0.25, M=0.5, h=0.25)

            if source == "CIECAM02":
                a = CAM_Specification_CIECAM02(J=0.25, M=0.5, h=0.25)

            if source == "Kim 2009":
                a = CAM_Specification_Kim2009(J=0.25, M=0.5, h=0.25)

            if source == "ZCAM":
                a = CAM_Specification_ZCAM(J=0.25, M=0.5, h=0.25)

            if source == "CMYK":
                a = np.array([(0.25, 0.5, 0.25, 0.5), (0.25, 0.5, 0.25, 0.5)])

            if source == "Hexadecimal":
                a = np.array(["#FFFFFF", "#FFFFFF"])

            if source == "Munsell Colour":
                a = ["4.2YR 8.1/5.3", "4.2YR 8.1/5.3"]

            if source == "Wavelength":
                a = 555

            if source.endswith(" xy") or source.endswith(" uv"):
                a = np.array([(0.25, 0.5), (0.25, 0.5)])

            def dtype_getter(x):
                """Dtype getter callable."""

                for specification in (
                        "ATD95",
                        "CIECAM02",
                        "CAM16",
                        "Hunt",
                        "Kim 2009",
                        "LLAB",
                        "Nayatani95",
                        "RLAB",
                        "ZCAM",
                ):
                    if target.endswith(specification):
                        return getattr(x, fields(x)[0].name).dtype

                return x.dtype

            self.assertEqual(dtype_getter(convert(a, source, target)), dtype)