def get_blackbody_illuminant (T_K): '''Get the spectrum of a blackbody at the given temperature, normalized to Y = 1.0.''' illuminant = blackbody.blackbody_spectrum (T_K) xyz = ciexyz.xyz_from_spectrum (illuminant) if xyz [1] != 0.0: scaling = 1.0 / xyz [1] illuminant [:,1] *= scaling return illuminant
def get_blackbody_illuminant(T_K): '''Get the spectrum of a blackbody at the given temperature, normalized to Y = 1.0.''' illuminant = blackbody.blackbody_spectrum(T_K) xyz = ciexyz.xyz_from_spectrum(illuminant) if xyz[1] != 0.0: scaling = 1.0 / xyz[1] illuminant[:, 1] *= scaling return illuminant
def test_coverage_2(self, verbose=False): ''' Another coverage test. ''' empty = ciexyz.empty_spectrum() xyz = ciexyz.xyz_from_spectrum(empty) if verbose: print('black = %s' % (str(xyz))) xyz_555 = ciexyz.xyz_from_wavelength(555.0) if verbose: print('555 nm = %s' % (str(xyz_555)))
def test_coverage_2(self, verbose=False): ''' Another coverage test. ''' empty = ciexyz.empty_spectrum () xyz = ciexyz.xyz_from_spectrum (empty) if verbose: print ('black = %s' % (str (xyz))) xyz_555 = ciexyz.xyz_from_wavelength (555.0) if verbose: print ('555 nm = %s' % (str (xyz_555)))
def get_constant_illuminant (): '''Get an illuminant, with spectrum constant over wavelength, normalized to Y = 1.0.''' illuminant = ciexyz.empty_spectrum() (num_wl, num_cols) = illuminant.shape for i in xrange (0, num_wl): illuminant [i][1] = 1.0 xyz = ciexyz.xyz_from_spectrum (illuminant) if xyz [1] != 0.0: scaling = 1.0 / xyz [1] illuminant [:,1] *= scaling return illuminant
def get_constant_illuminant(): '''Get an illuminant, with spectrum constant over wavelength, normalized to Y = 1.0.''' illuminant = ciexyz.empty_spectrum() (num_wl, num_cols) = illuminant.shape for i in range(0, num_wl): illuminant[i][1] = 1.0 xyz = ciexyz.xyz_from_spectrum(illuminant) if xyz[1] != 0.0: scaling = 1.0 / xyz[1] illuminant[:, 1] *= scaling return illuminant
def test_scattering(self, verbose=False): ''' Test of scattering calculations. ''' # Coverage test of rayleigh_scattering_spectrum(). rayleigh.rayleigh_scattering_spectrum() illum = illuminants.get_illuminant_D65() spect = rayleigh.rayleigh_illuminated_spectrum(illum) # Both color calculations should give the same result. xyz1 = ciexyz.xyz_from_spectrum(spect) xyz2 = rayleigh.rayleigh_illuminated_color(illum) atol = 1.0e-16 ok = numpy.allclose(xyz1, xyz2, atol=atol) self.assertTrue(ok) msg = 'D65 Rayleigh scattered xyz: %s, %s' % (str(xyz1), str(xyz2)) if verbose: print(msg)
def test_scattering(self, verbose=False): ''' Test of scattering calculations. ''' # Coverage test of rayleigh_scattering_spectrum(). rayleigh.rayleigh_scattering_spectrum() illum = illuminants.get_illuminant_D65() spect = rayleigh.rayleigh_illuminated_spectrum (illum) # Both color calculations should give the same result. xyz1 = ciexyz.xyz_from_spectrum (spect) xyz2 = rayleigh.rayleigh_illuminated_color (illum) atol = 1.0e-16 ok = numpy.allclose(xyz1, xyz2, atol=atol) self.assertTrue(ok) msg = 'D65 Rayleigh scattered xyz: %s, %s' % (str(xyz1), str(xyz2)) if verbose: print (msg)
def init(): """Initialize CIE Illuminant D65. This runs on module startup.""" first_wl = _Illuminant_D65_table[0][0] # for now, only consider the part in the normal visible range (360-830 nm) first_index = ciexyz.start_wl_nm - first_wl table_first = _Illuminant_D65_table[first_index][0] assert table_first == 360, "Mismatch finding 360 nm entry in D65 table" global _Illuminant_D65 _Illuminant_D65 = ciexyz.empty_spectrum() (num_wl, num_cols) = _Illuminant_D65.shape for i in range(0, num_wl): _Illuminant_D65[i][1] = _Illuminant_D65_table[first_index + i][1] # normalization - illuminant is scaled so that Y = 1.0 xyz = ciexyz.xyz_from_spectrum(_Illuminant_D65) scaling = 1.0 / xyz[1] _Illuminant_D65[:, 1] *= scaling
def test(verbose=0): '''Test the CIE XYZ conversions. Mainly call some functions.''' for i in range(0, 100): wl_nm = 1000.0 * random.random() xyz = ciexyz.xyz_from_wavelength(wl_nm) if verbose >= 1: print('wl_nm = %g, xyz = %s' % (wl_nm, str(xyz))) for i in range(0, 10): empty = ciexyz.empty_spectrum() xyz = ciexyz.xyz_from_spectrum(empty) if verbose >= 1: print('black = %s' % str(xyz)) xyz_555 = ciexyz.xyz_from_wavelength(555.0) if verbose >= 1: print('555 nm = %s' % str(xyz_555)) print('test_ciexyz.test() passed.')
def init(): '''Initialize CIE Illuminant D65. This runs on module startup.''' first_wl = _Illuminant_D65_table[0][0] # for now, only consider the part in the normal visible range (360-830 nm) first_index = ciexyz.start_wl_nm - first_wl table_first = _Illuminant_D65_table[first_index][0] assert (table_first == 360), 'Mismatch finding 360 nm entry in D65 table' global _Illuminant_D65 _Illuminant_D65 = ciexyz.empty_spectrum() (num_wl, num_cols) = _Illuminant_D65.shape for i in range(0, num_wl): _Illuminant_D65[i][1] = _Illuminant_D65_table[first_index + i][1] # normalization - illuminant is scaled so that Y = 1.0 xyz = ciexyz.xyz_from_spectrum(_Illuminant_D65) scaling = 1.0 / xyz[1] _Illuminant_D65[:, 1] *= scaling
def test (verbose=0): '''Test the CIE XYZ conversions. Mainly call some functions.''' for i in xrange (0, 100): wl_nm = 1000.0 * random.random() xyz = ciexyz.xyz_from_wavelength (wl_nm) if verbose >= 1: print 'wl_nm = %g, xyz = %s' % (wl_nm, str (xyz)) for i in xrange (0, 10): empty = ciexyz.empty_spectrum () xyz = ciexyz.xyz_from_spectrum (empty) if verbose >= 1: print 'black = %s' % (str (xyz)) xyz_555 = ciexyz.xyz_from_wavelength (555.0) if verbose >= 1: print '555 nm = %s' % (str (xyz_555)) print 'test_ciexyz.test() passed.'
def spectrum_plot ( spectrum, title, filename = None, xlabel = 'Wavelength ($nm$)', ylabel = 'Intensity ($W/m^2$)'): '''Plot for a single spectrum - In a two part graph, plot: top: color of the spectrum, as a large patch. low: graph of spectrum intensity vs wavelength (x axis). The graph is colored by the (approximated) color of each wavelength. Each wavelength has equal physical intensity, so the variation in apparent intensity (e.g. 400, 800 nm are very dark, 550 nm is bright), is due to perceptual factors in the eye. This helps show how much each wavelength contributes to the percieved color. spectrum - spectrum to plot title - title for plot filename - filename to save plot to xlabel - label for x axis ylabel - label for y axis ''' pylab.clf () # upper plot - solid patch of color that matches the spectrum color pylab.subplot (2,1,1) pylab.title (title) color_string = colormodels.irgb_string_from_rgb ( colormodels.rgb_from_xyz (ciexyz.xyz_from_spectrum (spectrum))) poly_x = [0.0, 1.0, 1.0, 0.0] poly_y = [0.0, 0.0, 1.0, 1.0] pylab.fill (poly_x, poly_y, color_string) # draw a solid line around the patch to look nicer pylab.plot (poly_x, poly_y, color='k', linewidth=2.0) pylab.axis ('off') # lower plot - spectrum vs wavelength, with colors of the associated spectral lines below pylab.subplot (2,1,2) spectrum_subplot (spectrum) tighten_x_axis (spectrum [:,0]) pylab.xlabel (xlabel) pylab.ylabel (ylabel) # done if filename is not None: print 'Saving plot %s' % str (filename) pylab.savefig (filename)
def spectrum_plot(spectrum, title, filename, xlabel='Wavelength ($nm$)', ylabel='Intensity ($W/m^2$)'): '''Plot for a single spectrum - In a two part graph, plot: top: color of the spectrum, as a large patch. low: graph of spectrum intensity vs wavelength (x axis). The graph is colored by the (approximated) color of each wavelength. Each wavelength has equal physical intensity, so the variation in apparent intensity (e.g. 400, 800 nm are very dark, 550 nm is bright), is due to perceptual factors in the eye. This helps show how much each wavelength contributes to the percieved color. spectrum - spectrum to plot title - title for plot filename - filename to save plot to xlabel - label for x axis ylabel - label for y axis ''' pylab.clf() # upper plot - solid patch of color that matches the spectrum color pylab.subplot(2, 1, 1) pylab.title(title) color_string = colormodels.irgb_string_from_rgb( colormodels.rgb_from_xyz(ciexyz.xyz_from_spectrum(spectrum))) poly_x = [0.0, 1.0, 1.0, 0.0] poly_y = [0.0, 0.0, 1.0, 1.0] pylab.fill(poly_x, poly_y, color_string) # draw a solid line around the patch to look nicer pylab.plot(poly_x, poly_y, color='k', linewidth=2.0) pylab.axis('off') # lower plot - spectrum vs wavelength, with colors of the associated spectral lines below pylab.subplot(2, 1, 2) spectrum_subplot(spectrum) tighten_x_axis(spectrum[:, 0]) pylab.xlabel(xlabel) pylab.ylabel(ylabel) # done print 'Saving plot %s' % str(filename) pylab.savefig(filename)
def blackbody_color(T_K): '''Given a temperature (K), return the xyz color of a thermal blackbody.''' spectrum = blackbody_spectrum(T_K) xyz = ciexyz.xyz_from_spectrum(spectrum) return xyz
def rayleigh_illuminated_color (illuminant): '''Get the xyz color when illuminated by the specified illuminant.''' spectrum = rayleigh_illuminated_spectrum (illuminant) xyz = ciexyz.xyz_from_spectrum (spectrum) return xyz
def blackbody_color (T_K): '''Given a temperature (K), return the xyz color of a thermal blackbody.''' spectrum = blackbody_spectrum (T_K) xyz = ciexyz.xyz_from_spectrum (spectrum) return xyz
wavel_df = pd.read_pickle("wavel_df.pkl") wavel_array = wavel_df.iloc[0:].values inten_df = pd.read_csv( 'C:/Users/juanr/Documents/data_mediciones/simultaneidad/defectoColorinche/inten50x50cuadrado.dat', header=None, sep=',', engine='python') inten_array = inten_df.iloc[:, 0:].values list_of_colors = [] for row in range(len(inten_array)): spectra = np.column_stack((wavel_array, inten_array[row, :])) xyz_color_vec = xyz_from_spectrum(spectra) rgb_disp = irgb_from_xyz(xyz_color_vec) list_of_colors.append(rgb_disp) rgb_matrix = np.asarray(list_of_colors) R_array = rgb_matrix[:, 0] G_array = rgb_matrix[:, 1] B_array = rgb_matrix[:, 2] R = R_array.reshape(50, 50) G = G_array.reshape(50, 50) B = B_array.reshape(50, 50) img = np.empty((50, 50, 3), dtype=np.uint16) img[:, :, 0] = R img[:, :, 1] = G
def rayleigh_illuminated_color(illuminant): '''Get the xyz color when illuminated by the specified illuminant.''' spectrum = rayleigh_illuminated_spectrum(illuminant) xyz = ciexyz.xyz_from_spectrum(spectrum) return xyz
def illuminated_color(self, illuminant): '''Get the xyz color when illuminated by the specified illuminant.''' spectrum = self.illuminated_spectrum(illuminant) xyz = ciexyz.xyz_from_spectrum(spectrum) return xyz
def illuminated_color (self, illuminant): '''Get the xyz color when illuminated by the specified illuminant.''' spectrum = self.illuminated_spectrum (illuminant) xyz = ciexyz.xyz_from_spectrum (spectrum) return xyz