Example #1
0
def make_ebu_color_patch_from_yuv():
    yuv_file = "./doc/ebu_test_colour_value.csv"
    ycbcr = np.loadtxt(yuv_file, delimiter=",", skiprows=1, usecols=(2, 3, 4))
    yuv = cc.ycbcr_to_yuv(ycbcr, bit_depth=10)

    rgb2yuv_mtx = [[0.2126, 0.7152, 0.0722],
                   [-0.2126 / 1.8556, -0.7152 / 1.8556, 0.9278 / 1.8556],
                   [0.7874 / 1.5748, -0.7152 / 1.5748, -0.0722 / 1.5748]]
    yuv2rgb_mtx = linalg.inv(np.array(rgb2yuv_mtx))
    print(yuv2rgb_mtx)
    yuv2rgb_mtx = np.array(yuv2rgb_mtx)

    rgb_dash = cc.color_cvt(yuv.reshape((1, yuv.shape[0], yuv.shape[1])),
                            yuv2rgb_mtx)
    rgb_dash = rgb_dash.reshape((rgb_dash.shape[1], rgb_dash.shape[2]))
    # rgb_dash = np.uint8(np.round(rgb_dash * 0xFF))
    # plot_color_patch(rgb_dash, v_num=3, h_num=5)

    rgb = rgb_dash**2.35
    rgb_name = 'ITU-R BT.709'
    illuminant_XYZ = colour.RGB_COLOURSPACES[rgb_name].whitepoint
    illuminant_RGB = colour.RGB_COLOURSPACES[rgb_name].whitepoint
    chromatic_adaptation_transform = 'Bradford'
    rgb_to_xyz_mtx = colour.RGB_COLOURSPACES[rgb_name].RGB_to_XYZ_matrix
    large_xyz = colour.RGB_to_XYZ(rgb, illuminant_XYZ, illuminant_RGB,
                                  rgb_to_xyz_mtx,
                                  chromatic_adaptation_transform)
    large_ucs = colour.XYZ_to_UCS(large_xyz)
    uv = colour.UCS_to_uv(large_ucs)
    uv[:, 1] = uv[:, 1] * 3 / 2
    print(uv)
Example #2
0
def XYZ_xyz_Luv_uv_Tc_lum_Eff_lum_KPD(spd, T_method='Robertson1968'):
    cmfs = colour.STANDARD_OBSERVERS_CMFS[
        'CIE 1931 2 Degree Standard Observer']
    # illuminant = colour.ILLUMINANTS_RELATIVE_SPDS['A']
    XYZ = colour.spectral_to_XYZ(spd, cmfs)
    x, y = colour.XYZ_to_xy(XYZ / 100)
    xyz = [x, y, 1 - x - y]
    Luv = colour.XYZ_to_Luv(XYZ)
    uv = colour.UCS_to_uv(colour.XYZ_to_UCS(XYZ))

    if T_method == 'Robertson1968':
        CCT, _D_uv = colour.uv_to_CCT_Robertson1968(uv)
    elif T_method == 'Ohno2013':
        CCT, _D_uv = colour.uv_to_CCT_Ohno2013(uv)

    Tc = [CCT, _D_uv]
    lum_Eff = colour.luminous_efficacy(spd)
    lum_KPD = colour.luminous_efficiency(spd)
    return (XYZ, xyz, Luv, uv, Tc, lum_Eff, lum_KPD)
Example #3
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)))
print(colour.XYZ_to_UCS(XYZ))

print('\n')

UCS = (0.76117564, 1.00000000, 1.17819430)
message_box(('Converting to "CIE XYZ" tristimulus values from given "CIE UCS" '
             'colourspace values:\n'
             '\n\t{0}'.format(UCS)))
print(colour.UCS_to_XYZ(UCS))

print('\n')

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

print('\n')

uv = (0.25895878, 0.34020896)
message_box(('Converting to "xy" chromaticity coordinates from given '
             '"CIE UCS" colourspace "uv" chromaticity coordinates:\n'
             '\n\t{0}'.format(uv)))
print(colour.UCS_uv_to_xy(uv))

print('\n')

message_box(('Converting to "CIE UVW" colourspace from given "CIE XYZ" '
             'tristimulus values:\n'
             '\n\t{0}'.format(XYZ)))
print(colour.XYZ_to_UVW(XYZ))
Example #5
0
def calc_temperature(dominant_color):
    XYZ = colour.sRGB_to_XYZ(dominant_color / 255)
    uv = colour.UCS_to_uv(colour.XYZ_to_UCS(XYZ))
    temperature = colour.uv_to_CCT_Robertson1968(uv)
    return 1 - (min(temperature[0], MAX) / MAX)