コード例 #1
0
 def check_xyz_irgb(self, xyz0, verbose):
     ''' Check the direct conversions from xyz to irgb. '''
     irgb0 = colormodels.irgb_from_rgb(colormodels.rgb_from_xyz(xyz0))
     irgb1 = colormodels.irgb_from_xyz(xyz0)
     self.assertEqual(irgb0[0], irgb1[0])
     self.assertEqual(irgb0[1], irgb1[1])
     self.assertEqual(irgb0[2], irgb1[2])
     # The string should also match.
     irgbs0 = colormodels.irgb_string_from_rgb(
         colormodels.rgb_from_xyz(xyz0))
     irgbs1 = colormodels.irgb_string_from_xyz(xyz0)
     msg = 'irgb0: %s    text0: %s        irgb1: %s    text1: %s' % (
         str(irgb0), irgbs0, str(irgb1), irgbs1)
     if verbose:
         print(msg)
     self.assertEqual(irgbs0, irgbs1)
コード例 #2
0
 def check_xyz_irgb(self, xyz0, verbose):
     ''' Check the direct conversions from xyz to irgb. '''
     irgb0 = colormodels.irgb_from_rgb (
         colormodels.rgb_from_xyz (xyz0))
     irgb1 = colormodels.irgb_from_xyz (xyz0)
     self.assertEqual(irgb0[0], irgb1[0])
     self.assertEqual(irgb0[1], irgb1[1])
     self.assertEqual(irgb0[2], irgb1[2])
     # The string should also match.
     irgbs0 = colormodels.irgb_string_from_rgb (
         colormodels.rgb_from_xyz (xyz0))
     irgbs1 = colormodels.irgb_string_from_xyz (xyz0)
     msg = 'irgb0: %s    text0: %s        irgb1: %s    text1: %s' % (
         str(irgb0), irgbs0, str(irgb1), irgbs1)
     if verbose:
         print (msg)
     self.assertEqual(irgbs0, irgbs1)
コード例 #3
0
ファイル: test_colormodels.py プロジェクト: sseo42/Univ_TMM
def test_xyz_irgb(verbose=1):
    '''Test the direct conversions from xyz to irgb.'''
    for i in xrange(0, 100):
        x0 = 10.0 * random.random()
        y0 = 10.0 * random.random()
        z0 = 10.0 * random.random()
        xyz0 = colormodels.xyz_color(x0, y0, z0)
        irgb0 = colormodels.irgb_from_rgb(colormodels.rgb_from_xyz(xyz0))
        irgb1 = colormodels.irgb_from_xyz(xyz0)
        if (irgb0[0] != irgb1[0]) or (irgb0[1] != irgb1[1]) or (irgb0[2] !=
                                                                irgb1[2]):
            raise ValueError
        irgbs0 = colormodels.irgb_string_from_rgb(
            colormodels.rgb_from_xyz(xyz0))
        irgbs1 = colormodels.irgb_string_from_xyz(xyz0)
        if irgbs0 != irgbs1:
            raise ValueError
    print('Passed test_xyz_irgb()')
コード例 #4
0
ファイル: test_colormodels.py プロジェクト: Stanpol/ColorPy
def test_xyz_irgb (verbose=1):
    '''Test the direct conversions from xyz to irgb.'''
    for i in xrange (0, 100):
        x0 = 10.0 * random.random()
        y0 = 10.0 * random.random()
        z0 = 10.0 * random.random()
        xyz0 = colormodels.xyz_color (x0,y0,z0)
        irgb0 = colormodels.irgb_from_rgb (
            colormodels.rgb_from_xyz (xyz0))
        irgb1 = colormodels.irgb_from_xyz (xyz0)
        if (irgb0[0] != irgb1[0]) or (irgb0[1] != irgb1[1]) or (irgb0[2] != irgb1[2]):
            raise ValueError
        irgbs0 = colormodels.irgb_string_from_rgb (
            colormodels.rgb_from_xyz (xyz0))
        irgbs1 = colormodels.irgb_string_from_xyz (xyz0)
        if irgbs0 != irgbs1:
            raise ValueError
    print 'Passed test_xyz_irgb()'
コード例 #5
0
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
img[:, :, 2] = B
コード例 #6
0
ファイル: misc.py プロジェクト: GyonShojaah/FitAltogether
def perceptually_uniform_spectral_colors (
    brightness = 1.0,
    plot_name  = 'PerceptuallyEqualColors',
    plot_title = 'Perceptually (almost) Equally Spaced Pure Colors',
    table_name = 'percep_equal_names.txt'):
    '''Patch plot of (nearly) perceptually equally spaced colors, covering the pure spectral lines plus purples.'''
    # TODO - This may or may not be quite right...
    # get pure colors
#    xyzs = ciexyz.get_normalized_spectral_line_colors (brightness=1.0, num_purples=200, dwl_angstroms=1)
    (xyzs, names) = ciexyz.get_normalized_spectral_line_colors_annotated (brightness=brightness, num_purples=200, dwl_angstroms=1)
    (num_colors, num_columns) = xyzs.shape

    # pick these two functions for either Luv or Lab
    uniform_from_xyz = colormodels.luv_from_xyz
    xyz_from_uniform = colormodels.xyz_from_luv
    #uniform_from_xyz = colormodels.lab_from_xyz
    #xyz_from_uniform = colormodels.xyz_from_lab

    # convert colors to a nearly perceptually uniform space
    uniforms = numpy.empty ((num_colors, 3))
    for i in range (0, num_colors):
        uniforms [i] = uniform_from_xyz (xyzs [i])
    # determine spacing
    sum_ds = 0.0
    dss = numpy.empty ((num_colors, 1))
    for i in range (0, num_colors-1):
        dri = uniforms [i+1] - uniforms [i]
        dsi = math.sqrt (numpy.dot (dri, dri))
        dss [i] = dsi
        sum_ds += dsi
    # last point closes the curve
    dri = uniforms [0] - uniforms [num_colors - 1]
    dsi = math.sqrt (numpy.dot (dri, dri))
    dss [num_colors - 1] = dsi
    sum_ds += dsi
    # pick out subsamples as evenly spaced as possible
    num_samples = 160
    ds_avg = sum_ds / float (num_samples - 1)
    E_indices = []
    index = 0
    count = 0
    need = 0.0
    while True:
        while need > 1.0e-10:
            need -= dss [index]
            index += 1
        E_indices.append (index)
        need += ds_avg
        count += 1
        if count >= num_samples:
            break
    # patch plot and save names
    xyz_list = []
    fil = open (table_name, 'wt')
    fil.write ('%s\n' % plot_title)
    fil.write ('Name iRGB\n')
    fil.write ('\n')
    for index in E_indices:
        uniform_color = uniforms [index]
        uniform_xyz   = xyz_from_uniform (uniform_color)
        uniform_irgb  = colormodels.irgb_from_xyz (uniform_xyz)
        uniform_name  = names [index]
        xyz_list.append (uniform_xyz)
        fil.write ('%s %s\n' % (uniform_name, str (uniform_irgb)))
    fil.close ()
    plots.xyz_patch_plot (
        xyz_list, None, plot_title, plot_name, num_across=20)
コード例 #7
0
ファイル: misc.py プロジェクト: ww9980/ColorPy
def perceptually_uniform_spectral_colors(
        brightness=1.0,
        plot_name='PerceptuallyEqualColors',
        plot_title='Perceptually (almost) Equally Spaced Pure Colors',
        table_name='percep_equal_names.txt'):
    '''Patch plot of (nearly) perceptually equally spaced colors, covering the pure spectral lines plus purples.'''
    # TODO - This may or may not be quite right...
    # get pure colors
    #    xyzs = ciexyz.get_normalized_spectral_line_colors (brightness=1.0, num_purples=200, dwl_angstroms=1)
    (xyzs, names) = ciexyz.get_normalized_spectral_line_colors_annotated(
        brightness=brightness, num_purples=200, dwl_angstroms=1)
    (num_colors, num_columns) = xyzs.shape

    # pick these two functions for either Luv or Lab
    uniform_from_xyz = colormodels.luv_from_xyz
    xyz_from_uniform = colormodels.xyz_from_luv
    #uniform_from_xyz = colormodels.lab_from_xyz
    #xyz_from_uniform = colormodels.xyz_from_lab

    # convert colors to a nearly perceptually uniform space
    uniforms = numpy.empty((num_colors, 3))
    for i in range(0, num_colors):
        uniforms[i] = uniform_from_xyz(xyzs[i])
    # determine spacing
    sum_ds = 0.0
    dss = numpy.empty((num_colors, 1))
    for i in range(0, num_colors - 1):
        dri = uniforms[i + 1] - uniforms[i]
        dsi = math.sqrt(numpy.dot(dri, dri))
        dss[i] = dsi
        sum_ds += dsi
    # last point closes the curve
    dri = uniforms[0] - uniforms[num_colors - 1]
    dsi = math.sqrt(numpy.dot(dri, dri))
    dss[num_colors - 1] = dsi
    sum_ds += dsi
    # pick out subsamples as evenly spaced as possible
    num_samples = 160
    ds_avg = sum_ds / float(num_samples - 1)
    E_indices = []
    index = 0
    count = 0
    need = 0.0
    while True:
        while need > 1.0e-10:
            need -= dss[index]
            index += 1
        E_indices.append(index)
        need += ds_avg
        count += 1
        if count >= num_samples:
            break
    # patch plot and save names
    xyz_list = []
    fil = open(table_name, 'wt')
    fil.write('%s\n' % plot_title)
    fil.write('Name iRGB\n')
    fil.write('\n')
    for index in E_indices:
        uniform_color = uniforms[index]
        uniform_xyz = xyz_from_uniform(uniform_color)
        uniform_irgb = colormodels.irgb_from_xyz(uniform_xyz)
        uniform_name = names[index]
        xyz_list.append(uniform_xyz)
        fil.write('%s %s\n' % (uniform_name, str(uniform_irgb)))
    fil.close()
    plots.xyz_patch_plot(xyz_list, None, plot_title, plot_name, num_across=20)