def sp2xy(sp): spd = colour.SpectralDistribution(sp, name='Sample') cmfs = colour.colorimetry.MSDS_CMFS_STANDARD_OBSERVER[ 'CIE 1931 2 Degree Standard Observer'] illuminant = colour.SDS_ILLUMINANTS['D65'] XYZ = colour.sd_to_XYZ(spd, cmfs, illuminant) return colour.XYZ_to_xy(XYZ)
def spectral2rgb(s): sd = colour.SpectralDistribution(s) cmfs = colour.STANDARD_OBSERVERS_CMFS[ 'CIE 1931 2 Degree Standard Observer'] illuminant = colour.ILLUMINANTS_SDS['D65'] XYZ = colour.sd_to_XYZ(sd, cmfs, illuminant) RGB = colour.XYZ_to_sRGB(XYZ / 100) return RGB
def abslines_to_molar_abs(inputf, title="Plot1", show_plot=False, stdev=3099.6, wav_range=(200, 1000), normalize=False): import numpy as np import matplotlib.pyplot as plt import colour abslines = inputf wav = list(map(lambda k: k.wavelength, abslines)) fs = list(map(lambda l: l.oscillator_strength, abslines)) start = wav_range[0] finish = wav_range[1] points = finish - start # i.e. 1 nm # A sqrt(2) * standard deviation of 0.4 eV is 3099.6 nm. 0.1 eV is 12398.4 nm. 0.2 eV is 6199.2 nm, 0.33 eV = 3723.01 nm bands = wav f = fs # Basic check that we have the same number of bands and oscillator strengths if len(bands) != len(f): raise Exception( 'ERROR: Number of bands does not match the number of oscillator strengths.' ) def gauss_band(x, band, strength, stdev): bandshape = 1.3062974e8 * (strength / (1e7 / stdev)) * np.exp(-(((1.0 / x) - (1.0 / band)) / (1.0 / stdev))**2) return bandshape x = np.linspace(start, finish, points) composite = 0 for i in range(0, len(bands), 1): peak = gauss_band(x, float(bands[i]), float(f[i]), stdev) composite += peak if show_plot == True: figg, axx = plt.subplots() axx.plot(x, composite) plt.xlabel('$\lambda$ / nm') plt.ylabel('$\epsilon$ / L mol$^{-1}$ cm$^{-1}$') plt.show() if normalize is True: from colour_of_molecule.analysis.common_tools import normalize_list composite = normalize_list(composite) data = colour.SpectralDistribution(data=composite, domain=x, name=title) return data
def compute_color(self): self.sample_spd_data = dict(zip(self.raw_wl, self.raw_spec)) self.spd = colour.SpectralDistribution(self.sample_spd_data, name=self.label) # Cloning the sample spectral power distribution. self.spd_interpolated = self.spd.clone() # Interpolating the cloned sample spectral power distribution. # Indeed, the algorithm for colour identification needs a spectra with a point each nanometer self.spd_interpolated.interpolate(colour.SpectralShape(370, 680, 1)) self.cmfs = colour.STANDARD_OBSERVERS_CMFS[ 'CIE 1931 2 Degree Standard Observer'] self.illuminant = colour.ILLUMINANTS_SDS['D65'] self.XYZ = colour.sd_to_XYZ(self.spd_interpolated, self.cmfs, self.illuminant) self.RGB = colour.XYZ_to_sRGB(self.XYZ / 100) """ We then come to the next obstacle... The RGB values that we get from this process are often out of range - meaning that they are either greater than 1.0, or even that they are negative! The first case is fairly straightforward, it means that the color is too bright for the display. The second case means that the color is too saturated and vivid for the display. The display must compose all colors from some combination of positive amounts of the colors of its red, green and blue phosphors. The colors of these phosphors are not perfectly saturated, they are washed out, mixed with white, to some extent. So not all colors can be displayed accurately. As an example, the colors of pure spectral lines, all have some negative component. Something must be done to put these values into the 0.0 - 1.0 range that can actually be displayed, known as color clipping. In the first case, values larger than 1.0, ColorPy scales the color so that the maximum component is 1.0. This reduces the brightness without changing the chromaticity. The second case requires some change in chromaticity. By default, ColorPy will add white to the color, just enough to make all of the components non-negative. (You can also have ColorPy clamp the negative values to zero. My personal, qualitative, assessment is that adding white produces somewhat better results. There is also the potential to develop a better clipping function.) """ if min(self.RGB) < 0: self.RGB += min(self.RGB) if max(self.RGB) > 1: self.RGB /= max(self.RGB) # TODO why can we get negative values and values > 1 ? self.RGB = np.abs(self.RGB) self.RGB = np.clip(self.RGB, 0, 1) self.xy = colour.XYZ_to_xy(self.XYZ)
def get_tristimulus_XYZs(Theta_I, Phi_I, Polarization, Data, observer, illuminant): u_wls = np.array(Data['Wavelengths']) u_theta_Is = np.array(Data['thetaIs']) u_phi_Is = np.array(Data['phiIs']) u_pols = np.array(Data['Polarization']) u_theta_Vs = np.array(Data['thetaVs']) u_phi_Vs = np.array(Data['phiVs']) data = np.array(Data['data']) cmfs = clr.STANDARD_OBSERVERS_CMFS[observer] illuminant = clr.ILLUMINANTS_SDS[illuminant] tristimulus_XYZ_values = [] color_values = [] for theta_V in u_theta_Vs: tristimulus_XYZ_row = [] color_values_row = [] for phi_V in u_phi_Vs: spectrum = data[u_pols == Polarization, u_theta_Is == Theta_I, u_phi_Is == Phi_I, :, u_theta_Vs == theta_V, u_phi_Vs == phi_V] # spectrum = spectrum[0]/np.max(spectrum) spectrum = np.array([u_wls, spectrum[0]]).T spectrum = spectrum.tolist() spectrum = {line[0]: line[1] for line in spectrum} sd = clr.SpectralDistribution(spectrum) sd = sd.interpolate(clr.SpectralShape(380, 830, 1)) # print(sd) XYZ = clr.sd_to_XYZ(sd, cmfs, illuminant) sRGB = clr.XYZ_to_sRGB(XYZ / 100) sRGB = sRGBColor(sRGB[0], sRGB[1], sRGB[2]) RGB = list(sRGB.get_upscaled_value_tuple()) for i in range(len(RGB)): if RGB[i] < 0: RGB[i] = 0 elif RGB[i] > 255: RGB[i] = 255 tristimulus_XYZ_row.append(XYZ) color_values_row.append(RGB) tristimulus_XYZ_values.append(tristimulus_XYZ_row) color_values.append(color_values_row) return tristimulus_XYZ_values, color_values
def molar_abs_to_complement_abs(spectrum, OD=0.15, normalize=True): import colour import numpy as np val = spectrum.values wav = spectrum.wavelengths tit = spectrum.name export = list() top = max(spectrum.values) norm = OD / top if normalize is True else 1 for j in range(0, len(val), 1): expo = val[j] * norm if expo < 1e-10: expo = 1e-10 exval = -np.log10(1 - 10**(-expo)) export.append(exval) out = colour.SpectralDistribution(data=export, domain=wav, name=tit) return out
def copute_color(self): self.sample_spd_data = dict(zip(self.raw_wl, self.raw_spec)) self.spd = colour.SpectralDistribution(self.sample_spd_data, name=self.label) # Cloning the sample spectral power distribution. self.spd_interpolated = self.spd.clone() # Interpolating the cloned sample spectral power distribution. # Indeed, the algorithm for colour identification needs a spectra with a point each nanometer self.spd_interpolated.interpolate(colour.SpectralShape(400, 820, 1)) self.cmfs = colour.STANDARD_OBSERVERS_CMFS[ 'CIE 1931 2 Degree Standard Observer'] self.illuminant = colour.ILLUMINANTS_SDS['D65'] self.XYZ = colour.sd_to_XYZ(self.spd_interpolated, self.cmfs, self.illuminant) self.RGB = colour.XYZ_to_sRGB(self.XYZ / 100) # TODO why can we get negative values and values > 1 ? self.RGB = np.abs(self.RGB) self.RGB = np.clip(self.RGB, 0, 1) self.xy = colour.XYZ_to_xy(self.XYZ)
def generate_documentation_plots(output_directory): """ Generates documentation plots. Parameters ---------- output_directory : unicode Output directory. """ colour.utilities.filter_warnings() colour_style() np.random.seed(0) # ************************************************************************* # "README.rst" # ************************************************************************* arguments = { 'tight_layout': True, 'transparent_background': True, 'filename': os.path.join(output_directory, 'Examples_Plotting_Visible_Spectrum.png') } plot_visible_spectrum('CIE 1931 2 Degree Standard Observer', **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Illuminant_F1_SD.png') plot_single_illuminant_sd('FL1', **arguments) arguments['filename'] = os.path.join(output_directory, 'Examples_Plotting_Blackbodies.png') blackbody_sds = [ colour.sd_blackbody(i, colour.SpectralShape(0, 10000, 10)) for i in range(1000, 15000, 1000) ] plot_multi_sds( blackbody_sds, y_label='W / (sr m$^2$) / m', use_sds_colours=True, normalise_sds_colours=True, legend_location='upper right', bounding_box=(0, 1250, 0, 2.5e15), **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Cone_Fundamentals.png') plot_single_cmfs( 'Stockman & Sharpe 2 Degree Cone Fundamentals', y_label='Sensitivity', bounding_box=(390, 870, 0, 1.1), **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Luminous_Efficiency.png') sd_mesopic_luminous_efficiency_function = ( colour.sd_mesopic_luminous_efficiency_function(0.2)) plot_multi_sds( (sd_mesopic_luminous_efficiency_function, colour.PHOTOPIC_LEFS['CIE 1924 Photopic Standard Observer'], colour.SCOTOPIC_LEFS['CIE 1951 Scotopic Standard Observer']), y_label='Luminous Efficiency', legend_location='upper right', y_tighten=True, margins=(0, 0, 0, .1), **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_BabelColor_Average.png') plot_multi_sds( colour.COLOURCHECKERS_SDS['BabelColor Average'].values(), use_sds_colours=True, title=('BabelColor Average - ' 'Spectral Distributions'), **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_ColorChecker_2005.png') plot_single_colour_checker( 'ColorChecker 2005', text_parameters={'visible': False}, **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Chromaticities_Prediction.png') plot_corresponding_chromaticities_prediction(2, 'Von Kries', 'Bianco', **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_CCT_CIE_1960_UCS_Chromaticity_Diagram.png') plot_planckian_locus_in_chromaticity_diagram_CIE1960UCS(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Examples_Plotting_Chromaticities_CIE_1931_Chromaticity_Diagram.png') RGB = np.random.random((32, 32, 3)) plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931( RGB, 'ITU-R BT.709', colourspaces=['ACEScg', 'S-Gamut'], show_pointer_gamut=True, **arguments) arguments['filename'] = os.path.join(output_directory, 'Examples_Plotting_CRI.png') plot_single_sd_colour_rendering_index_bars(colour.ILLUMINANTS_SDS['FL2'], **arguments) # ************************************************************************* # Documentation # ************************************************************************* arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_CVD_Simulation_Machado2009.png') plot_cvd_simulation_Machado2009(RGB, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Colour_Checker.png') plot_single_colour_checker('ColorChecker 2005', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Colour_Checkers.png') plot_multi_colour_checkers(['ColorChecker 1976', 'ColorChecker 2005'], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Single_SD.png') data = { 500: 0.0651, 520: 0.0705, 540: 0.0772, 560: 0.0870, 580: 0.1128, 600: 0.1360 } sd = colour.SpectralDistribution(data, name='Custom') plot_single_sd(sd, **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Multi_SDs.png') data_1 = { 500: 0.004900, 510: 0.009300, 520: 0.063270, 530: 0.165500, 540: 0.290400, 550: 0.433450, 560: 0.594500 } data_2 = { 500: 0.323000, 510: 0.503000, 520: 0.710000, 530: 0.862000, 540: 0.954000, 550: 0.994950, 560: 0.995000 } spd1 = colour.SpectralDistribution(data_1, name='Custom 1') spd2 = colour.SpectralDistribution(data_2, name='Custom 2') plot_multi_sds([spd1, spd2], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Single_CMFS.png') plot_single_cmfs('CIE 1931 2 Degree Standard Observer', **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Multi_CMFS.png') cmfs = ('CIE 1931 2 Degree Standard Observer', 'CIE 1964 10 Degree Standard Observer') plot_multi_cmfs(cmfs, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Illuminant_SD.png') plot_single_illuminant_sd('A', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Illuminant_SDs.png') plot_multi_illuminant_sds(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Visible_Spectrum.png') plot_visible_spectrum(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Lightness_Function.png') plot_single_lightness_function('CIE 1976', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Lightness_Functions.png') plot_multi_lightness_functions(['CIE 1976', 'Wyszecki 1963'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Luminance_Function.png') plot_single_luminance_function('CIE 1976', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Luminance_Functions.png') plot_multi_luminance_functions(['CIE 1976', 'Newhall 1943'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Blackbody_Spectral_Radiance.png') plot_blackbody_spectral_radiance( 3500, blackbody='VY Canis Major', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Blackbody_Colours.png') plot_blackbody_colours(colour.SpectralShape(150, 12500, 50), **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Colour_Swatch.png') RGB = ColourSwatch(RGB=(0.32315746, 0.32983556, 0.33640183)) plot_single_colour_swatch(RGB, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Colour_Swatches.png') RGB_1 = ColourSwatch(RGB=(0.45293517, 0.31732158, 0.26414773)) RGB_2 = ColourSwatch(RGB=(0.77875824, 0.57726450, 0.50453169)) plot_multi_colour_swatches([RGB_1, RGB_2], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Single_Function.png') plot_single_function(lambda x: x ** (1 / 2.2), **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Multi_Functions.png') functions = { 'Gamma 2.2': lambda x: x ** (1 / 2.2), 'Gamma 2.4': lambda x: x ** (1 / 2.4), 'Gamma 2.6': lambda x: x ** (1 / 2.6), } plot_multi_functions(functions, **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Image.png') path = os.path.join(colour.__path__[0], '..', 'docs', '_static', 'Logo_Medium_001.png') plot_image(colour.read_image(str(path)), **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Corresponding_Chromaticities_Prediction.png') plot_corresponding_chromaticities_prediction(1, 'Von Kries', 'CAT02', **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Spectral_Locus.png') plot_spectral_locus(spectral_locus_colours='RGB', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram_Colours.png') plot_chromaticity_diagram_colours(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram.png') plot_chromaticity_diagram(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1931.png') plot_chromaticity_diagram_CIE1931(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1960UCS.png') plot_chromaticity_diagram_CIE1960UCS(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Chromaticity_Diagram_CIE1976UCS.png') plot_chromaticity_diagram_CIE1976UCS(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram.png') A = colour.ILLUMINANTS_SDS['A'] D65 = colour.ILLUMINANTS_SDS['D65'] plot_sds_in_chromaticity_diagram([A, D65], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1931.png') plot_sds_in_chromaticity_diagram_CIE1931([A, D65], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1960UCS.png') plot_sds_in_chromaticity_diagram_CIE1960UCS([A, D65], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_SDs_In_Chromaticity_Diagram_CIE1976UCS.png') plot_sds_in_chromaticity_diagram_CIE1976UCS([A, D65], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Pointer_Gamut.png') plot_pointer_gamut(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_In_Chromaticity_Diagram.png') plot_RGB_colourspaces_in_chromaticity_diagram( ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_In_Chromaticity_Diagram_CIE1931.png') plot_RGB_colourspaces_in_chromaticity_diagram_CIE1931( ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_In_' 'Chromaticity_Diagram_CIE1960UCS.png') plot_RGB_colourspaces_in_chromaticity_diagram_CIE1960UCS( ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_In_' 'Chromaticity_Diagram_CIE1976UCS.png') plot_RGB_colourspaces_in_chromaticity_diagram_CIE1976UCS( ['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Chromaticities_In_' 'Chromaticity_Diagram_Plot.png') RGB = np.random.random((128, 128, 3)) plot_RGB_chromaticities_in_chromaticity_diagram(RGB, 'ITU-R BT.709', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Chromaticities_In_' 'Chromaticity_Diagram_CIE1931.png') plot_RGB_chromaticities_in_chromaticity_diagram_CIE1931( RGB, 'ITU-R BT.709', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Chromaticities_In_' 'Chromaticity_Diagram_CIE1960UCS.png') plot_RGB_chromaticities_in_chromaticity_diagram_CIE1960UCS( RGB, 'ITU-R BT.709', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Chromaticities_In_' 'Chromaticity_Diagram_CIE1976UCS.png') plot_RGB_chromaticities_in_chromaticity_diagram_CIE1976UCS( RGB, 'ITU-R BT.709', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_Chromaticity_Diagram.png') plot_ellipses_MacAdam1942_in_chromaticity_diagram(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_' 'Chromaticity_Diagram_CIE1931.png') plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1931(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_' 'Chromaticity_Diagram_CIE1960UCS.png') plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1960UCS(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Ellipses_MacAdam1942_In_' 'Chromaticity_Diagram_CIE1976UCS.png') plot_ellipses_MacAdam1942_in_chromaticity_diagram_CIE1976UCS(**arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Single_CCTF.png') plot_single_cctf('ITU-R BT.709', **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Multi_CCTFs.png') plot_multi_cctfs(['ITU-R BT.709', 'sRGB'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_Munsell_Value_Function.png') plot_single_munsell_value_function('ASTM D1535-08', **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_Munsell_Value_Functions.png') plot_multi_munsell_value_functions(['ASTM D1535-08', 'McCamy 1987'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_SD_Rayleigh_Scattering.png') plot_single_sd_rayleigh_scattering(**arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_The_Blue_Sky.png') plot_the_blue_sky(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Colour_Quality_Bars.png') illuminant = colour.ILLUMINANTS_SDS['FL2'] light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P'] light_source = light_source.copy().align(colour.SpectralShape(360, 830, 1)) cqs_i = colour.colour_quality_scale(illuminant, additional_data=True) cqs_l = colour.colour_quality_scale(light_source, additional_data=True) plot_colour_quality_bars([cqs_i, cqs_l], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_SD_Colour_Rendering_Index_Bars.png') illuminant = colour.ILLUMINANTS_SDS['FL2'] plot_single_sd_colour_rendering_index_bars(illuminant, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_SDs_Colour_Rendering_Indexes_Bars.png') light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P'] plot_multi_sds_colour_rendering_indexes_bars([illuminant, light_source], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Single_SD_Colour_Quality_Scale_Bars.png') illuminant = colour.ILLUMINANTS_SDS['FL2'] plot_single_sd_colour_quality_scale_bars(illuminant, **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Multi_SDs_Colour_Quality_Scales_Bars.png') light_source = colour.LIGHT_SOURCES_SDS['Kinoton 75P'] plot_multi_sds_colour_quality_scales_bars([illuminant, light_source], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_Planckian_Locus.png') plot_planckian_locus(**arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram.png') plot_planckian_locus_in_chromaticity_diagram(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram_CIE1931.png') plot_planckian_locus_in_chromaticity_diagram_CIE1931(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_Planckian_Locus_In_Chromaticity_Diagram_CIE1960UCS.png') plot_planckian_locus_in_chromaticity_diagram_CIE1960UCS(['A', 'B', 'C'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_Gamuts.png') plot_RGB_colourspaces_gamuts(['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join( output_directory, 'Plotting_Plot_RGB_Colourspaces_Gamuts.png') plot_RGB_colourspaces_gamuts(['ITU-R BT.709', 'ACEScg', 'S-Gamut'], **arguments) arguments['filename'] = os.path.join(output_directory, 'Plotting_Plot_RGB_Scatter.png') plot_RGB_scatter(RGB, 'ITU-R BT.709', **arguments) # ************************************************************************* # "tutorial.rst" # ************************************************************************* arguments['filename'] = os.path.join(output_directory, 'Tutorial_Visible_Spectrum.png') plot_visible_spectrum(**arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_Sample_SD.png') sample_sd_data = { 380: 0.048, 385: 0.051, 390: 0.055, 395: 0.060, 400: 0.065, 405: 0.068, 410: 0.068, 415: 0.067, 420: 0.064, 425: 0.062, 430: 0.059, 435: 0.057, 440: 0.055, 445: 0.054, 450: 0.053, 455: 0.053, 460: 0.052, 465: 0.052, 470: 0.052, 475: 0.053, 480: 0.054, 485: 0.055, 490: 0.057, 495: 0.059, 500: 0.061, 505: 0.062, 510: 0.065, 515: 0.067, 520: 0.070, 525: 0.072, 530: 0.074, 535: 0.075, 540: 0.076, 545: 0.078, 550: 0.079, 555: 0.082, 560: 0.087, 565: 0.092, 570: 0.100, 575: 0.107, 580: 0.115, 585: 0.122, 590: 0.129, 595: 0.134, 600: 0.138, 605: 0.142, 610: 0.146, 615: 0.150, 620: 0.154, 625: 0.158, 630: 0.163, 635: 0.167, 640: 0.173, 645: 0.180, 650: 0.188, 655: 0.196, 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 } sd = colour.SpectralDistribution(sample_sd_data, name='Sample') plot_single_sd(sd, **arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_SD_Interpolation.png') sd_copy = sd.copy() sd_copy.interpolate(colour.SpectralShape(400, 770, 1)) plot_multi_sds( [sd, sd_copy], bounding_box=[730, 780, 0.25, 0.5], **arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_Sample_Swatch.png') sd = colour.SpectralDistribution(sample_sd_data) cmfs = colour.STANDARD_OBSERVERS_CMFS[ 'CIE 1931 2 Degree Standard Observer'] illuminant = colour.ILLUMINANTS_SDS['D65'] with domain_range_scale('1'): XYZ = colour.sd_to_XYZ(sd, cmfs, illuminant) RGB = colour.XYZ_to_sRGB(XYZ) plot_single_colour_swatch( ColourSwatch('Sample', RGB), text_parameters={'size': 'x-large'}, **arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_Neutral5.png') patch_name = 'neutral 5 (.70 D)' patch_sd = colour.COLOURCHECKERS_SDS['ColorChecker N Ohta'][patch_name] with domain_range_scale('1'): XYZ = colour.sd_to_XYZ(patch_sd, cmfs, illuminant) RGB = colour.XYZ_to_sRGB(XYZ) plot_single_colour_swatch( ColourSwatch(patch_name.title(), RGB), text_parameters={'size': 'x-large'}, **arguments) arguments['filename'] = os.path.join(output_directory, 'Tutorial_Colour_Checker.png') plot_single_colour_checker( colour_checker='ColorChecker 2005', text_parameters={'visible': False}, **arguments) arguments['filename'] = os.path.join( output_directory, 'Tutorial_CIE_1931_Chromaticity_Diagram.png') xy = colour.XYZ_to_xy(XYZ) plot_chromaticity_diagram_CIE1931(standalone=False) x, y = xy plt.plot(x, y, 'o-', color='white') # Annotating the plot. plt.annotate( patch_sd.name.title(), xy=xy, xytext=(-50, 30), textcoords='offset points', arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=-0.2')) render( standalone=True, limits=(-0.1, 0.9, -0.1, 0.9), x_tighten=True, y_tighten=True, **arguments) # ************************************************************************* # "basics.rst" # ************************************************************************* arguments['filename'] = os.path.join(output_directory, 'Basics_Logo_Small_001_CIE_XYZ.png') RGB = colour.read_image( os.path.join(output_directory, 'Logo_Small_001.png'))[..., 0:3] XYZ = colour.sRGB_to_XYZ(RGB) colour.plotting.plot_image( XYZ, text_parameters={'text': 'sRGB to XYZ'}, **arguments)
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.SpectralDistribution(SAMPLE_SD_DATA, name='Sample')))
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 ' 'distributions:\n' '\n\t("dark skin", \n\t"blue sky")')) print( colour.sd_to_aces_relative_exposure_values( colour.COLOURCHECKERS_SDS['ColorChecker N Ohta']['dark skin'])) print( colour.sd_to_aces_relative_exposure_values( colour.COLOURCHECKERS_SDS['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.SpectralDistribution(dict( zip(wavelengths, [0.18] * len(wavelengths))), name='18%') print(repr(colour.sd_to_aces_relative_exposure_values(gray_reflector))) perfect_reflector = colour.SpectralDistribution(dict( zip(wavelengths, [1.] * len(wavelengths))), name='100%') print(colour.sd_to_aces_relative_exposure_values(perfect_reflector))
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 } sd_sample = colour.SpectralDistribution(data_sample, name='Sample') message_box('Sample spectral distribution shape.') print(sd_sample.shape) print('\n') message_box('Sample spectral distribution uniformity.') print(sd_sample.is_uniform()) print('\n') message_box(('Sample spectral distribution cloning:\n' '\n\t("Original Id", "Clone Id")\n' '\nCloning is a convenient way to get a copy of the spectral ' 'distribution, this an important feature because some '
spetral_f_initial = spectral_offset - half_spectral_window spetral_f_final = spectral_offset + half_spectral_window #Chop our spectrum down to this range #Thanks colour for making this a PITA. Just have a stupid array instead of hiding #this like it's something incredibly special. subset_of_blackbody_sd = {} for k in black_body_sd.wavelengths: s = black_body_sd[k] #print("s: {}, k: {}".format(s, k)) if spetral_f_initial <= k and k <= spetral_f_final: subset_of_blackbody_sd[ k] = s * intensity_normalization_factor else: subset_of_blackbody_sd[k] = 0.0 subset_of_blackbody_sd = colour.SpectralDistribution( subset_of_blackbody_sd) #Convert our spectrum into a color star_xyz_color = colour.sd_to_XYZ(subset_of_blackbody_sd, cmfs) star_rgb_color = [ min(max(int(c), 0), 255) for c in colour.XYZ_to_sRGB(star_xyz_color / 100) ] y_position = j * 16 + 1 + y x_position = i * 32 + 1 + x for c in range(3): output_texture[y_position][x_position][ c] = star_rgb_color[c] output_texture[y_position][x_position][3] = 255
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 } sd = colour.SpectralDistribution(sample_sd_data, name='Sample') uncorrected_values = sd.values print(np.dstack([uncorrected_values, colour.bandpass_correction(sd).values]))
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_rendering_index( colour.SpectralDistribution(data_sample, name="Sample")))
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, } sd_base = colour.SpectralDistribution(data_uniform, name="Reference") uniform_interpolated_sd = colour.SpectralDistribution( data_uniform, name="Uniform - Sprague Interpolation") uniform_pchip_interpolated_sd = colour.SpectralDistribution( data_uniform, name="Uniform - Pchip Interpolation") non_uniform_interpolated_sd = colour.SpectralDistribution( data_non_uniform, name="Non Uniform - Cubic Spline Interpolation") uniform_interpolated_sd.interpolate( colour.SpectralShape( uniform_interpolated_sd.shape.start, uniform_interpolated_sd.shape.end, 1, )) uniform_pchip_interpolated_sd.interpolate( colour.SpectralShape(
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_sd = colour.SpectralDistribution(uniform_sd_data, name='Reference') uniform_interpolated_sd = colour.SpectralDistribution( uniform_sd_data, name='Uniform - Sprague Interpolation') uniform_pchip_interpolated_sd = colour.SpectralDistribution( uniform_sd_data, name='Uniform - Pchip Interpolation') non_uniform_interpolated_sd = colour.SpectralDistribution( non_uniform_sd_data, name='Non Uniform - Cubic Spline Interpolation') uniform_interpolated_sd.interpolate(colour.SpectralShape(interval=1)) uniform_pchip_interpolated_sd.interpolate( colour.SpectralShape(interval=1), interpolator=colour.PchipInterpolator) non_uniform_interpolated_sd.interpolate(colour.SpectralShape(interval=1)) shape = base_sd.shape x_limit_min, x_limit_max, y_limit_min, y_limit_max = [], [], [], []
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 distributions.') plot_single_sd(colour.SpectralDistribution(data_sample, name='Custom')) plot_single_sd( colour.SpectralDistribution(data_galvanized_steel_metal, name='Galvanized Steel Metal')) print('\n') message_box('Plotting multiple spectral distributions.') plot_multi_sds((colour.SpectralDistribution(data_galvanized_steel_metal, name='Galvanized Steel Metal'), colour.SpectralDistribution(data_white_marble, name='White Marble'))) print('\n') message_box('Plotting spectral bandpass dependence correction.')
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 distributions.") plot_single_sd(colour.SpectralDistribution(data_sample, name="Custom")) plot_single_sd( colour.SpectralDistribution( data_galvanized_steel_metal, name="Galvanized Steel Metal" ) ) print("\n") message_box("Plotting multiple spectral distributions.") plot_multi_sds( ( colour.SpectralDistribution( data_galvanized_steel_metal, name="Galvanized Steel Metal" ), colour.SpectralDistribution(data_white_marble, name="White Marble"),
sd_r = colour.SpectralDistribution({ 360: 8.575e-136, 362: 7.585e-134, 364: 6.491e-132, 366: 5.372e-130, 368: 4.301e-128, 370: 3.331e-126, 372: 2.495e-124, 374: 1.808e-122, 376: 1.267e-120, 378: 8.591e-119, 380: 5.634e-117, 382: 3.573e-115, 384: 2.193e-113, 386: 1.301e-111, 388: 7.471e-110, 390: 4.149e-108, 392: 2.229e-106, 394: 1.158e-104, 396: 5.819e-103, 398: 2.829e-101, 400: 1.330e-99, 402: 6.051e-98, 404: 2.662e-96, 406: 1.133e-94, 408: 4.665e-93, 410: 1.857e-91, 412: 7.154e-90, 414: 2.666e-88, 416: 9.606e-87, 418: 3.349e-85, 420: 1.129e-83, 422: 3.683e-82, 424: 1.162e-80, 426: 3.546e-79, 428: 1.047e-77, 430: 2.989e-76, 432: 8.256e-75, 434: 2.206e-73, 436: 5.700e-72, 438: 1.425e-70, 440: 3.445e-69, 442: 8.058e-68, 444: 1.823e-66, 446: 3.989e-65, 448: 8.444e-64, 450: 1.729e-62, 452: 3.424e-61, 454: 6.560e-60, 456: 1.216e-58, 458: 2.179e-57, 460: 3.778e-56, 462: 6.336e-55, 464: 1.028e-53, 466: 1.613e-52, 468: 2.448e-51, 470: 3.595e-50, 472: 5.105e-49, 474: 7.013e-48, 476: 9.319e-47, 478: 1.198e-45, 480: 1.489e-44, 482: 1.791e-43, 484: 2.083e-42, 486: 2.344e-41, 488: 2.552e-40, 490: 2.687e-39, 492: 2.736e-38, 494: 2.695e-37, 496: 2.568e-36, 498: 2.367e-35, 500: 2.111e-34, 502: 1.822e-33, 504: 1.521e-32, 506: 1.230e-31, 508: 9.645e-31, 510: 7.340e-30, 512: 5.436e-29, 514: 3.935e-28, 516: 2.800e-27, 518: 1.974e-26, 520: 1.392e-25, 522: 9.882e-25, 524: 7.101e-24, 526: 5.154e-23, 528: 3.753e-22, 530: 2.710e-21, 532: 1.920e-20, 534: 1.321e-19, 536: 8.750e-19, 538: 5.553e-18, 540: 3.361e-17, 542: 1.935e-16, 544: 1.058e-15, 546: 5.487e-15, 548: 2.696e-14, 550: 1.254e-13, 552: 5.524e-13, 554: 2.302e-12, 556: 9.079e-12, 558: 3.387e-11, 560: 1.195e-10, 562: 3.991e-10, 564: 1.260e-09, 566: 3.764e-09, 568: 1.063e-08, 570: 2.842e-08, 572: 7.183e-08, 574: 1.718e-07, 576: 3.885e-07, 578: 8.315e-07, 580: 1.684e-06, 582: 3.228e-06, 584: 5.859e-06, 586: 1.007e-05, 588: 1.642e-05, 590: 2.540e-05, 592: 3.735e-05, 594: 5.233e-05, 596: 7.011e-05, 598: 9.028e-05, 600: 1.125e-04, 602: 1.371e-04, 604: 1.649e-04, 606: 1.983e-04, 608: 2.404e-04, 610: 2.950e-04, 612: 3.654e-04, 614: 4.539e-04, 616: 5.606e-04, 618: 6.835e-04, 620: 8.209e-04, 622: 9.775e-04, 624: 1.174e-03, 626: 1.448e-03, 628: 1.829e-03, 630: 2.281e-03, 632: 2.663e-03, 634: 2.788e-03, 636: 2.566e-03, 638: 2.080e-03, 640: 1.522e-03, 642: 1.052e-03, 644: 7.238e-04, 646: 5.107e-04, 648: 3.681e-04, 650: 2.653e-04, 652: 1.876e-04, 654: 1.290e-04, 656: 8.586e-05, 658: 5.532e-05, 660: 3.447e-05, 662: 2.078e-05, 664: 1.212e-05, 666: 6.835e-06, 668: 3.729e-06, 670: 1.968e-06, 672: 1.005e-06, 674: 4.961e-07, 676: 2.369e-07, 678: 1.095e-07, 680: 4.892e-08, 682: 2.115e-08, 684: 8.842e-09, 686: 3.576e-09, 688: 1.399e-09, 690: 5.294e-10, 692: 1.938e-10, 694: 6.862e-11, 696: 2.350e-11, 698: 7.786e-12, 700: 2.495e-12, 702: 7.734e-13, 704: 2.319e-13, 706: 6.725e-14, 708: 1.887e-14, 710: 5.120e-15, 712: 1.344e-15, 714: 3.412e-16, 716: 8.379e-17, 718: 1.991e-17, 720: 4.574e-18, 722: 1.017e-18, 724: 2.186e-19, 726: 4.546e-20, 728: 9.145e-21, 730: 1.779e-21, 732: 3.349e-22, 734: 6.098e-23, 736: 1.074e-23, 738: 1.829e-24, 740: 3.014e-25, 742: 4.804e-26, 744: 7.406e-27, 746: 1.104e-27, 748: 1.593e-28, 750: 2.223e-29, 752: 3.000e-30, 754: 3.917e-31, 756: 4.946e-32, 758: 6.042e-33, 760: 7.139e-34, 762: 8.159e-35, 764: 9.020e-36, 766: 9.646e-37, 768: 9.977e-38, 770: 9.983e-39, 772: 9.661e-40, 774: 9.044e-41, 776: 8.190e-42, 778: 7.174e-43, 780: 6.078e-44, 782: 4.981e-45, 784: 3.949e-46, 786: 3.028e-47, 788: 2.246e-48, 790: 1.611e-49, 792: 1.118e-50, 794: 7.506e-52, 796: 4.874e-53, 798: 3.061e-54, 800: 1.860e-55, 802: 1.093e-56, 804: 6.213e-58, 806: 3.416e-59, 808: 1.817e-60, 810: 9.348e-62, 812: 4.652e-63, 814: 2.239e-64, 816: 1.043e-65, 818: 4.696e-67, 820: 2.046e-68, 822: 8.621e-70, 824: 3.514e-71, 826: 1.386e-72, 828: 5.284e-74, 830: 1.949e-75, }, interpolator=colour.CubicSplineInterpolator, name='red')