示例#1
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)
示例#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)
示例#3
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)
示例#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)
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
0
    def test_opto_electronic_conversion_functions(self):
        """
        Tests opto-electronic conversion functions from the
        :attr:`colour.models.RGB_COLOURSPACES` attribute colourspace models.
        """

        aces_proxy_colourspaces = ('ACESproxy', 'ACEScg')

        samples = np.linspace(0, 1, 1000)
        for colourspace in RGB_COLOURSPACES.values():
            if colourspace.name in aces_proxy_colourspaces:
                continue

            samples_oecf = [colourspace.OECF(sample) for sample in samples]
            samples_inverse_oecf = [
                colourspace.EOCF(sample) for sample in samples_oecf
            ]

            np.testing.assert_almost_equal(samples,
                                           samples_inverse_oecf,
                                           decimal=7)

        for colourspace in aces_proxy_colourspaces:
            colourspace = RGB_COLOURSPACES.get(colourspace)
            samples_oecf = [colourspace.OECF(sample) for sample in samples]
            samples_inverse_oecf = [
                colourspace.EOCF(sample) for sample in samples_oecf
            ]

            np.testing.assert_allclose(samples,
                                       samples_inverse_oecf,
                                       rtol=0.01,
                                       atol=0.01)
示例#9
0
def get_RGB_colourspace(colourspace):
    """
    Returns the *RGB* colourspace with given name.

    Parameters
    ----------
    colourspace : unicode
        *RGB* colourspace name.

    Returns
    -------
    RGB_Colourspace
        *RGB* colourspace.

    Raises
    ------
    KeyError
        If the given *RGB* colourspace is not found in the factory *RGB*
        colourspaces.
    """

    colourspace, name = RGB_COLOURSPACES.get(colourspace), colourspace
    if colourspace is None:
        raise KeyError(
            ('"{0}" colourspace not found in factory RGB colourspaces: '
             '"{1}".').format(name,
                              ', '.join(sorted(RGB_COLOURSPACES.keys()))))

    return colourspace
示例#10
0
文件: models.py 项目: KevinJW/colour
def get_RGB_colourspace(colourspace):
    """
    Returns the *RGB* colourspace with given name.

    Parameters
    ----------
    colourspace : Unicode
        *RGB* Colourspace name.

    Returns
    -------
    RGB_Colourspace
        *RGB* Colourspace.

    Raises
    ------
    KeyError
        If the given colourspace is not found in the factory colourspaces.
    """

    colourspace, name = RGB_COLOURSPACES.get(colourspace), colourspace
    if colourspace is None:
        raise KeyError(
            ('"{0}" colourspace not found in factory colourspaces: '
             '"{1}".').format(name, sorted(RGB_COLOURSPACES.keys())))

    return colourspace
示例#11
0
    def test_opto_electronic_conversion_functions(self):
        """
        Tests opto-electronic conversion functions from the
        :attr:`colour.models.RGB_COLOURSPACES` attribute colourspace models.
        """

        aces_proxy_colourspaces = ('ACESproxy', 'ACEScg')

        samples = np.linspace(0, 1, 1000)
        for colourspace in RGB_COLOURSPACES.values():
            if colourspace.name in aces_proxy_colourspaces:
                continue

            samples_oecf = [colourspace.transfer_function(sample)
                            for sample in samples]
            samples_inverse_oecf = [
                colourspace.inverse_transfer_function(sample)
                for sample in samples_oecf]

            np.testing.assert_almost_equal(samples,
                                           samples_inverse_oecf,
                                           decimal=7)

        for colourspace in aces_proxy_colourspaces:
            colourspace = RGB_COLOURSPACES.get(colourspace)
            samples_oecf = [colourspace.transfer_function(sample)
                            for sample in samples]
            samples_inverse_oecf = [
                colourspace.inverse_transfer_function(sample)
                for sample in samples_oecf]

            np.testing.assert_allclose(samples,
                                       samples_inverse_oecf,
                                       rtol=0.01,
                                       atol=0.01)
示例#12
0
文件: common.py 项目: brehm/colour
def XYZ_to_sRGB(XYZ,
                illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint,
                chromatic_adaptation_transform='CAT02',
                apply_OECF=True):
    """
    Converts from *CIE XYZ* tristimulus values to *sRGB* colourspace.

    Parameters
    ----------
    XYZ : array_like
        *CIE XYZ* tristimulus values.
    illuminant : array_like, optional
        Source illuminant chromaticity coordinates.
    chromatic_adaptation_transform : unicode, optional
        **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp',
        'Fairchild, 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco',
        'Bianco PC'}**,
        *Chromatic adaptation* transform.
    apply_OECF : bool, optional
        Apply *sRGB* *opto-electronic conversion function*.

    Returns
    -------
    ndarray
        *sRGB* colour array.

    Notes
    -----
    -   Input *CIE XYZ* tristimulus values are in domain [0, 1].

    Examples
    --------
    >>> import numpy as np
    >>> XYZ = np.array([0.07049534, 0.10080000, 0.09558313])
    >>> XYZ_to_sRGB(XYZ)  # doctest: +ELLIPSIS
    array([ 0.1750135...,  0.3881879...,  0.3216195...])
    """

    sRGB = RGB_COLOURSPACES.get('sRGB')
    return XYZ_to_RGB(XYZ,
                      illuminant,
                      sRGB.whitepoint,
                      sRGB.XYZ_to_RGB_matrix,
                      chromatic_adaptation_transform,
                      sRGB.OECF if apply_OECF else None)
示例#13
0
文件: common.py 项目: fangjy88/colour
def sRGB_to_XYZ(RGB,
                illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint,
                chromatic_adaptation_method='CAT02',
                inverse_transfer_function=True):
    """
    Converts from *sRGB* colourspace to *CIE XYZ* tristimulus values.

    Parameters
    ----------
    RGB : array_like
        *sRGB* colourspace array.
    illuminant : array_like, optional
        Source illuminant chromaticity coordinates.
    chromatic_adaptation_method : unicode, optional
        {'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp', 'Fairchild,
        'CMCCAT97', 'CMCCAT2000', 'Bianco', 'Bianco PC'},
        *Chromatic adaptation* method.
    inverse_transfer_function : bool, optional
        Apply *sRGB* *inverse transfer function*.

    Returns
    -------
    ndarray
        *CIE XYZ* tristimulus values.

    Notes
    -----
    -   Input *RGB* colourspace array is in domain [0, 1].

    Examples
    --------
    >>> import numpy as np
    >>> RGB = np.array([0.17501358, 0.38818795, 0.32161955])
    >>> sRGB_to_XYZ(RGB)  # doctest: +ELLIPSIS
    array([ 0.0704953...,  0.1008    ,  0.0955831...])
    """

    sRGB = RGB_COLOURSPACES.get('sRGB')
    return RGB_to_XYZ(RGB,
                      sRGB.whitepoint,
                      illuminant,
                      sRGB.RGB_to_XYZ_matrix,
                      chromatic_adaptation_method,
                      (sRGB.inverse_transfer_function
                       if inverse_transfer_function else None))
示例#14
0
def sRGB_to_XYZ(RGB,
                illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint,
                chromatic_adaptation_method='CAT02',
                apply_EOCF=True):
    """
    Converts from *sRGB* colourspace to *CIE XYZ* tristimulus values.

    Parameters
    ----------
    RGB : array_like
        *sRGB* colourspace array.
    illuminant : array_like, optional
        Source illuminant chromaticity coordinates.
    chromatic_adaptation_method : unicode, optional
        **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp',
        'Fairchild, 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco',
        'Bianco PC'}**,
        *Chromatic adaptation* method.
    apply_EOCF : bool, optional
        Apply *sRGB* *electro-optical conversion function*.

    Returns
    -------
    ndarray
        *CIE XYZ* tristimulus values.

    Notes
    -----
    -   Input *RGB* colourspace array is in domain [0, 1].

    Examples
    --------
    >>> import numpy as np
    >>> RGB = np.array([0.17501358, 0.38818795, 0.32161955])
    >>> sRGB_to_XYZ(RGB)  # doctest: +ELLIPSIS
    array([ 0.0704953...,  0.1008    ,  0.0955831...])
    """

    sRGB = RGB_COLOURSPACES.get('sRGB')
    return RGB_to_XYZ(RGB, sRGB.whitepoint, illuminant, sRGB.RGB_to_XYZ_matrix,
                      chromatic_adaptation_method,
                      sRGB.EOCF if apply_EOCF else None)
示例#15
0
def XYZ_to_sRGB(XYZ,
                illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint,
                chromatic_adaptation_transform='CAT02',
                apply_OECF=True):
    """
    Converts from *CIE XYZ* tristimulus values to *sRGB* colourspace.

    Parameters
    ----------
    XYZ : array_like
        *CIE XYZ* tristimulus values.
    illuminant : array_like, optional
        Source illuminant chromaticity coordinates.
    chromatic_adaptation_transform : unicode, optional
        **{'CAT02', 'XYZ Scaling', 'Von Kries', 'Bradford', 'Sharp',
        'Fairchild, 'CMCCAT97', 'CMCCAT2000', 'CAT02_BRILL_CAT', 'Bianco',
        'Bianco PC'}**,
        *Chromatic adaptation* transform.
    apply_OECF : bool, optional
        Apply *sRGB* *opto-electronic conversion function*.

    Returns
    -------
    ndarray
        *sRGB* colour array.

    Notes
    -----
    -   Input *CIE XYZ* tristimulus values are in domain [0, 1].

    Examples
    --------
    >>> import numpy as np
    >>> XYZ = np.array([0.07049534, 0.10080000, 0.09558313])
    >>> XYZ_to_sRGB(XYZ)  # doctest: +ELLIPSIS
    array([ 0.1750135...,  0.3881879...,  0.3216195...])
    """

    sRGB = RGB_COLOURSPACES.get('sRGB')
    return XYZ_to_RGB(XYZ, illuminant, sRGB.whitepoint, sRGB.XYZ_to_RGB_matrix,
                      chromatic_adaptation_transform,
                      sRGB.OECF if apply_OECF else None)
示例#16
0
文件: common.py 项目: KevinJW/colour
def XYZ_to_sRGB(XYZ,
                illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint,
                chromatic_adaptation_method='CAT02',
                transfer_function=True):
    """
    Converts from *CIE XYZ* colourspace to *sRGB* colourspace.

    Parameters
    ----------
    XYZ : array_like, (3,)
        *CIE XYZ* colourspace matrix.
    illuminant : array_like, optional
        Source illuminant chromaticity coordinates.
    chromatic_adaptation_method : unicode, optional
        ('XYZ Scaling', 'Bradford', 'Von Kries', 'Fairchild', 'CAT02')
        *Chromatic adaptation* method.
    transfer_function : bool, optional
        Apply *sRGB* *transfer function*.

    Returns
    -------
    ndarray, (3,)
        *sRGB* colour matrix.

    Notes
    -----
    -   Input *CIE XYZ* colourspace matrix is in domain [0, 1].

    Examples
    --------
    >>> XYZ = np.array([0.1180583421, 0.1034, 0.0515089229])
    >>> XYZ_to_sRGB(XYZ)  # doctest: +ELLIPSIS
    array([ 0.4822488...,  0.3165197...,  0.2207051...])
    """

    sRGB = RGB_COLOURSPACES.get('sRGB')
    return XYZ_to_RGB(XYZ,
                      illuminant,
                      sRGB.whitepoint,
                      sRGB.to_RGB,
                      chromatic_adaptation_method,
                      sRGB.transfer_function if transfer_function else None)
示例#17
0
def XYZ_to_sRGB(XYZ,
                illuminant=RGB_COLOURSPACES.get('sRGB').whitepoint,
                chromatic_adaptation_method='CAT02',
                transfer_function=True):
    """
    Converts from *CIE XYZ* colourspace to *sRGB* colourspace.

    Parameters
    ----------
    XYZ : array_like, (3,)
        *CIE XYZ* colourspace matrix.
    illuminant : array_like, optional
        Source illuminant chromaticity coordinates.
    chromatic_adaptation_method : unicode, optional
        ('XYZ Scaling', 'Bradford', 'Von Kries', 'Fairchild', 'CAT02')
        *Chromatic adaptation* method.
    transfer_function : bool, optional
        Apply *sRGB* *transfer function*.

    Returns
    -------
    ndarray, (3,)
        *sRGB* colour matrix.

    Notes
    -----
    -   Input *CIE XYZ* colourspace matrix is in domain [0, 1].

    Examples
    --------
    >>> XYZ = np.array([0.1180583421, 0.1034, 0.0515089229])
    >>> XYZ_to_sRGB(XYZ)  # doctest: +ELLIPSIS
    array([ 0.4822488...,  0.3165197...,  0.2207051...])
    """

    sRGB = RGB_COLOURSPACES.get('sRGB')
    return XYZ_to_RGB(XYZ, illuminant, sRGB.whitepoint, sRGB.to_RGB,
                      chromatic_adaptation_method,
                      sRGB.transfer_function if transfer_function else None)
示例#18
0
def colour_checker_plot(colour_checker='ColorChecker 2005', **kwargs):
    """
    Plots given colour checker.

    Parameters
    ----------
    colour_checker : unicode, optional
        Color checker name.
    \**kwargs : dict, optional
        Keywords arguments.

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

    Raises
    ------
    KeyError
        If the given colour rendition chart is not found in the factory colour
        rendition charts.

    Examples
    --------
    >>> colour_checker_plot()  # doctest: +SKIP
    True
    """

    canvas(**kwargs)

    colour_checker, name = COLOURCHECKERS.get(colour_checker), colour_checker
    if colour_checker is None:
        raise KeyError(
            ('Colour checker "{0}" not found in '
             'factory colour checkers: "{1}".').format(
                name, sorted(COLOURCHECKERS.keys())))

    _name, data, illuminant = colour_checker
    colour_parameters = []
    for _index, label, x, y, Y in data:
        XYZ = xyY_to_XYZ((x, y, Y))
        RGB = XYZ_to_sRGB(XYZ, illuminant)

        colour_parameters.append(
            ColourParameter(label.title(), np.clip(np.ravel(RGB), 0, 1)))

    background_colour = '0.1'
    matplotlib.pyplot.gca().patch.set_facecolor(background_colour)

    width = height = 1.0
    spacing = 0.25
    across = 6

    settings = {
        'standalone': False,
        'width': width,
        'height': height,
        'spacing': spacing,
        'across': across,
        'text_size': 8,
        'margins': (-0.125, 0.125, -0.5, 0.125)}
    settings.update(kwargs)

    multi_colour_plot(colour_parameters, **settings)

    text_x = width * (across / 2) + (across * (spacing / 2)) - spacing / 2
    text_y = -(len(colour_parameters) / across + spacing / 2)

    pylab.text(text_x,
               text_y,
               '{0} - {1} - Colour Rendition Chart'.format(
                   name, RGB_COLOURSPACES.get('sRGB').name),
               color='0.95',
               clip_on=True,
               ha='center')

    settings.update({
        'title': name,
        'facecolor': background_colour,
        'edgecolor': None,
        'standalone': True})

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

    return display(**settings)