Exemplo n.º 1
0
    def test_RGB_to_RGB(self):
        """
        Tests :func:`colour.models.rgb.RGB_to_RGB` definition.
        """

        aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1')
        sRGB_colourspace = RGB_COLOURSPACES.get('sRGB')

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.35521588, 0.41000000, 0.24177934]),
                       aces_2065_1_colourspace, sRGB_colourspace),
            np.array([0.33658567, 0.44096335, 0.21509975]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.33658567, 0.44096335, 0.21509975]),
                       sRGB_colourspace, aces_2065_1_colourspace),
            np.array([0.35521588, 0.41000000, 0.24177934]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.35521588, 0.41000000, 0.24177934]),
                       aces_2065_1_colourspace, sRGB_colourspace, 'Bradford'),
            np.array([0.33704409, 0.44133521, 0.21429761]),
            decimal=7)
Exemplo n.º 2
0
    def test_n_dimensional_RGB_to_RGB(self):
        """
        Tests :func:`colour.models.rgb.RGB_to_RGB` definition n-dimensions
        support.
        """

        aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1')
        sRGB_colourspace = RGB_COLOURSPACES.get('sRGB')
        RGB_i = np.array([0.35521588, 0.41000000, 0.24177934])
        RGB_o = np.array([0.33658567, 0.44096335, 0.21509975])
        np.testing.assert_almost_equal(RGB_to_RGB(RGB_i,
                                                  aces_2065_1_colourspace,
                                                  sRGB_colourspace),
                                       RGB_o,
                                       decimal=7)

        RGB_i = np.tile(RGB_i, (6, 1))
        RGB_o = np.tile(RGB_o, (6, 1))
        np.testing.assert_almost_equal(RGB_to_RGB(RGB_i,
                                                  aces_2065_1_colourspace,
                                                  sRGB_colourspace),
                                       RGB_o,
                                       decimal=7)

        RGB_i = np.reshape(RGB_i, (2, 3, 3))
        RGB_o = np.reshape(RGB_o, (2, 3, 3))
        np.testing.assert_almost_equal(RGB_to_RGB(RGB_i,
                                                  aces_2065_1_colourspace,
                                                  sRGB_colourspace),
                                       RGB_o,
                                       decimal=7)
Exemplo n.º 3
0
    def test_n_dimensional_RGB_to_RGB(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_to_RGB` definition
        n-dimensional support.
        """

        aces_2065_1_colourspace = RGB_COLOURSPACES['ACES2065-1']
        sRGB_colourspace = RGB_COLOURSPACES['sRGB']
        RGB_i = np.array([0.21931722, 0.06950287, 0.04694832])
        RGB_o = RGB_to_RGB(RGB_i, aces_2065_1_colourspace, sRGB_colourspace)

        RGB_i = np.tile(RGB_i, (6, 1))
        RGB_o = np.tile(RGB_o, (6, 1))
        np.testing.assert_almost_equal(RGB_to_RGB(RGB_i,
                                                  aces_2065_1_colourspace,
                                                  sRGB_colourspace),
                                       RGB_o,
                                       decimal=7)

        RGB_i = np.reshape(RGB_i, (2, 3, 3))
        RGB_o = np.reshape(RGB_o, (2, 3, 3))
        np.testing.assert_almost_equal(RGB_to_RGB(RGB_i,
                                                  aces_2065_1_colourspace,
                                                  sRGB_colourspace),
                                       RGB_o,
                                       decimal=7)
Exemplo n.º 4
0
    def test_RGB_to_RGB(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_to_RGB` definition.
        """

        aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1')
        sRGB_colourspace = RGB_COLOURSPACES.get('sRGB')

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.35521588, 0.41000000, 0.24177934]),
                       aces_2065_1_colourspace,
                       sRGB_colourspace),
            np.array([0.33653829, 0.44097338, 0.21512063]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.33653829, 0.44097338, 0.21512063]),
                       sRGB_colourspace,
                       aces_2065_1_colourspace),
            np.array([0.35521588, 0.41000000, 0.24177934]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.35521588, 0.41000000, 0.24177934]),
                       aces_2065_1_colourspace,
                       sRGB_colourspace,
                       'Bradford'),
            np.array([0.33699675, 0.44134608, 0.21431681]),
            decimal=7)
Exemplo n.º 5
0
    def test_RGB_to_RGB(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_to_RGB` definition.
        """

        aces_2065_1_colourspace = RGB_COLOURSPACES['ACES2065-1']
        sRGB_colourspace = RGB_COLOURSPACES['sRGB']

        np.testing.assert_almost_equal(
            RGB_to_RGB(
                np.array([0.35521588, 0.41000000, 0.24177934]),
                aces_2065_1_colourspace, sRGB_colourspace),
            np.array([0.33654049, 0.44099674, 0.21512677]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(
                np.array([0.33653829, 0.44097338, 0.21512063]),
                sRGB_colourspace, aces_2065_1_colourspace),
            np.array([0.35521588, 0.41000000, 0.24177934]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(
                np.array([0.35521588, 0.41000000, 0.24177934]),
                aces_2065_1_colourspace, sRGB_colourspace, 'Bradford'),
            np.array([0.33699893, 0.44136948, 0.21432296]),
            decimal=7)

        aces_cg_colourspace = RGB_COLOURSPACES['ACEScg']
        aces_cc_colourspace = RGB_COLOURSPACES['ACEScc']

        np.testing.assert_almost_equal(
            RGB_to_RGB(
                np.array([0.35521588, 0.41000000, 0.24177934]),
                aces_cg_colourspace,
                aces_cc_colourspace,
                apply_decoding_cctf=True,
                apply_encoding_cctf=True),
            np.array([0.46956438, 0.48137533, 0.43788601]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(
                np.array([0.46956438, 0.48137533, 0.43788601]),
                aces_cc_colourspace,
                sRGB_colourspace,
                apply_decoding_cctf=True,
                apply_encoding_cctf=True),
            np.array([0.60983062, 0.67896356, 0.50435764]),
            decimal=7)
Exemplo n.º 6
0
    def test_domain_range_scale_XYZ_to_RGB(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_to_RGB` definition
        domain and range scale support.
        """

        aces_2065_1_colourspace = RGB_COLOURSPACES['ACES2065-1']
        sRGB_colourspace = RGB_COLOURSPACES['sRGB']
        RGB_i = np.array([0.21931722, 0.06950287, 0.04694832])
        RGB_o = RGB_to_RGB(RGB_i, aces_2065_1_colourspace, sRGB_colourspace)

        d_r = (('reference', 1), (1, 1), (100, 100))
        for scale, factor in d_r:
            with domain_range_scale(scale):
                np.testing.assert_almost_equal(RGB_to_RGB(
                    RGB_i * factor, aces_2065_1_colourspace, sRGB_colourspace),
                                               RGB_o * factor,
                                               decimal=7)
Exemplo n.º 7
0
    def test_RGB_to_RGB(self):
        """
        Tests :func:`colour.models.rgb.rgb_colourspace.RGB_to_RGB` definition.
        """

        aces_2065_1_colourspace = RGB_COLOURSPACES['ACES2065-1']
        sRGB_colourspace = RGB_COLOURSPACES['sRGB']

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.21931722, 0.06950287, 0.04694832]),
                       aces_2065_1_colourspace, sRGB_colourspace),
            np.array([0.45595289, 0.03040780, 0.04087313]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.45595571, 0.03039702, 0.04087245]),
                       sRGB_colourspace, aces_2065_1_colourspace),
            np.array([0.21931722, 0.06950287, 0.04694832]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.21931722, 0.06950287, 0.04694832]),
                       aces_2065_1_colourspace, sRGB_colourspace, 'Bradford'),
            np.array([0.45597530, 0.03030054, 0.04086041]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.21931722, 0.06950287, 0.04694832]),
                       aces_2065_1_colourspace, sRGB_colourspace, None),
            np.array([0.46484236, 0.02963459, 0.03667609]),
            decimal=7)

        aces_cg_colourspace = RGB_COLOURSPACES['ACEScg']
        aces_cc_colourspace = RGB_COLOURSPACES['ACEScc']

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.21931722, 0.06950287, 0.04694832]),
                       aces_cg_colourspace,
                       aces_cc_colourspace,
                       apply_cctf_decoding=True,
                       apply_cctf_encoding=True),
            np.array([0.42985679, 0.33522924, 0.30292336]),
            decimal=7)

        np.testing.assert_almost_equal(
            RGB_to_RGB(np.array([0.46956438, 0.48137533, 0.43788601]),
                       aces_cc_colourspace,
                       sRGB_colourspace,
                       apply_cctf_decoding=True,
                       apply_cctf_encoding=True),
            np.array([0.60983062, 0.67896356, 0.50435764]),
            decimal=7)

        np.testing.assert_equal(
            RGB_to_RGB(np.array([0.21931722, 0.06950287, 0.04694832]),
                       aces_2065_1_colourspace,
                       RGB_COLOURSPACES['ProPhoto RGB'],
                       apply_cctf_encoding=True,
                       out_int=True), np.array([120, 59, 46]))
Exemplo n.º 8
0
    def test_nan_RGB_to_RGB(self):
        """
        Tests :func:`colour.models.rgb.RGB_to_RGB` definition nan support.
        """

        aces_2065_1_colourspace = RGB_COLOURSPACES.get('ACES2065-1')
        sRGB_colourspace = RGB_COLOURSPACES.get('sRGB')

        cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
        cases = set(permutations(cases * 3, r=3))
        for case in cases:
            RGB = np.array(case)
            RGB_to_RGB(RGB, aces_2065_1_colourspace, sRGB_colourspace)
import numpy as np
import colour
from colour import read_LUT, write_LUT, LUT3D, LUT3x1D, LUTSequence
from colour.models import RGB_to_RGB, BT2020_COLOURSPACE, P3_D65_COLOURSPACE, eotf_inverse_sRGB
from colour.utilities import tstack

Log2_48_nits_Shaper_to_linear = read_LUT(
    '/Library/Application Support/OpenColorIO/aces_1.1/luts/Log2_48_nits_Shaper_to_linear.spi1d'
)
bt2020_cube = read_LUT(
    '/Library/Application Support/OpenColorIO/aces_1.1/luts/Log2_48_nits_Shaper.RRT.Rec.2020__P3D65_Limited_.spi3d'
)

table = bt2020_cube.table**2.4
table = RGB_to_RGB(table, BT2020_COLOURSPACE, P3_D65_COLOURSPACE)
table = eotf_inverse_sRGB(table)
table = np.clip(table, 0, 1)

display_p3_cube = LUT3D(table=table)

samples = np.linspace(0, 1, 4096)

domain = tstack(
    (Log2_48_nits_Shaper_to_linear.table, Log2_48_nits_Shaper_to_linear.table,
     Log2_48_nits_Shaper_to_linear.table))

shaper = LUT3x1D(domain=domain, table=tstack([samples, samples, samples]))

LUT = LUTSequence(shaper, display_p3_cube)
Exemplo n.º 10
0
def plot_RGB_chromaticities_in_chromaticity_diagram(
        RGB,
        colourspace='sRGB',
        chromaticity_diagram_callable=(
            plot_RGB_colourspaces_in_chromaticity_diagram),
        method='CIE 1931',
        scatter_parameters=None,
        **kwargs):
    """
    Plots given *RGB* colourspace array in the *Chromaticity Diagram* according
    to given method.

    Parameters
    ----------
    RGB : array_like
        *RGB* colourspace array.
    colourspace : optional, unicode
        *RGB* colourspace of the *RGB* array.
    chromaticity_diagram_callable : callable, optional
        Callable responsible for drawing the *Chromaticity Diagram*.
    method : unicode, optional
        **{'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}**,
        *Chromaticity Diagram* method.
    scatter_parameters : dict, optional
        Parameters for the :func:`plt.scatter` definition, if ``c`` is set to
        *RGB*, the scatter will use given ``RGB`` colours.

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

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

    Examples
    --------
    >>> RGB = np.random.random((128, 128, 3))
    >>> plot_RGB_chromaticities_in_chromaticity_diagram(
    ...     RGB, 'ITU-R BT.709')
    ... # doctest: +SKIP

    .. image:: ../_static/Plotting_\
Plot_RGB_Chromaticities_In_Chromaticity_Diagram_Plot.png
        :align: center
        :alt: plot_RGB_chromaticities_in_chromaticity_diagram
    """

    RGB = as_float_array(RGB).reshape(-1, 3)

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

    figure, axes = artist(**settings)

    method = method.upper()

    scatter_settings = {
        's': 40,
        'c': 'RGB',
        'marker': 'o',
        'alpha': 0.85,
    }
    if scatter_parameters is not None:
        scatter_settings.update(scatter_parameters)

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

    colourspace = first_item(filter_RGB_colourspaces(colourspace).values())
    settings['colourspaces'] = (['^{0}$'.format(colourspace.name)] +
                                settings.get('colourspaces', []))

    chromaticity_diagram_callable(**settings)

    use_RGB_colours = scatter_settings['c'].upper() == 'RGB'
    if use_RGB_colours:
        RGB = RGB[RGB[:, 1].argsort()]
        scatter_settings['c'] = np.clip(
            RGB_to_RGB(RGB,
                       colourspace,
                       COLOUR_STYLE_CONSTANTS.colour.colourspace,
                       apply_encoding_cctf=True).reshape(-1, 3), 0, 1)

    XYZ = RGB_to_XYZ(RGB, colourspace.whitepoint, colourspace.whitepoint,
                     colourspace.RGB_to_XYZ_matrix)

    if method == 'CIE 1931':
        ij = XYZ_to_xy(XYZ, colourspace.whitepoint)
    elif method == 'CIE 1960 UCS':
        ij = UCS_to_uv(XYZ_to_UCS(XYZ))

    elif method == 'CIE 1976 UCS':
        ij = Luv_to_uv(XYZ_to_Luv(XYZ, colourspace.whitepoint),
                       colourspace.whitepoint)

    axes.scatter(ij[..., 0], ij[..., 1], **scatter_settings)

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

    return render(**settings)