예제 #1
0
    def test_describe_conversion_path(self):
        """
        Tests :func:`colour.graph.conversion.describe_conversion_path`
        definition.
        """

        describe_conversion_path('Spectral Distribution', 'sRGB')

        describe_conversion_path('Spectral Distribution', 'sRGB', mode='Long')

        describe_conversion_path(
            'Spectral Distribution',
            'sRGB',
            mode='Extended',
            sd_to_XYZ={
                'illuminant': ILLUMINANTS_SDS['FL2'],
                'return': np.array([0.47924575, 0.31676968, 0.17362725])
            })
예제 #2
0
    def test_describe_conversion_path(self):
        """
        Test :func:`colour.graph.conversion.describe_conversion_path`
        definition.
        """

        describe_conversion_path("Spectral Distribution", "sRGB")

        describe_conversion_path("Spectral Distribution", "sRGB", mode="Long")

        describe_conversion_path(
            "Spectral Distribution",
            "sRGB",
            mode="Extended",
            sd_to_XYZ={
                "illuminant": SDS_ILLUMINANTS["FL2"],
                "return": np.array([0.47924575, 0.31676968, 0.17362725]),
            },
        )
예제 #3
0
def plot_automatic_colour_conversion_graph(
    filename: str,
    prog: Union[Literal["circo", "dot", "fdp", "neato", "nop", "twopi"],
                str] = "fdp",
    args: str = "",
) -> AGraph:  # type: ignore[name-defined]  # noqa
    """
    Plot *Colour* automatic colour conversion graph using
    `Graphviz <https://www.graphviz.org/>`__ and
    `pyraphviz <https://pygraphviz.github.io>`__.

    Parameters
    ----------
    filename
        Filename to use to save the image.
    prog
        *Graphviz* layout method.
    args
         Additional arguments for *Graphviz*.

    Returns
    -------
    :class:`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
    """

    import networkx as nx

    prog = validate_method(
        prog,
        ["circo", "dot", "fdp", "neato", "nop", "twopi"],
        '"{0}" program is invalid, it must be one of {1}!',
    )

    # TODO: Investigate API to trigger the conversion graph build.
    describe_conversion_path("RGB", "RGB", print_callable=lambda x: x)

    agraph = nx.nx_agraph.to_agraph(colour.graph.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",
            "Kim 2009",
            "LLAB",
            "Nayatani95",
            "RLAB",
            "ZCAM",
    ):
        agraph.get_node(node.lower()).attr.update(color="#00BCD4FF",
                                                  fillcolor="#00BCD470")

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

    return agraph
예제 #4
0
파일: graph.py 프로젝트: wenh06/colour
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
    """

    import networkx as nx

    # TODO: Investigate API to trigger the conversion graph build.
    describe_conversion_path('RGB', 'RGB', print_callable=lambda x: x)

    agraph = nx.nx_agraph.to_agraph(colour.graph.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