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 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
Exemplo n.º 3
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.º 4
0
def open_spd(sample, name):
    sample_spd_data = {}
    with open(sample) as f:
        for iii in f:
            (key, val) = iii.split()
            key = float(key)
            val = float(val)
            key = round(key)
            val = round(val, 5)
            sample_spd_data[key] = float(val)
    spd = colour.SpectralPowerDistribution(name, sample_spd_data)
    clone_spd = spd.clone()
    clone_spd.interpolate(colour.SpectralShape(200, 800, 1))
    return clone_spd
Exemplo n.º 5
0
def spectr_LED4(abca, spd_red0, spd_green0, spd_blue0, spd_yellow0):
    sample_spd_data = {}
    b1, b2, b3, a = abca[0], abca[1], abca[2], abca[3]
    chip_values = []
    for lamb in np.arange(200, 800, 0.9):
        chip_4d = b1 * spd_red0[lamb] + b2 * spd_green0[lamb] + b3 * spd_blue0[
            lamb] + a * spd_yellow0[lamb]
        sample_spd_data[lamb] = float(chip_4d)
        chip_values.append(chip_4d)
    max_del = max(chip_values)
    for sample in sample_spd_data:
        sample_spd_data[sample] = sample_spd_data[sample] / max_del
    spd = colour.SpectralPowerDistribution('Sample', sample_spd_data)
    spd.interpolate(colour.SpectralShape(200, 800, 1))
    return spd
Exemplo n.º 6
0
    660: 0.01347059,
    665: 0.01424768,
    670: 0.01215791,
    675: 0.01209338,
    680: 0.01155313,
    685: 0.01061995,
    690: 0.01014779,
    695: 0.00864212,
    700: 0.00951386,
    705: 0.00786982,
    710: 0.00841476,
    715: 0.00741868,
    720: 0.00637711,
    725: 0.00556483,
    730: 0.00590016,
    735: 0.00416819,
    740: 0.00422222,
    745: 0.00345776,
    750: 0.00336879,
    755: 0.00298999,
    760: 0.00367047,
    765: 0.00340568,
    770: 0.00261153,
    775: 0.00258850,
    780: 0.00293663
}

print(
    colour.colour_quality_scale(
        colour.SpectralPowerDistribution(SAMPLE_SPD_DATA, name='Sample')))
Exemplo n.º 7
0
    782: 84.19,
    784: 84.21,
    786: 84.22,
    788: 84.25,
    790: 84.29,
    792: 84.29,
    794: 84.31,
    796: 84.31,
    798: 84.34,
    800: 84.34,
    820: 84.47
}

message_box('Plotting various single spectral power distributions.')
single_spd_plot(
    colour.SpectralPowerDistribution(sample_spd_data, name='Custom'))
single_spd_plot(
    colour.SpectralPowerDistribution(galvanized_steel_metal_spd_data,
                                     name='Galvanized Steel Metal'))

print('\n')

message_box('Plotting multiple spectral power distributions.')
multi_spd_plot(
    (colour.SpectralPowerDistribution(galvanized_steel_metal_spd_data,
                                      name='Galvanized Steel Metal'),
     colour.SpectralPowerDistribution(white_marble_spd_data,
                                      name='White Marble')))

print('\n')
Exemplo n.º 8
0
    660: 0.204,
    665: 0.213,
    670: 0.222,
    675: 0.231,
    680: 0.242,
    685: 0.251,
    690: 0.261,
    695: 0.271,
    700: 0.282,
    705: 0.294,
    710: 0.305,
    715: 0.318,
    720: 0.334,
    725: 0.354,
    730: 0.372,
    735: 0.392,
    740: 0.409,
    745: 0.420,
    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_spd_data, name='Sample')
uncorrected_values = spd.values
print(np.dstack((uncorrected_values, colour.bandpass_correction(spd).values)))
Exemplo n.º 9
0
computations.
"""

import colour
from colour.utilities import message_box

message_box('"ACES" "Input Device Transform" Computations')

message_box(('Computing "ACES" relative exposure '
             'values for some colour rendition chart spectral power '
             'distributions:\n'
             '\n\t("dark skin", \n\t"blue sky")'))
print(colour.spectral_to_aces_relative_exposure_values(
    colour.COLOURCHECKERS_SPDS['ColorChecker N Ohta']['dark skin']))
print(colour.spectral_to_aces_relative_exposure_values(
    colour.COLOURCHECKERS_SPDS['ColorChecker N Ohta']['blue sky']))

print('\n')

message_box(('Computing "ACES" relative exposure values for various ideal '
             'reflectors:\n'
             '\n\t("18%", \n\t"100%")'))
wavelengths = colour.models.ACES_RICD.wavelengths
gray_reflector = colour.SpectralPowerDistribution(
    dict(zip(wavelengths, [0.18] * len(wavelengths))), name='18%')
print(repr(colour.spectral_to_aces_relative_exposure_values(gray_reflector)))

perfect_reflector = colour.SpectralPowerDistribution(
    dict(zip(wavelengths, [1.] * len(wavelengths))), name='100%')
print(colour.spectral_to_aces_relative_exposure_values(perfect_reflector))
Exemplo n.º 10
0
    778: 84.18,
    780: 84.19,
    782: 84.19,
    784: 84.21,
    786: 84.22,
    788: 84.25,
    790: 84.29,
    792: 84.29,
    794: 84.31,
    796: 84.31,
    798: 84.34,
    800: 84.34,
    820: 84.47}

message_box('Plotting various single spectral power distributions.')
single_spd_plot(colour.SpectralPowerDistribution('Custom', sample_spd_data))
single_spd_plot(colour.SpectralPowerDistribution(
    'Galvanized Steel Metal',
    galvanized_steel_metal_spd_data))

print('\n')

message_box('Plotting multiple spectral power distributions.')
multi_spd_plot((colour.SpectralPowerDistribution(
    'Galvanized Steel Metal',
    galvanized_steel_metal_spd_data),
    colour.SpectralPowerDistribution('White Marble', white_marble_spd_data)))

print('\n')

message_box('Plotting spectral bandpass dependence correction.')
Exemplo n.º 11
0
    580: 0.1128,
    600: 0.1360,
    620: 0.1511,
    640: 0.1688,
    660: 0.1996,
    680: 0.2397,
    700: 0.2852,
    720: 0.0000,
    740: 0.0000,
    760: 0.0000,
    780: 0.0000,
    800: 0.0000,
    820.9: 0.0000}

base_spd = colour.SpectralPowerDistribution(
    'Reference',
    uniform_spd_data)
uniform_interpolated_spd = colour.SpectralPowerDistribution(
    'Uniform - Sprague Interpolation',
    uniform_spd_data)
uniform_pchip_interpolated_spd = colour.SpectralPowerDistribution(
    'Uniform - Pchip Interpolation',
    uniform_spd_data)
non_uniform_interpolated_spd = colour.SpectralPowerDistribution(
    'Non Uniform - Cubic Spline Interpolation',
    non_uniform_spd_data)

uniform_interpolated_spd.interpolate(colour.SpectralShape(interval=1))
uniform_pchip_interpolated_spd.interpolate(colour.SpectralShape(interval=1),
                                           method='Pchip')
non_uniform_interpolated_spd.interpolate(colour.SpectralShape(interval=1))
Exemplo n.º 12
0
from random import random, seed
seed(20180501)
from iminuit import Minuit, describe, Struct
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())
Exemplo n.º 13
0
 def colour_spectr(sample_spd_data, name):
     spd = colour.SpectralPowerDistribution(name, sample_spd_data)
     spd.interpolate(colour.SpectralShape(200, 800, 1))
     return spd
Exemplo n.º 14
0
 def to_spd(self):
     self.spd = colour.SpectralPowerDistribution(self.spec_dict,
                                                 name=self.name)
     return self.spd
Exemplo n.º 15
0
    660: 0.01347059,
    665: 0.01424768,
    670: 0.01215791,
    675: 0.01209338,
    680: 0.01155313,
    685: 0.01061995,
    690: 0.01014779,
    695: 0.00864212,
    700: 0.00951386,
    705: 0.00786982,
    710: 0.00841476,
    715: 0.00741868,
    720: 0.00637711,
    725: 0.00556483,
    730: 0.00590016,
    735: 0.00416819,
    740: 0.00422222,
    745: 0.00345776,
    750: 0.00336879,
    755: 0.00298999,
    760: 0.00367047,
    765: 0.00340568,
    770: 0.00261153,
    775: 0.00258850,
    780: 0.00293663
}

print(
    colour.colour_quality_scale(
        colour.SpectralPowerDistribution('Sample', SAMPLE_SPD_DATA)))
Exemplo n.º 16
0
    720: 0.334,
    725: 0.354,
    730: 0.372,
    735: 0.392,
    740: 0.409,
    745: 0.420,
    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)

message_box('Sample spectral power distribution shape.')
print(spd.shape)

print('\n')

message_box('Sample spectral power distribution uniformity.')
print(spd.is_uniform())

print('\n')

message_box(('Sample spectral power distribution cloning:\n'
             '\n\t("Original Id", "Clone Id")\n'
             '\nCloning is a convenient way to get a copy of the spectral '
             'power distribution, this an important feature because some '
Exemplo n.º 17
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)])