Example #1
0
def getMunsellData(white_point=(1.0 / 3, 1.0 / 3), V=None, H=None):
    target_wp = np.array(white_point)
    munsell_wp = np.array([0.309, 0.319])
    XYZ_ws = colour.xy_to_XYZ(munsell_wp) * 100
    XYZ_wt = colour.xy_to_XYZ(target_wp) * 100

    if V is None:
        V = [4]
    if H is None:
        H = ['5R', '5Y', '10GY', '5BG', '5PB', '5P', '5RP']

    def convert_xyYtoXYZ(data):
        xyz = colour.xyY_to_XYZ(data)
        return colour.adaptation.chromatic_adaptation_VonKries(
            xyz, XYZ_ws, XYZ_wt, transform='CAT02')

    result = []
    for value in V:
        for hue in H:
            idx = np.logical_and(munsell_data_np[:, 0] == hue,
                                 munsell_data_np[:, 1] == value)
            if np.sum(idx) > 0:
                data = convert_xyYtoXYZ(munsell_data_np[idx, :][:, 3:]) / 100
                result.append((data, hue + '_v' + str(value)))
    return result
Example #2
0
def getHungBernsData(white_point=(1.0 / 3, 1.0 / 3)):
    hung_wp = np.array([0.3127, 0.3290])
    XYZ_ws = colour.xy_to_XYZ(hung_wp) * 100
    XYZ_wt = colour.xy_to_XYZ(np.array(white_point)) * 100

    def convertWp(data):
        return colour.adaptation.chromatic_adaptation_VonKries(
            data, XYZ_ws, XYZ_wt, transform='CAT02')

    with open(hung_data_path, 'r') as f:
        ydata = yaml.load(f, Loader=yaml.FullLoader)
        data = []
        names = []

        for col in ydata:
            names.append(col)
            j = 0
            ldata = np.zeros((4, 3))
            for sat in ydata[col]:
                ldata[j, :] = np.array(ydata[col][sat])
                j += 1
            data.append(convertWp(ldata) / 100)

        return (data, names)

    return None
def RGB_colourspace_whitepoint_axis_visual(colourspace='ITU-R BT.709',
                                           reference_colourspace='CIE xyY',
                                           width=2.0,
                                           method='gl',
                                           parent=None):
    """
    Returns a :class:`vispy.scene.visuals.Line` class instance representing
    a given RGB colourspace whitepoint axis.

    Parameters
    ----------
    colourspace : unicode, optional
        See :func:`RGB_colourspace_volume_visual` argument for possible values.

        :class:`colour.RGB_Colourspace` class instance name defining the *RGB*
        colourspace whitepoint axis to draw.
    reference_colourspace : unicode, optional
        **{'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW',
        'IPT', 'Hunter Lab', 'Hunter Rdab'}**,
        Reference colourspace to use for colour conversions / transformations.
    width : numeric, optional
        Line width.
    method : unicode, optional
        **{'gl', 'agg'}**,
        Line drawing method.
    parent : Node, optional
        Parent of the spectral locus visual in the `SceneGraph`.

    Returns
    -------
    Line
        RGB colourspace whitepoint axis.
    """

    colourspace = first_item(filter_RGB_colourspaces(colourspace).values())
    XYZ_o = xy_to_XYZ(colourspace.whitepoint + (0, ))
    XYZ_f = xy_to_XYZ(colourspace.whitepoint + (1.1, ))
    XYZ_l = np.vstack([XYZ_o, XYZ_f])

    illuminant = DEFAULT_PLOTTING_ILLUMINANT

    points = common_colourspace_model_axis_reorder(
        XYZ_to_colourspace_model(XYZ_l, illuminant, reference_colourspace),
        reference_colourspace)

    line = Line(points, (1, 1, 1), width=width, method=method, parent=parent)

    return line
def RGB_colourspace_whitepoint_axis_visual(colourspace='ITU-R BT.709',
                                           reference_colourspace='CIE xyY',
                                           width=2.0,
                                           method='gl',
                                           parent=None):
    """
    Returns a :class:`vispy.scene.visuals.Line` class instance representing
    a given RGB colourspace whitepoint axis.

    Parameters
    ----------
    colourspace : unicode, optional
        See :func:`RGB_colourspace_volume_visual` argument for possible values.

        :class:`colour.RGB_Colourspace` class instance name defining the *RGB*
        colourspace whitepoint axis to draw.
    reference_colourspace : unicode, optional
        **{'CIE XYZ', 'CIE xyY', 'CIE Lab', 'CIE Luv', 'CIE UCS', 'CIE UVW',
        'IPT', 'Hunter Lab', 'Hunter Rdab'}**,
        Reference colourspace to use for colour conversions / transformations.
    width : numeric, optional
        Line width.
    method : unicode, optional
        **{'gl', 'agg'}**,
        Line drawing method.
    parent : Node, optional
        Parent of the spectral locus visual in the `SceneGraph`.

    Returns
    -------
    Line
        RGB colourspace whitepoint axis.
    """

    colourspace = first_item(filter_RGB_colourspaces(colourspace).values())
    XYZ_o = xy_to_XYZ(colourspace.whitepoint + (0, ))
    XYZ_f = xy_to_XYZ(colourspace.whitepoint + (1.1, ))
    XYZ_l = np.vstack([XYZ_o, XYZ_f])

    illuminant = DEFAULT_PLOTTING_ILLUMINANT

    points = common_colourspace_model_axis_reorder(
        XYZ_to_colourspace_model(XYZ_l, illuminant, reference_colourspace),
        reference_colourspace)

    line = Line(points, (1, 1, 1), width=width, method=method, parent=parent)

    return line
Example #5
0
    def set_color(self, color):
        """Propagate user-set colors to the brush too (extension).
        """

        colors.ColorManager.set_color(self, color)
        if not self.__in_callback:

            if not isinstance(color, lib.color.CIECAMColor):
                prefs = self.get_prefs()
                lightsource = prefs['color.dimension_lightsource']

                if lightsource == "custom_XYZ":
                    lightsource = prefs['color.dimension_lightsource_XYZ']
                else:
                    lightsource = colour.xy_to_XYZ(
                        colour.ILLUMINANTS['cie_2_1931'][lightsource]) * 100.0
                # standard sRGB view environment except adjustable illuminant
                cieaxes = prefs['color.dimension_value'] + \
                    prefs['color.dimension_purity'] + "h"
                color = lib.color.CIECAMColor(color=color, cieaxes=cieaxes,
                                              lightsource=lightsource)
                #from gui.application import get_app
                #app = get_app()
                self._app.doc.last_color_target = None
            self.__brush.set_ciecam_color(color)
            self.__brush.set_color_hsv(color.get_hsv())
Example #6
0
def JzAzBz(xyz, saturation, white_point):
    XYZ_w = colour.xy_to_XYZ(np.array(white_point)) * 100
    XYZ_wr = colour.xy_to_XYZ(np.array([0.3127, 0.3290])) * 100
    data = colour.adaptation.chromatic_adaptation_VonKries(xyz * 100,
                                                           XYZ_w,
                                                           XYZ_wr,
                                                           transform='CAT02')
    data[data < 0.000000001] = 0.000000001
    data = colour.XYZ_to_JzAzBz(data)

    data[..., 1] = saturation * data[..., 1]
    data[..., 2] = saturation * data[..., 2]

    data = colour.JzAzBz_to_XYZ(data)
    return colour.adaptation.chromatic_adaptation_VonKries(
        data, XYZ_wr, XYZ_w, transform='CAT02') * 0.01
Example #7
0
def applyHermiteTonemap(xyz,
                        white_point,
                        spline_params=None,
                        rgb_space=colour.RGB_COLOURSPACES['sRGB'],
                        overwrite_params={}):
    if spline_params is None:
        spline_params = spline_curve_defaults.copy()
    spline_params.update(overwrite_params)

    XYZ_w = colour.xy_to_XYZ(np.array(white_point)) * 100
    XYZ_wr = colour.xy_to_XYZ(rgb_space.whitepoint) * 100
    xyz_d65 = colour.adaptation.chromatic_adaptation_VonKries(
        xyz, XYZ_w, XYZ_wr, transform='CAT02')

    rgb_pure = colour.XYZ_to_RGB(xyz_d65, rgb_space.whitepoint,
                                 rgb_space.whitepoint,
                                 rgb_space.XYZ_to_RGB_matrix, None, None)
    rgb_pure = applySplineCurve(rgb_pure, spline_params)

    ycbcr = np.zeros(xyz_d65.shape)
    ycbcr[..., 0] = xyz_d65[..., 0] * XYZ_TO_YCbCr_Rec2020[0] + xyz_d65[
        ..., 1] * XYZ_TO_YCbCr_Rec2020[1] + xyz_d65[
            ..., 2] * XYZ_TO_YCbCr_Rec2020[2]
    ycbcr[..., 1] = xyz_d65[..., 0] * XYZ_TO_YCbCr_Rec2020[3] + xyz_d65[
        ..., 1] * XYZ_TO_YCbCr_Rec2020[4] + xyz_d65[
            ..., 2] * XYZ_TO_YCbCr_Rec2020[5]
    ycbcr[..., 2] = xyz_d65[..., 0] * XYZ_TO_YCbCr_Rec2020[6] + xyz_d65[
        ..., 1] * XYZ_TO_YCbCr_Rec2020[7] + xyz_d65[
            ..., 2] * XYZ_TO_YCbCr_Rec2020[8]
    ycbcr[..., 0] = applySplineCurve(ycbcr[..., 0], spline_params)
    xyz_d65[..., 0] = ycbcr[..., 0] * Rec2020_YCbCr_TO_XYZ[0] + ycbcr[
        ..., 1] * Rec2020_YCbCr_TO_XYZ[1] + ycbcr[...,
                                                  2] * Rec2020_YCbCr_TO_XYZ[2]
    xyz_d65[..., 1] = ycbcr[..., 0] * Rec2020_YCbCr_TO_XYZ[3] + ycbcr[
        ..., 1] * Rec2020_YCbCr_TO_XYZ[4] + ycbcr[...,
                                                  2] * Rec2020_YCbCr_TO_XYZ[5]
    xyz_d65[..., 2] = ycbcr[..., 0] * Rec2020_YCbCr_TO_XYZ[6] + ycbcr[
        ..., 1] * Rec2020_YCbCr_TO_XYZ[7] + ycbcr[...,
                                                  2] * Rec2020_YCbCr_TO_XYZ[8]
    rgb_luma = colour.XYZ_to_RGB(xyz_d65, rgb_space.whitepoint,
                                 rgb_space.whitepoint,
                                 rgb_space.XYZ_to_RGB_matrix, None, None)

    return rgb_pure * (1.0 - spline_params['luma_ratio']
                       ) + rgb_luma * spline_params['luma_ratio']
Example #8
0
    def get_bar_amount_for_color(self, col):
        # pull in CIECAM config
        cm = self.get_color_manager()
        prefs = cm.get_prefs()
        lightsource = colour.xy_to_XYZ(
            colour.ILLUMINANTS['cie_2_1931']['D65']) * 100.0
        # standard sRGB view environment except adjustable illuminant
        cieaxes = prefs['color.dimension_value'] + \
            prefs['color.dimension_purity'] + "h"
        col = CIECAMColor(color=col, cieaxes=cieaxes, lightsource=lightsource,
                          discount_in=False, discount_out=False)

        return max(0.0, col.h) / 360
def RGB_colourspace_triangle_visual(colourspace='ITU-R BT.709',
                                    diagram='CIE 1931',
                                    uniform_colour=None,
                                    uniform_opacity=1.0,
                                    width=4.0,
                                    parent=None):
    """
    Returns a :class:`vispy.scene.visuals.Line` class instance representing
    a *RGB* colourspace triangle visual.

    Parameters
    ----------
    colourspace : unicode, optional
        See :func:`RGB_colourspace_volume_visual` argument for possible values.

        :class:`colour.RGB_Colourspace` class instance name defining the *RGB*
        colourspace triangle to draw.
    diagram : unicode, optional
        **{'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}**,
        Chromaticity diagram to use.
    uniform_colour : array_like, optional
        Uniform triangle colour.
    uniform_opacity : numeric, optional
        Uniform mesh opacity.
    width : numeric, optional
        Triangle edge width.
    parent : Node, optional
        Parent of the *RGB* colourspace volume visual in the `SceneGraph`.
    """

    if uniform_colour is None:
        uniform_colour = (0.8, 0.8, 0.8)

    colourspace = first_item(filter_RGB_colourspaces(colourspace).values())

    illuminant = DEFAULT_PLOTTING_ILLUMINANT

    XYZ_to_ij = CHROMATICITY_DIAGRAM_TRANSFORMATIONS[diagram]['XYZ_to_ij']

    ij = XYZ_to_ij(xy_to_XYZ(colourspace.primaries), illuminant)
    # TODO: Remove following hack dealing with 'agg' method issues.
    ij = np.vstack([ij[-1, ...], ij, ij[0, ...]])

    ij[np.isnan(ij)] = 0

    RGB = np.hstack([uniform_colour, uniform_opacity])

    line = Line(ij, RGB, width=width, method='agg', parent=parent)

    return line
def RGB_colourspace_triangle_visual(colourspace='ITU-R BT.709',
                                    diagram='CIE 1931',
                                    uniform_colour=None,
                                    uniform_opacity=1.0,
                                    width=4.0,
                                    parent=None):
    """
    Returns a :class:`vispy.scene.visuals.Line` class instance representing
    a *RGB* colourspace triangle visual.

    Parameters
    ----------
    colourspace : unicode, optional
        See :func:`RGB_colourspace_volume_visual` argument for possible values.

        :class:`colour.RGB_Colourspace` class instance name defining the *RGB*
        colourspace triangle to draw.
    diagram : unicode, optional
        **{'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}**,
        Chromaticity diagram to use.
    uniform_colour : array_like, optional
        Uniform triangle colour.
    uniform_opacity : numeric, optional
        Uniform mesh opacity.
    width : numeric, optional
        Triangle edge width.
    parent : Node, optional
        Parent of the *RGB* colourspace volume visual in the `SceneGraph`.
    """

    if uniform_colour is None:
        uniform_colour = (0.8, 0.8, 0.8)

    colourspace = first_item(filter_RGB_colourspaces(colourspace).values())

    illuminant = DEFAULT_PLOTTING_ILLUMINANT

    XYZ_to_ij = CHROMATICITY_DIAGRAM_TRANSFORMATIONS[diagram]['XYZ_to_ij']

    ij = XYZ_to_ij(xy_to_XYZ(colourspace.primaries), illuminant)
    # TODO: Remove following hack dealing with 'agg' method issues.
    ij = np.vstack([ij[-1, ...], ij, ij[0, ...]])

    ij[np.isnan(ij)] = 0

    RGB = np.hstack([uniform_colour, uniform_opacity])

    line = Line(ij, RGB, width=width, method='agg', parent=parent)

    return line
Example #11
0
	def temperatureChange(self):	
		value = self.temperatureSlider.value() +1
		#range is 1100K to 11 000K
		K = int(1000+ (value*120))
		print("Kelvins: ", K)
		xy = colour.CCT_to_xy(K)
		#print("xy", xy)
		xyz = colour.xy_to_XYZ(xy)
		#print("xyz", xyz)
		rgb = colour.XYZ_to_sRGB(xyz)
		r = int(min(1,max(0,rgb[0]))*255)
		g = int(min(1,max(0,rgb[1]))*255)
		b = int(min(1,max(0,rgb[2]))*255)
		self.color = [r, g, b]
		print("rgb", self.color)
		self.updateColorLabel()
def calculate_EVILS_eiY(XYZ_D65, xy_achromatic=[0.3127, 0.3290]):
    # EVILS eiY Oppenent Chroma Model. Fancy words for transforming the
    # CIE XYZ values into u' v' Cartesian coordinates. The true "magic" if
    # there is any, is in the identification of the HK effect issues with
    # the Cartesian distances offered from u' v'.
    e, i, Y = np.split(calculate_eiY(XYZ_D65), 3, axis=-1)
    e_a, i_a, Y_a = np.split(calculate_eiY(colour.xy_to_XYZ(xy_achromatic)),
                             3,
                             axis=-1)

    eiY_output_e = e - e_a
    eiY_output_i = i - i_a
    eiY_output_Y = Y

    eiY_output = np.vstack([eiY_output_e.T, eiY_output_i.T,
                            eiY_output_Y.T]).T.reshape(XYZ_D65.shape)

    return eiY_output
Example #13
0
def temperature_to_rgb(cct):
    """ Convert temperature in Kelvin to sRGB.
    First, we convert CCT (Kelvin) to chromaticity coordinates.
    Second, we convert to tristimulus values.
    Third, we convert to rgb

    Parameters
    ----------
    cct : Correlated color temperature in kelvin

    Returns
    -------
    array : List/tuple of rgb values, e.g. [255.0, 235.0, 12.0]
    """
    xy = colour.CCT_to_xy(cct)
    xyz = colour.xy_to_XYZ(xy)
    rgb = colour.XYZ_to_sRGB(xyz)
    return rgb
Example #14
0
    def get_color_for_bar_amount(self, amt):
        # pull in CIECAM config
        cm = self.get_color_manager()
        prefs = cm.get_prefs()

        lightsource = colour.xy_to_XYZ(
            colour.ILLUMINANTS['cie_2_1931']['D65']) * 100.0

        cieaxes = prefs['color.dimension_value'] + \
            prefs['color.dimension_purity'] + "h"
        col = CIECAMColor(
            color=self.get_managed_color(),
            cieaxes=cieaxes,
            lightsource=lightsource,
            discount_in=False,
            discount_out=False
        )
        col.limit_purity = None
        col.cachedrgb = None
        col.h = max(0.0, amt) * 360
        col.v = 50
        col.s = 35
        return col
Example #15
0
def get_normalize_rgb_value_from_small_xy(small_xy, name=cs.BT709):
    """
    Examples
    --------
    >>> xy = calc_xy_from_white_to_primary_n_step(name=cs.BT709,
                                                  step=5, color='green')
    >>> print(xy)
    [[0.3127, 0.3290], [0.3095, 0.3968], [0.3064, 0.4645],
     [0.3032, 0.5323], [0.3000, 0.6000]]
    >>> get_normalize_rgb_value_from_small_xy(xy)
    [[  1.00000000e+00   1.00000000e+00   1.00000000e+00]
     [  5.40536717e-01   1.00000000e+00   5.40536717e-01]
     [  2.81687026e-01   1.00000000e+00   2.81687026e-01]
     [  1.15605362e-01   1.00000000e+00   1.15605362e-01]
     [  1.58799347e-16   1.00000000e+00   4.73916800e-16]]
    """
    large_xyz = xy_to_XYZ(small_xy)
    xyz_to_rgb_mtx = RGB_COLOURSPACES[name].XYZ_to_RGB_matrix
    rgb_linear = XYZ_to_RGB(large_xyz, D65_WHITE, D65_WHITE, xyz_to_rgb_mtx)
    normalize_val = np.max(rgb_linear, axis=-1)
    rgb_linear /= normalize_val.reshape((rgb_linear.shape[0], 1))

    return rgb_linear
__all__ = ['POINTER_GAMUT_DATA',
           'POINTER_GAMUT_BOUNDARIES',
           'pointer_gamut_visual',
           'pointer_gamut_boundaries_visual',
           'pointer_gamut_hull_visual']

POINTER_GAMUT_DATA = Lab_to_XYZ(LCHab_to_Lab(POINTER_GAMUT_DATA),
                                POINTER_GAMUT_ILLUMINANT)
"""
Pointer's Gamut data converted to *CIE XYZ* tristimulus values.

POINTER_GAMUT_DATA : ndarray
"""

POINTER_GAMUT_BOUNDARIES = xy_to_XYZ(POINTER_GAMUT_BOUNDARIES)
"""
Pointer's Gamut boundaries data converted to *CIE XYZ* tristimulus values.

POINTER_GAMUT_BOUNDARIES : ndarray
"""


def pointer_gamut_visual(reference_colourspace='CIE xyY',
                         size=4.0,
                         edge_size=0.5,
                         uniform_colour=(0.9, 0.9, 0.9),
                         uniform_opacity=0.8,
                         uniform_edge_colour=(0.9, 0.9, 0.9),
                         uniform_edge_opacity=0.8,
                         parent=None):
Example #17
0
from colour import (Luv_to_uv, Luv_uv_to_xy, UCS_to_uv, UCS_uv_to_xy,
                    xy_to_XYZ, XYZ_to_Luv, XYZ_to_UCS, XYZ_to_xy)

__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__ = ['CHROMATICITY_DIAGRAM_TRANSFORMATIONS', 'Cycle']

CHROMATICITY_DIAGRAM_TRANSFORMATIONS = {
    'CIE 1931': {
        'XYZ_to_ij': lambda a, i: XYZ_to_xy(a, i),
        'ij_to_XYZ': lambda a, i: xy_to_XYZ(a)
    },
    'CIE 1960 UCS': {
        'XYZ_to_ij': lambda a, i: UCS_to_uv(XYZ_to_UCS(a)),
        'ij_to_XYZ': lambda a, i: xy_to_XYZ(UCS_uv_to_xy(a))
    },
    'CIE 1976 UCS': {
        'XYZ_to_ij': lambda a, i: Luv_to_uv(XYZ_to_Luv(a, i), i),
        'ij_to_XYZ': lambda a, i: xy_to_XYZ(Luv_uv_to_xy(a))
    }
}
"""
Chromaticity diagram specific helper conversion objects.

CHROMATICITY_DIAGRAM_TRANSFORMATIONS : dict
    **{'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}**
colourspace = colour.RGB_COLOURSPACES['ACES RGB']
print('Name:\n"{0}"'.format(colourspace.name))
print('\nPrimaries:\n{0}'.format(colourspace.primaries))
print('\nNormalised primary matrix to "CIE XYZ":\n{0}'.format(
    colourspace.to_XYZ))
print('\nNormalised primary matrix to "ACES RGB":\n{0}'.format(
    colourspace.to_RGB))
print('\nTransfer function from linear to colourspace:\n{0}'.format(
    colourspace.transfer_function))
print('\nInverse transfer function from colourspace to linear:\n{0}'.format(
    colourspace.inverse_transfer_function))

print('\n')

message_box('Computing "ACES RGB" colourspace to "sRGB" colourspace matrix.')
cat = colour.chromatic_adaptation_matrix(
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['ACES RGB'].whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['sRGB'].whitepoint))
print(np.dot(colour.RGB_COLOURSPACES['sRGB'].to_RGB,
             np.dot(cat, colour.RGB_COLOURSPACES['ACES RGB'].to_XYZ)))

print('\n')

RGB = [0.35521588, 0.41, 0.24177934]
message_box(('Converting from "sRGB" colourspace to "ProPhoto RGB" '
             'colourspace given "RGB" values:\n'
             '\n\t{0}'.format(RGB)))
print(colour.RGB_to_RGB(RGB,
                        colour.RGB_COLOURSPACES['sRGB'],
                        colour.RGB_COLOURSPACES['ProPhoto RGB']))
Example #19
0
print('\nPrimaries:\n{0}'.format(colourspace.primaries))
print(('\nNormalised primary matrix to "CIE XYZ" '
       'tristimulus values:\n{0}').format(colourspace.RGB_to_XYZ_matrix))
print('\nNormalised primary matrix to "ACES2065-1":\n{0}'.format(
    colourspace.XYZ_to_RGB_matrix))
print('\nOpto-electronic transfer function from '
      'linear to colourspace:\n{0}'.format(colourspace.encoding_cctf))
print('\nElectro-optical transfer function from '
      'colourspace to linear:\n{0}'.format(colourspace.decoding_cctf))

print('\n')

message_box(('Computing "ACES2065-1" colourspace to "Rec. 709" colourspace '
             'matrix.'))
cat = colour.chromatic_adaptation_matrix_VonKries(
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['ACES2065-1'].whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['Rec. 709'].whitepoint))
print(
    np.dot(
        colour.RGB_COLOURSPACES['Rec. 709'].XYZ_to_RGB_matrix,
        np.dot(cat, colour.RGB_COLOURSPACES['ACES2065-1'].RGB_to_XYZ_matrix)))

print('\n')

RGB = (0.35521588, 0.41000000, 0.24177934)
message_box(('Converting from "Rec. 709" colourspace to "ACEScg" colourspace '
             'given "RGB" values:\n'
             '\n\t{0}'.format(RGB)))
print(
    colour.RGB_to_RGB(RGB, colour.RGB_COLOURSPACES['Rec. 709'],
                      colour.RGB_COLOURSPACES['ACEScg']))
Example #20
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Showcases correlated colour temperature computations.
"""

import colour
from colour.utilities.verbose import message_box

message_box('Correlated Colour Temperature Computations')

cmfs = colour.CMFS['CIE 1931 2 Degree Standard Observer']
illuminant = colour.ILLUMINANTS_RELATIVE_SPDS['D65']
xy = colour.XYZ_to_xy(colour.spectral_to_XYZ(illuminant, cmfs))
uv = colour.UCS_to_uv(colour.XYZ_to_UCS(colour.xy_to_XYZ(xy)))
message_box(('Converting to "CCT" and "D_uv" from given "CIE UCS" colourspace '
             '"uv" chromaticity coordinates using "Ohno (2013)" method:\n'
             '\n\t{0}'.format(uv)))
print(colour.uv_to_CCT_Ohno2013(uv, cmfs=cmfs))
print(colour.uv_to_CCT(uv, cmfs=cmfs))

print('\n')

message_box('Faster computation with 3 iterations but a lot less precise.')
print(colour.uv_to_CCT_Ohno2013(uv, cmfs=cmfs, iterations=3))

print('\n')

message_box(('Converting to "CCT" and "D_uv" from given "CIE UCS" colourspace '
             '"uv" chromaticity coordinates using "Robertson (1968)" method:\n'
             '\n\t{0}'.format(uv)))
Example #21
0
print('\n')

message_box('Using "Bradford" CAT.')
print(colour.chromatic_adaptation_matrix_VonKries(
    XYZ_w, XYZ_wr, transform='Bradford'))

print('\n')

message_box(('Computing the chromatic adaptation matrix from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using "Von Kries" CAT.'))
A = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['A']
D65 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
print(colour.chromatic_adaptation_matrix_VonKries(
    colour.xy_to_XYZ(A),
    colour.xy_to_XYZ(D65),
    transform='Von Kries'))

print('\n')

XYZ = (1.14176346, 1.00000000, 0.49815206)
message_box(('Adapting given "CIE XYZ" tristimulus values from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using "Sharp" CAT.\n'
             '\n\t"XYZ":\n\t\t{0}'.format(XYZ)))
print(colour.chromatic_adaptation_VonKries(
    XYZ,
    colour.xy_to_XYZ(A),
    colour.xy_to_XYZ(D65),
    transform='Sharp'))
Example #22
0
        / 100
    )
)

print("\n")

RGB = np.array([0.45675795, 0.30986982, 0.24861924])
message_box(
    f'Converting to the "CAM16-UCS" colourspace from given "Output-Referred" '
    f'"sRGB" colourspace values:\n\n\t{RGB}'
)
print(colour.convert(RGB, "Output-Referred RGB", "CAM16UCS"))
specification = colour.XYZ_to_CAM16(
    colour.sRGB_to_XYZ(RGB) * 100,
    XYZ_w=colour.xy_to_XYZ(
        colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"]
    )
    * 100,
    L_A=64 / np.pi * 0.2,
    Y_b=20,
)
print(
    colour.JMh_CAM16_to_CAM16UCS(
        colour.utilities.tstack(
            [
                specification.J,
                specification.M,
                specification.h,
            ]
        )
    )
Example #23
0
message_box('Using "Bradford" CAT.')
print(
    colour.chromatic_adaptation_matrix_VonKries(XYZ_w,
                                                XYZ_wr,
                                                transform='Bradford'))

print('\n')

message_box(('Computing the chromatic adaptation matrix from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using Von Kries CAT.'))
A = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['A']
D65 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
print(
    colour.chromatic_adaptation_matrix_VonKries(colour.xy_to_XYZ(A),
                                                colour.xy_to_XYZ(D65),
                                                transform='Von Kries'))

print('\n')

XYZ = (1.14176346, 1.00000000, 0.49815206)
message_box(('Adapting given "CIE XYZ" tristimulus values from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using "Sharp" CAT.\n'
             '\n\t"XYZ":\n\t\t{0}'.format(XYZ)))
print(
    colour.chromatic_adaptation_VonKries(XYZ,
                                         colour.xy_to_XYZ(A),
                                         colour.xy_to_XYZ(D65),
                                         transform='Sharp'))
Example #24
0
        })

    if not result.success:
        raise RuntimeError(
            'Optimization failed for {0} after {1} iterations: "{2}".'.format(
                XYZ, result.nit, result.message))

    return SpectralDistribution(
        from_range_100(np.exp(result.x) * 100),
        wavelengths,
        name='Meng (2015) - {0}'.format(XYZ))

# Define our illuminant and color space matrices

D65_xy = colour.ILLUMINANTS['cie_2_1931']['D65']
D65 = colour.xy_to_XYZ(D65_xy)

CMFS = colour.CMFS['cie_2_1931']
D65_SPD = colour.ILLUMINANTS_SDS['D65']/100.
# illuminant_SPD = colour.XYZ_to_spectral_Meng2015(D65, cmfs=CMFS, interval=shape.interval)
illuminant_SPD = D65_SPD

np.set_printoptions(formatter={"float": "{:0.15f}".format}, threshold=np.nan)

colorspace = colour.models.BT709_COLOURSPACE

colorspace.use_derived_transformation_matrices(True)


RGB_to_XYZ_m = colorspace.RGB_to_XYZ_matrix
XYZ_to_RGB_m = colorspace.XYZ_to_RGB_matrix
Example #25
0
def plot_jzazbz(lines = [], scatter = [], hue_lines = [], white_point = (1.0/3, 1.0/3),
                filename = None, save_only = False):
    XYZ_w  = colour.xy_to_XYZ(np.array(white_point)) * 100
    XYZ_wr = colour.xy_to_XYZ(np.array([0.3127,   0.3290])) * 100
    def convertData(xyz):
        xyz_d65 = colour.adaptation.chromatic_adaptation_VonKries(xyz * 100, XYZ_w, XYZ_wr, transform='CAT02')
        return colour.XYZ_to_JzAzBz(xyz_d65)

    ax  = [None] * 3
    fig = [None] * 3
    for i in range(3):
        fig[i], ax[i] = plt.subplots()
    plotHull(jzazbz_hull[:,[1,0]], ax[0])
    plotHull(jzazbz_hull[:,[2,0]], ax[1])
    plotHull(jzazbz_hull[:,[1,2]], ax[2])

    ax[0].set_xlim(-0.45, 0.45)
    ax[0].set_ylim(-0.05, 1.05)
    ax[0].set_aspect('equal')
    ax[0].set_xlabel('Az')
    ax[0].set_ylabel('Jz')

    ax[1].set_xlim(-0.45, 0.45)
    ax[1].set_ylim(-0.05, 1.05)
    ax[1].set_aspect('equal')
    ax[1].set_xlabel('Bz')
    ax[1].set_ylabel('Jz')

    ax[2].set_xlim(-0.45, 0.45)
    ax[2].set_ylim(-0.45, 0.45)
    ax[2].set_aspect('equal')
    ax[2].set_xlabel('Az')
    ax[2].set_ylabel('Bz')

    for line,label in hue_lines:
        data = convertData(line)
        ax[0].plot(data[:,1], data[:,0], label=label, color=hue_line_color, linestyle=hue_line_style, marker=hue_point_style)
        ax[1].plot(data[:,2], data[:,0], label=label, color=hue_line_color, linestyle=hue_line_style, marker=hue_point_style)
        ax[2].plot(data[:,1], data[:,2], label=label, color=hue_line_color, linestyle=hue_line_style, marker=hue_point_style)

    cnt = 0
    for line,label in lines:
        data = convertData(line)
        lstyle = lineStyle(cnt)
        ax[0].plot(data[:,1], data[:,0], label=label, color=lstyle[0], linestyle=lstyle[2], marker=lstyle[1])
        ax[1].plot(data[:,2], data[:,0], label=label, color=lstyle[0], linestyle=lstyle[2], marker=lstyle[1])
        ax[2].plot(data[:,1], data[:,2], label=label, color=lstyle[0], linestyle=lstyle[2], marker=lstyle[1])
        cnt += 1

    for points,label in scatter:
        data = convertData(points)
        c,m = scatterStyle(cnt)
        ax[0].scatter(data[:,1], data[:,0], label=label, c=c, marker=m)
        ax[1].scatter(data[:,2], data[:,0], label=label, c=c, marker=m)
        ax[2].scatter(data[:,1], data[:,2], label=label, c=c, marker=m)
        cnt += 1

    modes = ['Jz-Az', 'Jz-Bz', 'Bz-Az']
    for i in range(3):
        if filename:
            fig[i].savefig(filename.format('jaz-' + modes[i]), bbox_inches='tight')
        if not filename or not save_only:
            fig[i].show()
Example #26
0
print(('\nNormalised primary matrix to "CIE XYZ" '
       'tristimulus values:\n{0}').format(
    colourspace.RGB_to_XYZ_matrix))
print('\nNormalised primary matrix to "ACES2065-1":\n{0}'.format(
    colourspace.XYZ_to_RGB_matrix))
print('\nOpto-electronic transfer function from '
      'linear to colourspace:\n{0}'.format(colourspace.encoding_cctf))
print('\nElectro-optical transfer function from '
      'colourspace to linear:\n{0}'.format(colourspace.decoding_cctf))

print('\n')

message_box(('Computing "ACES2065-1" colourspace to "Rec. 709" colourspace '
             'matrix.'))
cat = colour.chromatic_adaptation_matrix_VonKries(
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['ACES2065-1'].whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['Rec. 709'].whitepoint))
print(np.dot(colour.RGB_COLOURSPACES['Rec. 709'].XYZ_to_RGB_matrix,
             np.dot(cat,
                    colour.RGB_COLOURSPACES['ACES2065-1'].RGB_to_XYZ_matrix)))

print('\n')

RGB = (0.35521588, 0.41000000, 0.24177934)
message_box(('Converting from "Rec. 709" colourspace to "ACEScg" colourspace '
             'given "RGB" values:\n'
             '\n\t{0}'.format(RGB)))
print(colour.RGB_to_RGB(RGB,
                        colour.RGB_COLOURSPACES['Rec. 709'],
                        colour.RGB_COLOURSPACES['ACEScg']))
Example #27
0
print('\n')

message_box('Using "Bradford" CAT.')
print(colour.chromatic_adaptation_matrix_VonKries(
    XYZ_w, XYZ_wr, transform='Bradford'))

print('\n')

message_box(('Computing the chromatic adaptation matrix from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using Von Kries CAT.'))
A = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['A']
D65 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
print(colour.chromatic_adaptation_matrix_VonKries(
    colour.xy_to_XYZ(A),
    colour.xy_to_XYZ(D65),
    transform='Von Kries'))

print('\n')

XYZ = [1.14176346, 1., 0.49815206]
message_box(('Adapting given "CIE XYZ" matrix from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using "Sharp" CAT.\n'
             '\n\t"XYZ":\n\t\t{0}'.format(XYZ)))
print(colour.chromatic_adaptation_VonKries(
    XYZ,
    colour.xy_to_XYZ(A),
    colour.xy_to_XYZ(D65),
    transform='Von Kries'))
message_box('Using "Bradford" CAT.')
print(
    colour.adaptation.chromatic_adaptation_matrix_VonKries(
        XYZ_w, XYZ_wr, transform='Bradford'))

print('\n')

message_box(('Computing the chromatic adaptation matrix from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using "Von Kries" CAT.'))
A = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['A']
D65 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
print(
    colour.adaptation.chromatic_adaptation_matrix_VonKries(
        colour.xy_to_XYZ(A), colour.xy_to_XYZ(D65), transform='Von Kries'))

print('\n')

XYZ = np.array([1.14176346, 1.00000000, 0.49815206])
message_box(('Adapting given "CIE XYZ" tristimulus values from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using "Sharp" CAT.\n'
             '\n\t"XYZ":\n\t\t{0}'.format(XYZ)))
print(
    colour.chromatic_adaptation(
        XYZ, colour.xy_to_XYZ(A), colour.xy_to_XYZ(D65), transform='Sharp'))
print(
    colour.adaptation.chromatic_adaptation_VonKries(
        XYZ, colour.xy_to_XYZ(A), colour.xy_to_XYZ(D65), transform='Sharp'))
Example #29
0
from colour import (Luv_to_uv, Luv_uv_to_xy, UCS_to_uv, UCS_uv_to_xy,
                    xy_to_XYZ, XYZ_to_Luv, XYZ_to_UCS, XYZ_to_xy)

__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__ = ['CHROMATICITY_DIAGRAM_TRANSFORMATIONS', 'Cycle']

CHROMATICITY_DIAGRAM_TRANSFORMATIONS = {
    'CIE 1931': {
        'XYZ_to_ij': lambda a, i: XYZ_to_xy(a, i),
        'ij_to_XYZ': lambda a, i: xy_to_XYZ(a)
    },
    'CIE 1960 UCS': {
        'XYZ_to_ij': lambda a, i: UCS_to_uv(XYZ_to_UCS(a)),
        'ij_to_XYZ': lambda a, i: xy_to_XYZ(UCS_uv_to_xy(a))
    },
    'CIE 1976 UCS': {
        'XYZ_to_ij': lambda a, i: Luv_to_uv(XYZ_to_Luv(a, i), i),
        'ij_to_XYZ': lambda a, i: xy_to_XYZ(Luv_uv_to_xy(a))
    }
}
"""
Chromaticity diagram specific helper conversion objects.

CHROMATICITY_DIAGRAM_TRANSFORMATIONS : dict
    **{'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}**
Example #30
0
message_box('Using "Bradford" CAT.')
print(
    colour.adaptation.matrix_chromatic_adaptation_VonKries(
        XYZ_w, XYZ_wr, transform='Bradford'))

print('\n')

message_box(('Computing the chromatic adaptation matrix from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using "Von Kries" CAT.'))
A = colour.CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['A']
D65 = colour.CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
print(
    colour.adaptation.matrix_chromatic_adaptation_VonKries(
        colour.xy_to_XYZ(A), colour.xy_to_XYZ(D65), transform='Von Kries'))

print('\n')

XYZ = np.array([1.14176346, 1.00000000, 0.49815206])
message_box(('Adapting given "CIE XYZ" tristimulus values from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D65" using "Sharp" CAT.\n'
             '\n\t"XYZ":\n\t\t{0}'.format(XYZ)))
print(
    colour.chromatic_adaptation(XYZ,
                                colour.xy_to_XYZ(A),
                                colour.xy_to_XYZ(D65),
                                transform='Sharp'))
print(
    colour.adaptation.chromatic_adaptation_VonKries(XYZ,
Example #31
0
print(colour.convert(sd_dark_skin, 'Spectral Distribution', 'sRGB'))
print(
    colour.XYZ_to_sRGB(
        colour.sd_to_XYZ(sd_dark_skin,
                         illuminant=colour.SDS_ILLUMINANTS['D65']) / 100))

print('\n')

RGB = np.array([0.45675795, 0.30986982, 0.24861924])
message_box(('Converting to "CAM16-UCS" colourspace from given '
             '"Output-Referred" "sRGB" colourspace values:\n'
             '\n\t{0}'.format(RGB)))
print(colour.convert(RGB, 'Output-Referred RGB', 'CAM16UCS'))
specification = colour.XYZ_to_CAM16(
    colour.sRGB_to_XYZ(RGB) * 100,
    XYZ_w=colour.xy_to_XYZ(
        colour.CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']) *
    100,
    L_A=64 / np.pi * 0.2,
    Y_b=20)
print(
    colour.JMh_CAM16_to_CAM16UCS(
        colour.utilities.tstack([
            specification.J,
            specification.M,
            specification.h,
        ])) / 100)

print('\n')

Jpapbp = np.array([0.39994811, 0.09206558, 0.0812752])
message_box(('Converting to "Output-Referred" "sRGB" colourspace from given '
Example #32
0
print(('\nNormalised primary matrix to "CIE XYZ" '
       'tristimulus values:\n{0}').format(colourspace.RGB_to_XYZ_matrix))
print('\nNormalised primary matrix to "ACES2065-1":\n{0}'.format(
    colourspace.XYZ_to_RGB_matrix))
print('\nOpto-electronic transfer function from '
      'linear to colourspace:\n{0}'.format(colourspace.encoding_cctf))
print('\nElectro-optical transfer function from '
      'colourspace to linear:\n{0}'.format(colourspace.decoding_cctf))

print('\n')

message_box(
    ('Computing "ACES2065-1" colourspace to "ITU-R BT.709" colourspace '
     'matrix.'))
cat = colour.adaptation.chromatic_adaptation_matrix_VonKries(
    colour.xy_to_XYZ(colourspace.whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES['ITU-R BT.709'].whitepoint))
print(
    np.dot(colour.RGB_COLOURSPACES['ITU-R BT.709'].XYZ_to_RGB_matrix,
           np.dot(cat, colourspace.RGB_to_XYZ_matrix)))

print('\n')

RGB = np.array([0.45620519, 0.03081071, 0.04091952])
message_box(
    ('Converting from "ITU-R BT.709" colourspace to "ACEScg" colourspace '
     'given "RGB" values:\n'
     '\n\t{0}'.format(RGB)))
print(
    colour.RGB_to_RGB(
        RGB,
print(colour.xyY_to_XYZ(xyY))

print('\n')

message_box(('Converting to "xy" chromaticity coordinates from given '
             '"CIE XYZ" tristimulus values:\n'
             '\n\t{0}'.format(XYZ)))
print(colour.XYZ_to_xy(XYZ))

print('\n')

xy = (0.43250000, 0.37880000)
message_box(('Converting to "CIE XYZ" tristimulus values from given "xy" '
             'chromaticity coordinates:\n'
             '\n\t{0}'.format(xy)))
print(colour.xy_to_XYZ(xy))

print('\n')

message_box(('Converting to "RGB" colourspace from given "CIE XYZ" '
             'tristimulus values:\n'
             '\n\t{0}'.format(XYZ)))
D50 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50']
print(
    colour.XYZ_to_RGB(XYZ, D50, colour.sRGB_COLOURSPACE.whitepoint,
                      colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix, 'Bradford',
                      colour.sRGB_COLOURSPACE.encoding_cctf))

print('\n')

RGB = (1.26651054, 0.91394181, 0.76936593)
Example #34
0
    def load(self):
        """
        Syncs, parses, converts and returns the *Hung and Berns (1995)*
        *Constant Hue Loci Data* dataset content.

        Returns
        -------
        OrderedDict
            *Hung and Berns (1995)* *Constant Hue Loci Data* dataset content.

        Examples
        --------
        >>> from colour_datasets.utilities import suppress_stdout
        >>> dataset = DatasetLoader_Hung1995()
        >>> with suppress_stdout():
        ...     dataset.load()
        >>> len(dataset.content.keys())
        6
        """

        super(DatasetLoader_Hung1995, self).sync()

        self._content = OrderedDict()

        filenames = OrderedDict([
            ('Table I.csv', 'Reference colors.'),
            ('Table II.csv', 'Intra- and interobserver variances for each '
             'reference hue expressed in circumferential '
             'hue-angle difference.'),
            ('Table III.csv', 'Weight-averaged constant hue loci for the CL '
             'experiment.'),
            ('Table IV.csv', 'Weight-averaged constant hue loci for the VL '
             'experiment.'),
        ])

        for filename in filenames:
            datafile_path = os.path.join(self.record.repository, 'dataset',
                                         filename)

            self._content[filename.split('.')[0]] = np.genfromtxt(
                datafile_path,
                delimiter=',',
                names=True,
                dtype=None,
                encoding='utf-8')

        hues = [
            'Red', 'Red-yellow', 'Yellow', 'Yellow-green', 'Green',
            'Green-cyan', 'Cyan', 'Cyan-blue', 'Blue', 'Blue-magenta',
            'Magenta', 'Magenta-red'
        ]

        XYZ_r = xy_to_XYZ(
            CCS_ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['C'])

        for table, experiment in [('Table III', 'CL'), ('Table IV', 'VL')]:
            key = 'Constant Hue Loci Data - {0}'.format(experiment)
            self._content[key] = OrderedDict()
            for hue in hues:
                for sample_r in self._content['Table I']:
                    sample_r = sample_r.tolist()
                    if sample_r[0] == hue:
                        XYZ_cr = xyY_to_XYZ(sample_r[1:4]) / 100
                        break

                XYZ_ct = []
                metadata = {
                    'Color name': [],
                    'C*uv': [],
                }
                for sample_t in self._content[table]:
                    sample_t = sample_t.tolist()
                    if not sample_t[0] == hue:
                        continue

                    XYZ_ct.append(sample_t[2:])
                    metadata['Color name'].append(sample_t[0])
                    metadata['C*uv'].append(sample_t[1])

                self._content[key][hue] = (
                    ConstantPerceivedHueColourMatches_Hung1995(
                        hue, XYZ_r, XYZ_cr,
                        np.vstack(XYZ_ct) / 100, metadata))

        return self._content
Example #35
0
    f"\nOpto-electronic transfer function from linear to colourspace:\n"
    f"{colourspace.cctf_encoding}"
)
print(
    f"\nElectro-optical transfer function from colourspace to linear:\n"
    f"{colourspace.cctf_decoding}"
)

print("\n")

message_box(
    'Computing the "ACES2065-1" colourspace to "ITU-R BT.709" colourspace '
    "matrix."
)
cat = colour.adaptation.matrix_chromatic_adaptation_VonKries(
    colour.xy_to_XYZ(colourspace.whitepoint),
    colour.xy_to_XYZ(colour.RGB_COLOURSPACES["ITU-R BT.709"].whitepoint),
)
print(
    np.dot(
        colour.RGB_COLOURSPACES["ITU-R BT.709"].matrix_XYZ_to_RGB,
        np.dot(cat, colourspace.matrix_RGB_to_XYZ),
    )
)

print("\n")

RGB = np.array([0.45620519, 0.03081071, 0.04091952])
message_box(
    f'Converting from the "ITU-R BT.709" colourspace to the "ACEScg" '
    f'colourspace given "RGB" values:\n\n\t{RGB}'
Example #36
0
    [0.45079660, 0.52288689],
    [0.19124902, 0.55444488],
    [0.13128455, 0.51210591],
    [0.14889223, 0.37091478],
    [0.28992574, 0.30964533],
]
swatches_XYZ = []
for patch in swatches:
    in_XYZ = colour.Luv_to_XYZ(colour.uv_to_Luv(patch))
    swatches_XYZ.append(in_XYZ * (average_luminance / in_XYZ[1]))

# Adapting Luminance, 250 cd/m^2 represents a typical modern computer
# display peak luminance.
L_a = 250 * average_luminance

bg_grey = colour.xy_to_XYZ(colour.Luv_uv_to_xy(wp)) * average_luminance

swatches_normal = []
swatches_VCC = []
swatches_VAC = []

for i in range(len(swatches)):
    VCC = colour.HelmholtzKohlrausch_effect_luminous_Nayatani1997(swatches[i],
                                                                  wp,
                                                                  L_a,
                                                                  method="VCC")
    VAC = colour.HelmholtzKohlrausch_effect_luminous_Nayatani1997(swatches[i],
                                                                  wp,
                                                                  L_a,
                                                                  method="VAC")
Example #37
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Showcases correlated colour temperature computations.
"""

import colour
from colour.utilities.verbose import message_box

message_box('Correlated Colour Temperature Computations')

cmfs = colour.CMFS['CIE 1931 2 Degree Standard Observer']
illuminant = colour.ILLUMINANTS_RELATIVE_SPDS['D65']
xy = colour.XYZ_to_xy(colour.spectral_to_XYZ(illuminant, cmfs))
uv = colour.UCS_to_uv(colour.XYZ_to_UCS(colour.xy_to_XYZ(xy)))
message_box(('Converting to "CCT" and "Duv" from given "CIE UCS" colourspace '
             '"uv" chromaticity coordinates using "Yoshi Ohno (2013)" '
             'method:\n'
             '\n\t{0}'.format(uv)))
print(colour.uv_to_CCT_ohno2013(uv, cmfs=cmfs))
print(colour.uv_to_CCT(uv, cmfs=cmfs))

print('\n')

message_box('Faster computation with 3 iterations but a lot less precise.')
print(colour.uv_to_CCT_ohno2013(uv, cmfs=cmfs, iterations=3))

print('\n')

message_box(('Converting to "CCT" and "Duv" from given "CIE UCS" colourspace '
Example #38
0
print(colour.xyY_to_XYZ(xyY))

print('\n')

message_box(('Converting to "xy" chromaticity coordinates from given '
             '"CIE XYZ" colourspace values:\n'
             '\n\t{0}'.format(XYZ)))
print(colour.XYZ_to_xy(XYZ))

print('\n')

xy = (0.43249999995420696, 0.378800000065942)
message_box(('Converting to "CIE XYZ" colourspace from given "xy" '
             'chromaticity coordinates:\n'
             '\n\t{0}'.format(xy)))
print(colour.xy_to_XYZ(xy))

print('\n')

message_box(('Converting to "RGB" colourspace from given "CIE XYZ" '
             'colourspace values:\n'
             '\n\t{0}'.format(XYZ)))
print(colour.XYZ_to_RGB(
    XYZ,
    colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50'],
    colour.sRGB_COLOURSPACE.whitepoint,
    colour.sRGB_COLOURSPACE.XYZ_to_RGB_matrix,
    'Bradford',
    colour.sRGB_COLOURSPACE.transfer_function))

print('\n')
__status__ = 'Production'

__all__ = [
    'POINTER_GAMUT_DATA', 'POINTER_GAMUT_BOUNDARIES', 'pointer_gamut_visual',
    'pointer_gamut_boundaries_visual', 'pointer_gamut_hull_visual'
]

POINTER_GAMUT_DATA = Lab_to_XYZ(LCHab_to_Lab(POINTER_GAMUT_DATA),
                                POINTER_GAMUT_ILLUMINANT)
"""
Pointer's Gamut data converted to *CIE XYZ* tristimulus values.

POINTER_GAMUT_DATA : ndarray
"""

POINTER_GAMUT_BOUNDARIES = xy_to_XYZ(POINTER_GAMUT_BOUNDARIES)
"""
Pointer's Gamut boundaries data converted to *CIE XYZ* tristimulus values.

POINTER_GAMUT_BOUNDARIES : ndarray
"""


def pointer_gamut_visual(reference_colourspace='CIE xyY',
                         size=4.0,
                         edge_size=0.5,
                         uniform_colour=(0.9, 0.9, 0.9),
                         uniform_opacity=0.8,
                         uniform_edge_colour=(0.9, 0.9, 0.9),
                         uniform_edge_opacity=0.8,
                         parent=None):
message_box('Using "Bradford" CAT.')
print(
    colour.adaptation.matrix_chromatic_adaptation_VonKries(
        XYZ_w, XYZ_wr, transform="Bradford"))

print("\n")

message_box(
    "Computing the chromatic adaptation matrix from "
    'the "CIE Standard Illuminant A" to '
    'the "CIE Standard Illuminant D Series D65" using the "Von Kries" CAT.')
A = colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["A"]
D65 = colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"]
print(
    colour.adaptation.matrix_chromatic_adaptation_VonKries(
        colour.xy_to_XYZ(A), colour.xy_to_XYZ(D65), transform="Von Kries"))

print("\n")

XYZ = np.array([1.14176346, 1.00000000, 0.49815206])
message_box(
    f'Adapting given "CIE XYZ" tristimulus values from '
    f'the "CIE Standard Illuminant A" to the '
    f'"CIE Standard Illuminant D Series D65" using the "Sharp" CAT.\n\n'
    f'\t"XYZ": {XYZ}')
print(
    colour.chromatic_adaptation(XYZ,
                                colour.xy_to_XYZ(A),
                                colour.xy_to_XYZ(D65),
                                transform="Sharp"))
print(
Example #41
0
import colour
from colour.utilities import message_box

message_box('"CIE 1994" Chromatic Adaptation Model Computations')

XYZ_1 = np.array([0.2800, 0.2126, 0.0527])
xy_o1 = np.array([0.4476, 0.4074])
xy_o2 = np.array([0.3127, 0.3290])
Y_o = 20
E_o1 = 1000
E_o2 = 1000
message_box(('Computing chromatic adaptation using "CIE 1994" chromatic '
             'adaptation model.\n'
             '\n\t"XYZ_1":\n\t\t{0}\n\t"xy_o1":\n\t\t{1}\n\t"xy_o2":\n\t\t{2}'
             '\n\t"Y_o":\n\t\t{3}\n\t"E_o1":\n\t\t{4}'
             '\n\t"E_o2":\n\t\t{5}\n\n'
             'Warning: The input domain and output range of that definition '
             'are non standard!'.format(XYZ_1, xy_o1, xy_o2, Y_o, E_o1, E_o2)))
print(
    colour.chromatic_adaptation(
        XYZ_1,
        colour.xy_to_XYZ(xy_o1),
        colour.xy_to_XYZ(xy_o2),
        method='CIE 1994',
        Y_o=Y_o,
        E_o1=E_o1,
        E_o2=E_o2))
print(
    colour.adaptation.chromatic_adaptation_CIE1994(XYZ_1 * 100.0, xy_o1, xy_o2,
                                                   Y_o, E_o1, E_o2) / 100.0)
Example #42
0
import colour
from colour.utilities.verbose import message_box

message_box('Chromatic Adaptation Computations')

XYZ1 = (1.09923822, 1.000, 0.35445412)
XYZ2 = (0.96907232, 1.000, 1.121792157)
message_box(('Computing the chromatic adaptation matrix from two source '
             '"CIE XYZ" matrices, default CAT is "CAT02".\n'
             '\n\t"XYZ1":\n\t\t{0}\n\t"XYZ2":\n\t\t{1}'.format(XYZ1, XYZ2)))
print(colour.chromatic_adaptation_matrix(XYZ1, XYZ2))

print('\n')

message_box('Using "Bradford" CAT.')
print(colour.chromatic_adaptation_matrix(XYZ1, XYZ2, method='Bradford'))

print('\n')

message_box(('Computing the chromatic adaptation matrix from '
             '"CIE Standard Illuminant A" to '
             '"CIE Standard Illuminant D Series D60" using "Von Kries" CAT.'))
A = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['A']
D60 = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D60']

print(colour.chromatic_adaptation_matrix(
    colour.xy_to_XYZ(A),
    colour.xy_to_XYZ(D60),
    method='Von Kries'))