Exemplo n.º 1
0
def spectrum_to_XYZ(domain, values):
    """ Converts a spectral distribution into a XYZ colour """
    spd = colour.SpectralPowerDistribution(
        values, domain=domain, interpolator=colour.NullInterpolator)
    cmfs = colour.STANDARD_OBSERVERS_CMFS[
        'CIE 1931 2 Degree Standard Observer']
    illuminant = colour.ILLUMINANTS_RELATIVE_SPDS['D65']
    return colour.spectral_to_XYZ(spd, cmfs, illuminant)
Exemplo n.º 2
0
def calculateColorValues(splineT, splineR, settings):
    '''Function calculates color values of the Transmission and Refelection side of the stack. 
    Input Arguments are tranmission and reflection spline functions.
    Returns array of values/tuples of different standards.'''
    import colour
    import numpy as np
    wvl = np.linspace(380, 780, 81)
    dic_T = {}
    dic_R = {}
    dic_test = {}
    for idx, value in enumerate(wvl):
        dic_T[value] = splineT(value).item()
        dic_R[value] = splineR(value).item()

    #Removes warnings from conversions.
    colour.filter_warnings()
    cmfs = colour.STANDARD_OBSERVERS_CMFS[settings.color_cmfs]  #1931 etc
    illuminant = colour.ILLUMINANTS_RELATIVE_SPDS[
        settings.color_illuminant]  #D65, A, C

    T_spd = colour.SpectralPowerDistribution('', dic_T)
    T_XYZ = colour.spectral_to_XYZ(T_spd, cmfs, illuminant)
    T_xy = colour.XYZ_to_xy(T_XYZ / 100)
    T_ab = colour.XYZ_to_Lab(T_XYZ / 100,
                             illuminant=colour.ILLUMINANTS[settings.color_cmfs]
                             [settings.color_illuminant])
    T_rgb = colour.XYZ_to_sRGB(
        T_XYZ / 100,
        illuminant=colour.ILLUMINANTS[settings.color_cmfs][
            settings.color_illuminant])

    R_spd = colour.SpectralPowerDistribution('', dic_R)
    R_XYZ = colour.spectral_to_XYZ(R_spd, cmfs, illuminant)
    R_xy = colour.XYZ_to_xy(R_XYZ / 100)
    R_ab = colour.XYZ_to_Lab(R_XYZ / 100,
                             illuminant=colour.ILLUMINANTS[settings.color_cmfs]
                             [settings.color_illuminant])
    R_rgb = colour.XYZ_to_sRGB(
        R_XYZ / 100,
        illuminant=colour.ILLUMINANTS[settings.color_cmfs][
            settings.color_illuminant])

    return (T_XYZ, T_xy, T_ab, T_rgb, R_XYZ, R_xy, R_ab, R_rgb)
Exemplo n.º 3
0
def mutiple():
    cmfs = CMFS['CIE 1931 2 Degree Standard Observer']
    spd = []
    for d in ['test.txt', 'test1.txt']:
        with open(d) as f:
            data = pd.read_csv(f, sep="\t" or ' ' or ',', header=None)
            f.close()
        w = [i[0] for i in data.values]
        s = [i[1] for i in data.values]
        data_formated = dict(zip(w, s))
        spd.append(SpectralPowerDistribution('Sample', data_formated))
    b = multi_spd_plot(spd,
                       standalone=False,
                       figure_size=(5, 5),
                       title='Spectrum')
    figfile_b = StringIO()
    b.savefig(figfile_b, format='svg')
    figfile_b.seek(0)
    figdata_svg_b = '<svg' + figfile_b.getvalue().split('<svg')[1]
    b.clf()
    plot.close(b)

    CIE_1931_chromaticity_diagram_plot(standalone=False,
                                       figure_size=(5, 5),
                                       grid=False,
                                       title='CIE 1931 Chromaticity Diagram',
                                       bounding_box=(-0.1, 0.9, -0.05, 0.95))
    illuminant = ILLUMINANTS_RELATIVE_SPDS['D50']
    for s in spd:
        XYZ = spectral_to_XYZ(s, cmfs, illuminant)
        xy = XYZ_to_xy(XYZ)
        print(xy)

        x, y = xy
        pylab.plot(x, y, 'o-', color='white')
        pylab.annotate((("%.4f" % x), ("%.4f" % y)),
                       xy=xy,
                       xytext=(-50, 30),
                       textcoords='offset points',
                       arrowprops=dict(arrowstyle='->',
                                       connectionstyle='arc3, rad=-0.2'))

    a = plot.gcf()
    figfile = StringIO()
    a.savefig(figfile, format='svg')
    figfile.seek(0)
    figdata_svg = '<svg' + figfile.getvalue().split('<svg')[1]
    a.clf()
    plot.close(a)
    del a, b
    # pprint.pprint(figdata_svg)
    return render_template('index.html', spd=figdata_svg_b, result=figdata_svg)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    755: 0.450,
    760: 0.462,
    765: 0.465,
    770: 0.448,
    775: 0.432,
    780: 0.421
}

spd = colour.SpectralPowerDistribution('Sample', sample_spd_data)

cmfs = colour.CMFS['CIE 1931 2 Degree Standard Observer']
illuminant = colour.ILLUMINANTS_RELATIVE_SPDS['A']

message_box(('Computing *CIE XYZ* tristimulus values for sample spectral '
             'power distribution and "CIE Standard Illuminant A".'))
print(colour.spectral_to_XYZ(spd, cmfs, illuminant))

print('\n')

message_box(('Computing "CIE Standard Illuminant A" chromaticity coordinates '
             'from its relative spectral power distribution.'))
print(colour.XYZ_to_xy(colour.spectral_to_XYZ(illuminant, cmfs)))

print('\n')

message_box(('Computing *CIE XYZ* tristimulus values for a single given '
             'wavelength in nm.'))
print(
    colour.wavelength_to_XYZ(
        546.1, colour.CMFS['CIE 1931 2 Degree Standard Observer']))
Exemplo n.º 6
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 '
Exemplo n.º 7
0
mLConvert = .05 / mL.shape[1]


#Need to do own michel-levy chart
def mlEQ(lam, ret):
    '''lam: wavelength in nanometers
        ret: retardence in microns'''
    return np.sin(np.pi * ret / lam * 10**3)**2.


lamL = np.arange(360, 830, 5)
retL = np.arange(.05, 0.3, .0001) * 5
I = np.array([[mlEQ(lam, ret) for lam in lamL] for ret in retL])
XYZ = [
    colour.spectral_to_XYZ(colour.SpectralPowerDistribution(
        {lam: i
         for (lam, i) in zip(lamL, iL)}),
                           illuminant=colour.ILLUMINANTS_RELATIVE_SPDS["D65"])
    for iL in I
]
ilA = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer'][
    'D65']  #don't really know what this is, but I think I'm using a halogen lamp
M = np.array([[2.04414, -.5649, -0.3447], [-0.9693, 1.8760, 0.0416],
              [0.0134, -0.1184, 1.0154]])
#RGB = [list(colour.XYZ_to_RGB(xyz/100,ilA,ilA,M)) for xyz in XYZ]
sRGB = [list(colour.XYZ_to_sRGB(xyz / 100)) for xyz in XYZ]
#psd = {lam:i for (lam,i) in zip(lamL,I)}
#psd = colour.SpectralPowerDistribution(psd)
#XYZ = colour.spectral_to_XYZ(psd)
#mlChart = np.array([[i for i in RGB] for j in np.arange(0,1000)])
mlChart2 = np.array([[i for i in sRGB] for j in np.arange(0, 200)])
fig10, ax10 = plt.subplots()
Exemplo n.º 8
0
from iminuit.util import make_func_code # lo utiliza Chi2Functor
from math import pi, exp, sqrt
#import colour.colorimetry as colorimetry

"""
Conviete valores RGB cualquiera, dado como constante, a xy y lo grafica como un punto dentro chromaticity diagram standar 
"""
from colour.plotting import (
    colour_plotting_defaults, chromaticity_diagram_plot_CIE1931,render,single_spd_plot)

# Defining a sample spectral power distribution data.
sample_spd_data = {380+i*5: random() for i in range(80)}
spd = colour.SpectralPowerDistribution(sample_spd_data)
single_spd_plot(spd)
cmfs = colour.STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer']
XYZ = colour.spectral_to_XYZ(spd, cmfs)
#ch1=colour.XYZ_to_spectral(XYZ,Method='Meng 2015')
ch1=colour.XYZ_to_spectral(XYZ,Method='Smits 1999')
single_spd_plot(ch1)
#spd_rec=ch1.values
y=ch1.values
x=[360+i*5 for i in range(95)]
#for i, v in enumerate(spd_rec):
#    x=360+i*5
#    y=v
#this is very useful if you want to build a generic cost functor
#this is actually how probfit is implemented
#x=sorted(sample_spd_data.keys())
#y=sorted(sample_spd_data.values())
class Chi2Functor:
    def __init__(self,f,x,y):
Exemplo n.º 9
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Showcases blackbody / planckian radiator computations.
"""

import colour
from colour.utilities.verbose import message_box

message_box('Blackbody / Planckian Radiator Computations')

message_box(('Computing the spectral radiance of a blackbody at wavelength '
             '500 nm and temperature 5500 kelvin degrees.'))
print(colour.planck_law(500 * 1e-9, 5500))

print('\n')

message_box(('Computing the spectral power distribution of a blackbody at '
             'temperature 5500 kelvin degrees and converting to "CIE XYZ" '
             'tristimulus values.'))
cmfs = colour.STANDARD_OBSERVERS_CMFS['CIE 1931 2 Degree Standard Observer']
blackbody_spd = colour.blackbody_spd(5500, cmfs.shape)
print(blackbody_spd)
XYZ = colour.spectral_to_XYZ(blackbody_spd, cmfs)
print(XYZ)
Exemplo n.º 10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Showcases blackbody / planckian radiator computations.
"""

from __future__ import division, unicode_literals

import colour
from colour.utilities.verbose import message_box

message_box('Blackbody / Planckian Radiator Computations')

message_box(('Computing the spectral radiance of a blackbody at wavelength '
            '500 nm and temperature 5500 kelvin degrees.'))
print(colour.planck_law(500 * 1e-9, 5500))

print('\n')

message_box(('Computing the spectral power distribution of a blackbody at '
            'temperature 5500 kelvin degrees and converting to "CIE XYZ" '
            'tristimulus values.'))
cmfs = colour.STANDARD_OBSERVERS_CMFS.get(
    'CIE 1931 2 Degree Standard Observer')
blackbody_spd = colour.blackbody_spd(5500, cmfs.shape)
print(blackbody_spd)
XYZ = colour.spectral_to_XYZ(blackbody_spd, cmfs)
print(XYZ)
Exemplo n.º 11
0
def index():
    cmfs = CMFS['CIE 1931 2 Degree Standard Observer']
    with open('test.txt') as f:
        data = pd.read_csv(f, sep="\t" or ' ' or ',', header=None)
        f.close()
    w = [i[0] for i in data.values]
    s = [i[1] for i in data.values]
    data_formated = dict(zip(w, s))
    spd = SpectralPowerDistribution('Sample', data_formated)
    b = single_spd_plot(spd,
                        standalone=False,
                        figure_size=(5, 5),
                        title='Spectrum')
    figfile_b = StringIO()
    b.savefig(figfile_b, format='svg')
    figfile_b.seek(0)
    figdata_svg_b = '<svg' + figfile_b.getvalue().split('<svg')[1]
    b.clf()
    plot.close(b)
    illuminant = ILLUMINANTS_RELATIVE_SPDS['D50']
    XYZ = spectral_to_XYZ(spd, cmfs, illuminant)
    xy = XYZ_to_xy(XYZ)
    print(xy)
    cct = xy_to_CCT(xy)
    print(cct)
    cri = colour_rendering_index(spd, additional_data=True)
    print(cri.Q_a)
    Q_as = cri.Q_as
    y = [s[1].Q_a for s in sorted(Q_as.items(), key=lambda s: s[0])]
    print(y)
    single_spd_colour_rendering_index_bars_plot(spd,
                                                standalone=False,
                                                figure_size=(7, 7),
                                                title='Colour rendering index')
    c = plot.gcf()
    figfile_c = StringIO()
    c.savefig(figfile_c, format='svg')
    figfile_c.seek(0)
    figdata_svg_c = '<svg' + figfile_c.getvalue().split('<svg')[1]
    c.clf()
    plot.close(c)

    CIE_1931_chromaticity_diagram_plot(standalone=False,
                                       figure_size=(6, 5),
                                       grid=False,
                                       title='CIE 1931 Chromaticity Diagram',
                                       bounding_box=(-0.1, 0.9, -0.05, 0.95))
    x, y = xy
    pylab.plot(x, y, 'o-', color='white')
    pylab.annotate((("%.4f" % x), ("%.4f" % y)),
                   xy=xy,
                   xytext=(-50, 30),
                   textcoords='offset points',
                   arrowprops=dict(arrowstyle='->',
                                   connectionstyle='arc3, rad=-0.2'))

    a = plot.gcf()
    figfile = StringIO()
    a.savefig(figfile, format='svg')
    figfile.seek(0)
    figdata_svg = '<svg' + figfile.getvalue().split('<svg')[1]
    a.clf()
    plot.close(a)
    del a, b, c
    # pprint.pprint(figdata_svg)
    return render_template('index.html',
                           spd=figdata_svg_b,
                           result=figdata_svg,
                           colour_rendering_index=figdata_svg_c)
Exemplo n.º 12
0
def LED_3D(l_red, l_green, l_blue, T, h, spd3_name, image):
    def aprocsimate_CIA(l0, l05):
        sample_spd_data = {}
        for lamb in np.arange(200, 800, 0.9):
            g = np.exp(-((lamb - l0) / l05)**2)
            Phi_led = (g + 2 * g**5) / 3
            sample_spd_data[lamb] = float(Phi_led)
        return sample_spd_data

    def colour_spectr(sample_spd_data, name):
        spd = colour.SpectralPowerDistribution(name, sample_spd_data)
        spd.interpolate(colour.SpectralShape(200, 800, 1))
        return spd

    spd_red0 = aprocsimate_CIA(l_red[0], l_red[1])
    spd_green0 = aprocsimate_CIA(l_green[0], l_green[1])
    spd_blue0 = aprocsimate_CIA(l_blue[0], l_blue[1])

    spd_red = colour_spectr(spd_red0, 'red')
    spd_green = colour_spectr(spd_green0, 'green')
    spd_blue = colour_spectr(spd_blue0, 'blue')

    blackbody_spd = colour.blackbody_spd(T)

    cmfs = colour.STANDARD_OBSERVERS_CMFS[
        'CIE 1931 2 Degree Standard Observer']
    # # # # Calculating the sample spectral power distribution *CIE XYZ* tristimulus values.
    XYZ_blackbody = colour.spectral_to_XYZ(blackbody_spd, cmfs)

    XYZ_red = colour.spectral_to_XYZ(spd_red, cmfs)
    XYZ_green = colour.spectral_to_XYZ(spd_green, cmfs)
    XYZ_blue = colour.spectral_to_XYZ(spd_blue, cmfs)

    #print(XYZ_blackbody,XYZ_red,XYZ_green,XYZ_blue)
    XYZ = np.vstack((XYZ_red, XYZ_green, XYZ_blue))
    XYZ = XYZ.transpose()
    XYZ = np.linalg.inv(XYZ)
    XYZ_blackbody = XYZ_blackbody.transpose()
    abc = np.dot(XYZ, XYZ_blackbody)
    abc = abc / max(abc)

    def spectr_LED(abc, spd_red0, spd_green0, spd_blue0):
        sample_spd_data = {}
        a, b, c = abc[0], abc[1], abc[2]
        for lamb in np.arange(200, 800, 0.9):
            chip_3d = a * spd_red0[lamb] + b * spd_green0[
                lamb] + c * spd_blue0[lamb]
            sample_spd_data[lamb] = float(chip_3d)
        spd = colour.SpectralPowerDistribution('Sample', sample_spd_data)
        spd.interpolate(colour.SpectralShape(200, 800, 1))
        return spd

    spd_3 = [spd_red, spd_green, spd_blue]
    spd_3d = spectr_LED(abc, spd_red0, spd_green0, spd_blue0)
    b1, b2, b3 = abc[0], abc[1], abc[2]
    c1 = 1
    c2 = (b2 / b1) * (l_red[0] / l_green[0])
    c3 = (b3 / b1) * (l_red[0] / l_blue[0])
    h1, h2, h3 = h[0], h[1], h[2]
    h_sum = (c1 * h1 + c2 * h2 + c3 * h3) / (c1 + c2 + c3)
    multi_spd_plot(spd_3, bounding_box=[300, 800, 0, 1], filename=spd3_name)
    image.append(spd3_name)
    return spd_3, spd_3d, h_sum, image, abc
Exemplo n.º 13
0
def LED_4D(l_red, l_green, l_blue, l_yellow, T, a, h, spd4_name, image, Fi_4d,
           Fi_red, Fi_green, Fi_blue, Fi_yellow):

    spd_red0 = aprocsimate_CIA(l_red[0], l_red[1])
    spd_green0 = aprocsimate_CIA(l_green[0], l_green[1])
    spd_blue0 = aprocsimate_CIA(l_blue[0], l_blue[1])
    spd_yellow0 = aprocsimate_CIA(l_yellow[0], l_yellow[1])

    spd_red = colour_spectr(spd_red0, 'red')
    spd_green = colour_spectr(spd_green0, 'green')
    spd_blue = colour_spectr(spd_blue0, 'blue')
    spd_yellow = colour_spectr(spd_yellow0, 'yellow')

    blackbody_spd = colour.blackbody_spd(T)
    #single_spd_plot(blackbody_spd)
    cmfs = colour.STANDARD_OBSERVERS_CMFS[
        'CIE 1931 2 Degree Standard Observer']
    # # # # Calculating the sample spectral power distribution *CIE XYZ* tristimulus values.

    blackbody_spd.normalise()

    XYZ_blackbody = colour.spectral_to_XYZ(blackbody_spd, cmfs)

    XYZ_red = colour.spectral_to_XYZ(spd_red, cmfs)
    XYZ_green = colour.spectral_to_XYZ(spd_green, cmfs)
    XYZ_blue = colour.spectral_to_XYZ(spd_blue, cmfs)
    XYZ_yellow = colour.spectral_to_XYZ(spd_yellow, cmfs)

    XYZ_blackbody[0] = XYZ_blackbody[0] - XYZ_yellow[0] * a
    XYZ_blackbody[1] = XYZ_blackbody[1] - XYZ_yellow[1] * a
    XYZ_blackbody[2] = XYZ_blackbody[2] - XYZ_yellow[2] * a

    #print(XYZ_blackbody,XYZ_red,XYZ_green,XYZ_blue)
    XYZ = np.vstack((XYZ_red, XYZ_green, XYZ_blue))
    XYZ = XYZ.transpose()
    XYZ = np.linalg.inv(XYZ)
    XYZ_blackbody = XYZ_blackbody.transpose()
    abc = np.dot(XYZ, XYZ_blackbody)
    abca = [abc[0], abc[1], abc[2], a]
    #abca=abca/max(abca)

    spd_4 = [spd_red, spd_green, spd_blue, spd_yellow]
    spd_4d = spectr_LED4(abca, spd_red0, spd_green0, spd_blue0, spd_yellow0)
    b1, b2, b3, b4 = abca[0], abca[1], abca[2], abca[3]
    c1 = 1
    c2 = (b2 / b1) * (l_red[0] / l_green[0])
    c3 = (b3 / b1) * (l_red[0] / l_blue[0])
    c4 = (b4 / b1) * (l_red[0] / l_yellow[0])
    h1, h2, h3, h4 = h[0], h[1], h[2], h[3]
    h_sum = (c1 * h1 + c2 * h2 + c3 * h3 + c4 * h4) / (c1 + c2 + c3 + c4)
    multi_spd_plot(spd_4, bounding_box=[300, 800, 0, 1], filename=spd4_name)
    image.append(spd4_name)

    from colour.colorimetry import PHOTOPIC_LEFS

    lef = PHOTOPIC_LEFS.get('CIE 1924 Photopic Standard Observer')
    lef_4d = lef.clone().align(spd_4d.shape,
                               extrapolation_left=0,
                               extrapolation_right=0)
    lef_red = lef.clone().align(spd_red.shape,
                                extrapolation_left=0,
                                extrapolation_right=0)
    lef_green = lef.clone().align(spd_green.shape,
                                  extrapolation_left=0,
                                  extrapolation_right=0)
    lef_blue = lef.clone().align(spd_blue.shape,
                                 extrapolation_left=0,
                                 extrapolation_right=0)
    lef_yellow = lef.clone().align(spd_yellow.shape,
                                   extrapolation_left=0,
                                   extrapolation_right=0)
    #import numpy as np
    #spd_4d
    Fi_max_4d = (683 *
                 np.trapz(lef_4d.values * spd_4d.values, spd_4d.wavelengths))
    k_4d = Fi_4d / Fi_max_4d
    Fe_4d = (k_4d * np.trapz(spd_4d.values, spd_4d.wavelengths))
    F_4d = [Fi_max_4d, k_4d, Fe_4d, Fi_4d]
    #spd_red
    Fi_max_red = (
        683 * np.trapz(lef_red.values * spd_red.values, spd_red.wavelengths))
    k_red = Fi_red / Fi_max_red
    Fe_red = (k_red * np.trapz(spd_red.values, spd_red.wavelengths))
    F_red = [Fi_max_red, k_red, Fe_red, Fi_red]

    #spd_green
    Fi_max_green = (
        683 *
        np.trapz(lef_green.values * spd_green.values, spd_green.wavelengths))
    k_green = Fi_green / Fi_max_green
    Fe_green = (k_green * np.trapz(spd_green.values, spd_green.wavelengths))
    F_green = [Fi_max_green, k_green, Fe_green, Fi_green]
    #spd_blue
    Fi_max_blue = (
        683 *
        np.trapz(lef_blue.values * spd_blue.values, spd_blue.wavelengths))
    k_blue = Fi_blue / Fi_max_blue
    Fe_blue = (k_blue * np.trapz(spd_blue.values, spd_blue.wavelengths))
    F_blue = [Fi_max_blue, k_blue, Fe_blue, Fi_blue]
    #spd_yellow
    Fi_max_yellow = (683 * np.trapz(lef_yellow.values * spd_yellow.values,
                                    spd_yellow.wavelengths))
    k_yellow = Fi_yellow / Fi_max_yellow
    Fe_yellow = (k_yellow *
                 np.trapz(spd_yellow.values, spd_yellow.wavelengths))
    F_yellow = [Fi_max_yellow, k_yellow, Fe_yellow, Fi_yellow]
    return spd_4, spd_4d, h_sum, image, abca, F_4d, F_red, F_green, F_blue, F_yellow
Exemplo n.º 14
0
 def spd_to_XYZ(self, cmfs=cmfs, illuminant=illuminant):
     XYZ = colour.spectral_to_XYZ(self.spd, cmfs, illuminant)
     return XYZ
Exemplo n.º 15
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)))
Exemplo n.º 16
0
    750: 0.436,
    755: 0.450,
    760: 0.462,
    765: 0.465,
    770: 0.448,
    775: 0.432,
    780: 0.421}

spd = colour.SpectralPowerDistribution('Sample', sample_spd_data)

cmfs = colour.CMFS['CIE 1931 2 Degree Standard Observer']
illuminant = colour.ILLUMINANTS_RELATIVE_SPDS['A']

message_box(('Computing *CIE XYZ* tristimulus values for sample spectral '
             'power distribution and "CIE Standard Illuminant A".'))
print(colour.spectral_to_XYZ(spd, cmfs, illuminant))

print('\n')

message_box(('Computing "CIE Standard Illuminant A" chromaticity coordinates '
             'from its relative spectral power distribution.'))
print(colour.XYZ_to_xy(colour.spectral_to_XYZ(illuminant, cmfs)))

print('\n')

message_box(('Computing *CIE XYZ* tristimulus values for a single given '
             'wavelength in nm.'))
print(colour.wavelength_to_XYZ(
    546.1,
    colour.CMFS['CIE 1931 2 Degree Standard Observer']))
Exemplo n.º 17
0
import pylab
from io import BytesIO

cmfs = CMFS['CIE 1931 2 Degree Standard Observer']
with open('test.txt') as f:
    data = pd.read_csv(f, sep="\t" or ' ' or ',', header=None)
    f.close()
w = [i[0] for i in data.values]
s = [i[1] for i in data.values]
data_formated = dict(zip(w, s))
print(data)
print(data.values)
print(data_formated)
spd = SpectralPowerDistribution('Sample', data_formated)
illuminant = ILLUMINANTS_RELATIVE_SPDS['D50']
XYZ = spectral_to_XYZ(spd, cmfs, illuminant)
print(XYZ)
xy = XYZ_to_xy(XYZ)
print(xy)

CIE_1931_chromaticity_diagram_plot(standalone=False)
x, y = xy
pylab.plot(x, y, 'o-', color='white')
pylab.annotate('test',
               xy=xy,
               xytext=(-50, 30),
               textcoords='offset points',
               arrowprops=dict(arrowstyle='->',
                               connectionstyle='arc3, rad=-0.2'))

a = display(standalone=False)
Exemplo n.º 18
0
 def post(self):
     data = request.json
     data = dict(zip(data['wavelengths'], data['values']))
     spd = SpectralPowerDistribution('spd', data)
     cmfs = CMFS.get('CIE 1931 2 Degree Standard Observer')
     return spectral_to_XYZ(spd, cmfs).tolist()