Пример #1
0
def test_clipping (verbose=1):
    '''Test the various color clipping methods.'''
    xyz_colors = ciexyz.get_normalized_spectral_line_colors ()
    #print 'xyz_colors', xyz_colors
    (num_wl, num_cols) = xyz_colors.shape
    # get rgb values for standard clipping
    colormodels.init_clipping (colormodels.CLIP_ADD_WHITE)
    rgb_add_white = []
    for i in xrange (0, num_wl):
        color = colormodels.irgb_string_from_rgb (
            colormodels.rgb_from_xyz (xyz_colors [i]))
        rgb_add_white.append (color)
    # get rgb values for clamp clipping
    colormodels.init_clipping (colormodels.CLIP_CLAMP_TO_ZERO)
    rgb_clamp = []
    for i in xrange (0, num_wl):
        color = colormodels.irgb_string_from_rgb (
            colormodels.rgb_from_xyz (xyz_colors [i]))
        rgb_clamp.append (color)
    # compare
    if verbose >= 1:
        print 'colors from add white, colors from clamp'
        for i in xrange (0, num_wl):
            print rgb_add_white [i], rgb_clamp [i]
    print 'Passed test_clipping()'
Пример #2
0
def test_clipping(verbose=1):
    '''Test the various color clipping methods.'''
    xyz_colors = ciexyz.get_normalized_spectral_line_colors()
    #print 'xyz_colors', xyz_colors
    (num_wl, num_cols) = xyz_colors.shape
    # get rgb values for standard clipping
    colormodels.init_clipping(colormodels.CLIP_ADD_WHITE)
    rgb_add_white = []
    for i in xrange(0, num_wl):
        color = colormodels.irgb_string_from_rgb(
            colormodels.rgb_from_xyz(xyz_colors[i]))
        rgb_add_white.append(color)
    # get rgb values for clamp clipping
    colormodels.init_clipping(colormodels.CLIP_CLAMP_TO_ZERO)
    rgb_clamp = []
    for i in xrange(0, num_wl):
        color = colormodels.irgb_string_from_rgb(
            colormodels.rgb_from_xyz(xyz_colors[i]))
        rgb_clamp.append(color)
    # compare
    if verbose >= 1:
        print('colors from add white, colors from clamp')
        for i in xrange(0, num_wl):
            print(rgb_add_white[i], rgb_clamp[i])
    print('Passed test_clipping()')
Пример #3
0
def spectrum_subplot(spectrum):
    '''Plot a spectrum, with x-axis the wavelength, and y-axis the intensity.
    The curve is colored at that wavelength by the (approximate) color of a
    pure spectral color at that wavelength, with intensity constant over wavelength.
    (This means that dark looking colors here mean that wavelength is poorly viewed by the eye.

    This is not a complete plotting function, e.g. no file is saved, etc.
    It is assumed that this function is being called by one that handles those things.'''
    (num_wl, num_cols) = spectrum.shape
    # get rgb colors for each wavelength
    rgb_colors = numpy.empty((num_wl, 3))
    for i in range(0, num_wl):
        wl_nm = spectrum[i][0]
        xyz = ciexyz.xyz_from_wavelength(wl_nm)
        rgb_colors[i] = colormodels.rgb_from_xyz(xyz)
    # scale to make brightest rgb value = 1.0
    rgb_max = numpy.max(rgb_colors)
    scaling = 1.0 / rgb_max
    rgb_colors *= scaling
    # draw color patches (thin vertical lines matching the spectrum curve) in color
    for i in range(0,
                   num_wl - 1):  # skipping the last one here to stay in range
        x0 = spectrum[i][0]
        x1 = spectrum[i + 1][0]
        y0 = spectrum[i][1]
        y1 = spectrum[i + 1][1]
        poly_x = [x0, x1, x1, x0]
        poly_y = [0.0, 0.0, y1, y0]
        color_string = colormodels.irgb_string_from_rgb(rgb_colors[i])
        pylab.fill(poly_x, poly_y, color_string, edgecolor=color_string)
    # plot intensity as a curve
    w = spectrum[:, 0]
    I = spectrum[:, 1]
    return w, I
Пример #4
0
def spectrum_subplot (spectrum):
    '''Plot a spectrum, with x-axis the wavelength, and y-axis the intensity.
    The curve is colored at that wavelength by the (approximate) color of a
    pure spectral color at that wavelength, with intensity constant over wavelength.
    (This means that dark looking colors here mean that wavelength is poorly viewed by the eye.

    This is not a complete plotting function, e.g. no file is saved, etc.
    It is assumed that this function is being called by one that handles those things.'''
    (num_wl, num_cols) = spectrum.shape
    # get rgb colors for each wavelength
    rgb_colors = numpy.empty ((num_wl, 3))
    for i in xrange (0, num_wl):
        wl_nm = spectrum [i][0]
        xyz = ciexyz.xyz_from_wavelength (wl_nm)
        rgb_colors [i] = colormodels.rgb_from_xyz (xyz)
    # scale to make brightest rgb value = 1.0
    rgb_max = numpy.max (rgb_colors)
    scaling = 1.0 / rgb_max
    rgb_colors *= scaling        
    # draw color patches (thin vertical lines matching the spectrum curve) in color
    for i in xrange (0, num_wl-1):    # skipping the last one here to stay in range
        x0 = spectrum [i][0]
        x1 = spectrum [i+1][0]
        y0 = spectrum [i][1]
        y1 = spectrum [i+1][1]
        poly_x = [x0,  x1,  x1, x0]
        poly_y = [0.0, 0.0, y1, y0]
        color_string = colormodels.irgb_string_from_rgb (rgb_colors [i])
        pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string)
    # plot intensity as a curve
    pylab.plot (
        spectrum [:,0], spectrum [:,1],
        color='k', linewidth=2.0, antialiased=True)
Пример #5
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)
Пример #6
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)
Пример #7
0
 def check_xyz_rgb(self, xyz0, verbose):
     ''' Check that the xyz color, converted to rgb then back, remains the same. '''
     rgb0 = colormodels.rgb_from_xyz (xyz0)
     xyz1 = colormodels.xyz_from_rgb (rgb0)
     rgb1 = colormodels.rgb_from_xyz (xyz1)
     # Check errors.
     err_rgb = rgb1 - rgb0
     error_rgb = math.sqrt (numpy.dot (err_rgb, err_rgb))
     err_xyz = xyz1 - xyz0
     error_xyz = math.sqrt (numpy.dot (err_xyz, err_xyz))
     tolerance = 1.0e-10
     self.assertLess(error_xyz, tolerance)
     self.assertLess(error_rgb, tolerance)
     msg = 'xyz: %s    rgb: %s    xyz2: %s    rgb2: %s' % (
         str(xyz0), str(rgb0), str(xyz1), str(rgb1))
     if verbose:
         print (msg)
Пример #8
0
 def check_xyz_rgb(self, xyz0, verbose):
     ''' Check that the xyz color, converted to rgb then back, remains the same. '''
     rgb0 = colormodels.rgb_from_xyz(xyz0)
     xyz1 = colormodels.xyz_from_rgb(rgb0)
     rgb1 = colormodels.rgb_from_xyz(xyz1)
     # Check errors.
     err_rgb = rgb1 - rgb0
     error_rgb = math.sqrt(numpy.dot(err_rgb, err_rgb))
     err_xyz = xyz1 - xyz0
     error_xyz = math.sqrt(numpy.dot(err_xyz, err_xyz))
     tolerance = 1.0e-10
     self.assertLess(error_xyz, tolerance)
     self.assertLess(error_rgb, tolerance)
     msg = 'xyz: %s    rgb: %s    xyz2: %s    rgb2: %s' % (
         str(xyz0), str(rgb0), str(xyz1), str(rgb1))
     if verbose:
         print(msg)
Пример #9
0
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()')
Пример #10
0
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()'
Пример #11
0
    def test_clipping(self, verbose=False):
        ''' Test the various color clipping methods. '''
        # This is just a coverage test.
        xyz_colors = ciexyz.get_normalized_spectral_line_colors ()
        num_wl = xyz_colors.shape[0]
        for i in range (num_wl):
            # Get rgb values for standard add white clipping.
            colormodels.init_clipping (colormodels.CLIP_ADD_WHITE)
            rgb_white_color = colormodels.irgb_string_from_rgb (
                colormodels.rgb_from_xyz (xyz_colors [i]))

            # Get rgb values for clamp-to-zero clipping.
            colormodels.init_clipping (colormodels.CLIP_CLAMP_TO_ZERO)
            rgb_clamp_color = colormodels.irgb_string_from_rgb (
                colormodels.rgb_from_xyz (xyz_colors [i]))

            msg = 'Wavelength: %s    White: %s    Clamp: %s' % (
                str(i),    # FIXME: Put in Angstroms.
                rgb_white_color,
                rgb_clamp_color)
            if verbose:
                print (msg)
Пример #12
0
def xyz_patch_plot (
    xyz_colors,
    color_names,
    title,
    filename = None,
    patch_gap = 0.05,
    num_across = 6):
    '''Draw a set of color patches specified as xyz colors.'''
    rgb_colors = []
    for xyz in xyz_colors:
        rgb = colormodels.rgb_from_xyz (xyz)
        rgb_colors.append (rgb)
    rgb_patch_plot (rgb_colors, color_names, title, filename, patch_gap=patch_gap, num_across=num_across)
Пример #13
0
 def test_A (xyz0, tolerance=1.0e-10, verbose=1):
     rgb0 = colormodels.rgb_from_xyz (xyz0)
     xyz1 = colormodels.xyz_from_rgb (rgb0)
     rgb1 = colormodels.rgb_from_xyz (xyz1)
     # check errors
     err_rgb = rgb1 - rgb0
     error_rgb = math.sqrt (numpy.dot (err_rgb, err_rgb))
     err_xyz = xyz1 - xyz0
     error_xyz = math.sqrt (numpy.dot (err_xyz, err_xyz))
     passed = (error_rgb <= tolerance) and (error_xyz <= tolerance)
     if passed:
         status = 'pass'
     else:
         status = 'FAILED'
     msg = 'test_xyz_rgb.test_A() : xyz0 = %s, rgb(xyz0) = %s, xyz(rgb(xyz0)) = %s, rgb(xyz(rgb(xyz0))) = %s, errors = (%g, %g), %s' % (
         str (xyz0), str (rgb0), str (xyz1), str (rgb1), error_rgb, error_xyz, status)
     if verbose >= 1:
         print msg
     if not passed:
         pass
         raise ValueError, msg
     return passed
Пример #14
0
    def test_clipping(self, verbose=False):
        ''' Test the various color clipping methods. '''
        # This is just a coverage test.
        xyz_colors = ciexyz.get_normalized_spectral_line_colors()
        num_wl = xyz_colors.shape[0]
        for i in range(num_wl):
            # Get rgb values for standard add white clipping.
            colormodels.init_clipping(colormodels.CLIP_ADD_WHITE)
            rgb_white_color = colormodels.irgb_string_from_rgb(
                colormodels.rgb_from_xyz(xyz_colors[i]))

            # Get rgb values for clamp-to-zero clipping.
            colormodels.init_clipping(colormodels.CLIP_CLAMP_TO_ZERO)
            rgb_clamp_color = colormodels.irgb_string_from_rgb(
                colormodels.rgb_from_xyz(xyz_colors[i]))

            msg = 'Wavelength: %s    White: %s    Clamp: %s' % (
                str(i),  # FIXME: Put in Angstroms.
                rgb_white_color,
                rgb_clamp_color)
            if verbose:
                print(msg)
Пример #15
0
 def test_A(xyz0, tolerance=1.0e-10, verbose=1):
     rgb0 = colormodels.rgb_from_xyz(xyz0)
     xyz1 = colormodels.xyz_from_rgb(rgb0)
     rgb1 = colormodels.rgb_from_xyz(xyz1)
     # check errors
     err_rgb = rgb1 - rgb0
     error_rgb = math.sqrt(numpy.dot(err_rgb, err_rgb))
     err_xyz = xyz1 - xyz0
     error_xyz = math.sqrt(numpy.dot(err_xyz, err_xyz))
     passed = (error_rgb <= tolerance) and (error_xyz <= tolerance)
     if passed:
         status = 'pass'
     else:
         status = 'FAILED'
     msg = 'test_xyz_rgb.test_A() : xyz0 = %s, rgb(xyz0) = %s, xyz(rgb(xyz0)) = %s, rgb(xyz(rgb(xyz0))) = %s, errors = (%g, %g), %s' % (
         str(xyz0), str(rgb0), str(xyz1), str(rgb1), error_rgb, error_xyz,
         status)
     if verbose >= 1:
         print(msg)
     if not passed:
         pass
         raise ValueError(msg)
     return passed
Пример #16
0
def thinfilm_color_vs_thickness_plot(n1, n2, n3, thickness_nm_list, illuminant,
                                     title, filename):
    '''Plot the color of the thin film for the specfied thicknesses [nm].'''
    num_thick = len(thickness_nm_list)
    rgb_list = numpy.empty((num_thick, 3))
    for i in xrange(0, num_thick):
        film = thin_film(n1, n2, n3, thickness_nm_list[i])
        xyz = film.illuminated_color(illuminant)
        rgb_list[i] = colormodels.rgb_from_xyz(xyz)
    plots.color_vs_param_plot(thickness_nm_list,
                              rgb_list,
                              title,
                              filename,
                              xlabel=r'Thickness (nm)',
                              ylabel=r'RGB Color')
Пример #17
0
def thinfilm_color_vs_thickness_plot (n1, n2, n3, thickness_nm_list, illuminant, title, filename):
    '''Plot the color of the thin film for the specfied thicknesses [nm].'''
    films = create_thin_films(n1, n2, n3, thickness_nm_list)
    num_films = len (films)
    rgb_list = numpy.empty ((num_films, 3))
    for i in range (0, num_films):
        film = films[i]
        xyz = film.illuminated_color (illuminant)
        rgb_list [i] = colormodels.rgb_from_xyz (xyz)
    plots.color_vs_param_plot (
        thickness_nm_list,
        rgb_list,
        title,
        filename,
        xlabel = r'Thickness (nm)',
        ylabel = r'RGB Color')
Пример #18
0
def xyz_patch_plot(xyz_colors,
                   color_names,
                   title,
                   filename,
                   patch_gap=0.05,
                   num_across=6):
    '''Draw a set of color patches specified as xyz colors.'''
    rgb_colors = []
    for xyz in xyz_colors:
        rgb = colormodels.rgb_from_xyz(xyz)
        rgb_colors.append(rgb)
    rgb_patch_plot(rgb_colors,
                   color_names,
                   title,
                   filename,
                   patch_gap=patch_gap,
                   num_across=num_across)
Пример #19
0
def blackbody_color_vs_temperature_plot(T_list, title, filename):
    '''Draw a color vs temperature plot for the given temperature range.'''
    num_T = len(T_list)
    rgb_list = numpy.empty((num_T, 3))
    for i in xrange(0, num_T):
        T_i = T_list[i]
        xyz = blackbody_color(T_i)
        rgb_list[i] = colormodels.rgb_from_xyz(xyz)
    # note that b and g become negative for low T - MatPlotLib skips those on the semilog plot.
    plots.color_vs_param_plot(T_list,
                              rgb_list,
                              title,
                              filename,
                              plotfunc=pylab.semilogy,
                              tight=True,
                              xlabel=r'Temperature (K)',
                              ylabel=r'RGB Color')
Пример #20
0
def get_normalized_spectral_line_colors (
    brightness = 1.0,
    num_purples = 0,
    dwl_angstroms = 10):
    '''Get an array of xyz colors covering the visible spectrum.
    Optionally add a number of 'purples', which are colors interpolated between the color
    of the lowest wavelength (violet) and the highest (red).

    brightness - Desired maximum rgb component of each color.  Default 1.0.  (Maxiumum displayable brightness)
    num_purples - Number of colors to interpolate in the 'purple' range.  Default 0.  (No purples)
    dwl_angstroms - Wavelength separation, in angstroms (0.1 nm).  Default 10 A. (1 nm spacing)
    '''
    # get range of wavelengths, in angstroms, so that we can have finer resolution than 1 nm
    wl_angstrom_range = xrange (10*start_wl_nm, 10*(end_wl_nm + 1), dwl_angstroms)
    # get total point count
    num_spectral = len (wl_angstrom_range)
    num_points   = num_spectral + num_purples
    xyzs = numpy.empty ((num_points, 3))
    # build list of normalized color x,y values proceeding along each wavelength
    i = 0
    for wl_A in wl_angstrom_range:
        wl_nm = wl_A * 0.1
        xyz = xyz_from_wavelength (wl_nm)
        colormodels.xyz_normalize (xyz)
        xyzs [i] = xyz
        i += 1
    # interpolate from end point to start point (filling in the purples)
    first_xyz = xyzs [0]
    last_xyz  = xyzs [num_spectral - 1]
    for ipurple in xrange (0, num_purples):
        t = float (ipurple) / float (num_purples - 1)
        omt = 1.0 - t
        xyz = t * first_xyz + omt * last_xyz
        colormodels.xyz_normalize (xyz)
        xyzs [i] = xyz
        i += 1
    # scale each color to have the max rgb component equal to the desired brightness
    for i in xrange (0, num_points):
        rgb = colormodels.rgb_from_xyz (xyzs [i])
        max_rgb = max (rgb)
        if max_rgb != 0.0:
            scale = brightness / max_rgb
            rgb *= scale
        xyzs [i] = colormodels.xyz_from_rgb (rgb)
    # done
    return xyzs
Пример #21
0
def rayleigh_color_vs_illuminant_temperature_plot(T_list, title, filename):
    '''Make a plot of the Rayleigh scattered color vs. temperature of blackbody illuminant.'''
    num_T = len(T_list)
    rgb_list = numpy.empty((num_T, 3))
    for i in xrange(0, num_T):
        T_i = T_list[i]
        illuminant = illuminants.get_blackbody_illuminant(T_i)
        xyz = rayleigh_illuminated_color(illuminant)
        rgb_list[i] = colormodels.rgb_from_xyz(xyz)
    plots.color_vs_param_plot(T_list,
                              rgb_list,
                              title,
                              filename,
                              tight=True,
                              plotfunc=pylab.plot,
                              xlabel=r'Illuminant Temperature (K)',
                              ylabel=r'RGB Color')
Пример #22
0
def get_normalized_spectral_line_colors(brightness=1.0,
                                        num_purples=0,
                                        dwl_angstroms=10):
    '''Get an array of xyz colors covering the visible spectrum.
    Optionally add a number of 'purples', which are colors interpolated between the color
    of the lowest wavelength (violet) and the highest (red).

    brightness - Desired maximum rgb component of each color.  Default 1.0.  (Maxiumum displayable brightness)
    num_purples - Number of colors to interpolate in the 'purple' range.  Default 0.  (No purples)
    dwl_angstroms - Wavelength separation, in angstroms (0.1 nm).  Default 10 A. (1 nm spacing)
    '''
    # get range of wavelengths, in angstroms, so that we can have finer resolution than 1 nm
    wl_angstrom_range = xrange(10 * start_wl_nm, 10 * (end_wl_nm + 1),
                               dwl_angstroms)
    # get total point count
    num_spectral = len(wl_angstrom_range)
    num_points = num_spectral + num_purples
    xyzs = numpy.empty((num_points, 3))
    # build list of normalized color x,y values proceeding along each wavelength
    i = 0
    for wl_A in wl_angstrom_range:
        wl_nm = wl_A * 0.1
        xyz = xyz_from_wavelength(wl_nm)
        colormodels.xyz_normalize(xyz)
        xyzs[i] = xyz
        i += 1
    # interpolate from end point to start point (filling in the purples)
    first_xyz = xyzs[0]
    last_xyz = xyzs[num_spectral - 1]
    for ipurple in xrange(0, num_purples):
        t = float(ipurple) / float(num_purples - 1)
        omt = 1.0 - t
        xyz = t * first_xyz + omt * last_xyz
        colormodels.xyz_normalize(xyz)
        xyzs[i] = xyz
        i += 1
    # scale each color to have the max rgb component equal to the desired brightness
    for i in xrange(0, num_points):
        rgb = colormodels.rgb_from_xyz(xyzs[i])
        max_rgb = max(rgb)
        if max_rgb != 0.0:
            scale = brightness / max_rgb
            rgb *= scale
        xyzs[i] = colormodels.xyz_from_rgb(rgb)
    # done
    return xyzs
Пример #23
0
def blackbody_color_vs_temperature_plot (T_list, title, filename):
    '''Draw a color vs temperature plot for the given temperature range.'''
    num_T = len (T_list)
    rgb_list = numpy.empty ((num_T, 3))
    for i in xrange (0, num_T):
        T_i = T_list [i]
        xyz = blackbody_color (T_i)
        rgb_list [i] = colormodels.rgb_from_xyz (xyz)
    # note that b and g become negative for low T - MatPlotLib skips those on the semilog plot.
    plots.color_vs_param_plot (
        T_list,
        rgb_list,
        title,
        filename,
        plotfunc = pylab.semilogy,
        tight = True,
        xlabel = r'Temperature (K)',
        ylabel = r'RGB Color')
Пример #24
0
def rayleigh_color_vs_illuminant_temperature_plot (T_list, title, filename):
    '''Make a plot of the Rayleigh scattered color vs. temperature of blackbody illuminant.'''
    num_T = len (T_list)
    rgb_list = numpy.empty ((num_T, 3))
    for i in range (0, num_T):
        T_i = T_list [i]
        illuminant = illuminants.get_blackbody_illuminant (T_i)
        xyz = rayleigh_illuminated_color (illuminant)
        rgb_list [i] = colormodels.rgb_from_xyz (xyz)
    plots.color_vs_param_plot (
        T_list,
        rgb_list,
        title,
        filename,
        tight = True,
        plotfunc = pylab.plot,
        xlabel = r'Illuminant Temperature (K)',
        ylabel = r'RGB Color')
Пример #25
0
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)
Пример #26
0
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)
Пример #27
0
def visible_spectrum_plot():
    '''Plot the visible spectrum, as a plot vs wavelength.'''
    spectrum = ciexyz.empty_spectrum()
    (num_wl, num_cols) = spectrum.shape
    # get rgb colors for each wavelength
    rgb_colors = numpy.empty((num_wl, 3))
    for i in xrange(0, num_wl):
        xyz = ciexyz.xyz_from_wavelength(spectrum[i][0])
        rgb = colormodels.rgb_from_xyz(xyz)
        rgb_colors[i] = rgb
    # scale to make brightest rgb value = 1.0
    rgb_max = numpy.max(rgb_colors)
    scaling = 1.0 / rgb_max
    rgb_colors *= scaling
    # plot colors and rgb values vs wavelength
    color_vs_param_plot(spectrum[:, 0],
                        rgb_colors,
                        'The Visible Spectrum',
                        'VisibleSpectrum',
                        tight=True,
                        xlabel=r'Wavelength (nm)',
                        ylabel=r'RGB Color')
Пример #28
0
def visible_spectrum_plot ():
    '''Plot the visible spectrum, as a plot vs wavelength.'''
    spectrum = ciexyz.empty_spectrum()
    (num_wl, num_cols) = spectrum.shape
    # get rgb colors for each wavelength
    rgb_colors = numpy.empty ((num_wl, 3))
    for i in xrange (0, num_wl):
        xyz = ciexyz.xyz_from_wavelength (spectrum [i][0])
        rgb = colormodels.rgb_from_xyz (xyz)
        rgb_colors [i] = rgb
    # scale to make brightest rgb value = 1.0
    rgb_max = numpy.max (rgb_colors)
    scaling = 1.0 / rgb_max
    rgb_colors *= scaling        
    # plot colors and rgb values vs wavelength
    color_vs_param_plot (
        spectrum [:,0],
        rgb_colors,
        'The Visible Spectrum',
        'VisibleSpectrum',
        tight = True,
        xlabel = r'Wavelength (nm)',
        ylabel = r'RGB Color')
Пример #29
0
def visible_spectrum_table(filename='visible_spectrum.html'):
    '''Write an HTML table with the visible spectrum colors.'''
    spectrum = ciexyz.empty_spectrum()
    (num_wl, num_cols) = spectrum.shape
    # get rgb colors for each wavelength
    rgb_colors_1 = numpy.empty((num_wl, 3))
    rgb_colors_2 = numpy.empty((num_wl, 3))
    for i in range(0, num_wl):
        xyz = ciexyz.xyz_from_wavelength(spectrum[i][0])
        rgb_1 = colormodels.rgb_from_xyz(xyz)
        rgb_2 = colormodels.brightest_rgb_from_xyz(xyz)
        rgb_colors_1[i] = rgb_1
        rgb_colors_2[i] = rgb_2
    # scale 1 to make brightest rgb value = 1.0
    rgb_max = numpy.max(rgb_colors_1)
    scaling = 1.0 / rgb_max
    rgb_colors_1 *= scaling

    # write HTML file

    def write_link(f, url, text):
        '''Write an html link.'''
        link = '<a href="%s">%s</a><br/>\n' % (url, text)
        f.write(link)

    f = open(filename, 'w')
    # html headers
    f.write('<html>\n')
    f.write('<head>\n')
    f.write('<title>Colors of Pure Spectral Lines</title>\n')
    f.write('</head>\n')
    f.write('<body>\n')
    f.write('<p><h1>Colors of Pure Spectral Lines</h1></p>\n')
    f.write('<p>%s</p>\n' %
            'White added to undisplayable pure colors to fit into rgb space.')
    f.write('<hr/>\n')
    # table header
    f.write('<table border cellpadding="5">\n')
    f.write('<tr>\n')
    f.write('<th>Wavelength</th>\n')
    f.write('<th>R</th>\n')
    f.write('<th>G</th>\n')
    f.write('<th>B</th>\n')
    f.write('<th>Hex Code</th>\n')
    f.write('<th width=200>Full Brightness</th>\n')
    f.write('<th width=200>Perceptual Brightness</th>\n')
    f.write('</tr>\n')
    # each row

    for i in range(0, num_wl):
        irgb_1 = colormodels.irgb_from_rgb(rgb_colors_1[i])
        irgb_2 = colormodels.irgb_from_rgb(rgb_colors_2[i])
        red = irgb_2[0]
        green = irgb_2[1]
        blue = irgb_2[2]
        hexstr_1 = colormodels.irgb_string_from_irgb(irgb_1)
        hexstr_2 = colormodels.irgb_string_from_irgb(irgb_2)

        iwl = spectrum[i][0]
        code = '%.1f nm' % iwl

        f.write('<tr>\n')
        f.write('<td>%s</td>\n' % (code))
        f.write('<td>%d</td>\n' % (red))
        f.write('<td>%d</td>\n' % (green))
        f.write('<td>%d</td>\n' % (blue))
        f.write('<td>%s</td>\n' % (hexstr_2))
        swatch = "&nbsp;"
        f.write('<td bgcolor="%s">%s</td>\n' % (hexstr_2, swatch))
        f.write('<td bgcolor="%s">%s</td>\n' % (hexstr_1, swatch))
        f.write('</tr>\n')

    f.write('</table>\n')
    # references
    f.write('<hr/>\n')
    f.write('<p>References</p>\n')
    # one source for data
    write_link(f, 'http://goffgrafix.com/pantone-rgb-100.php',
               'Goffgrafix.com')
    # another source with basically the same data
    write_link(f, 'http://www.sandaleo.com/pantone.asp', 'Sandaleo.com')
    # one with more colors including metallic (also some errors), not quite consistent with the first two
    write_link(
        f, 'http://www.loral.org/Z/Colors/100.html',
        'Loral.org - Conversions based on CorelDRAW v12 Pantone Solid Coated or Pastel Coated tables and sRGB color space.'
    )
    # some colors for various sports teams
    write_link(
        f,
        'http://www.pennjersey.info/forums/questions-answers/7895-pantone-colors-colleges-university-mlb-nfl-teams.html',
        'Pantone colors for some sports teams.')
    # some colors for various national flags
    write_link(
        f, 'http://desktoppub.about.com/od/colorpalettes/l/aa_flagcolors.htm',
        'What color is your flag? Pantone colors for some flags.')
    write_link(f,
               'http://desktoppub.about.com/library/weekly/blcpflagsrwb.htm',
               'Red, White, &amp Blue - Pantone colors for some flags.')
    write_link(
        f, 'http://desktoppub.about.com/library/weekly/blcpflagsyellow.htm',
        'Yellow or Gold - Pantone colors for some flags.')
    write_link(
        f, 'http://desktoppub.about.com/library/weekly/blcpflagsgreen.htm',
        'Green - Pantone colors for some flags.')
    write_link(
        f,
        'http://desktoppub.about.com/library/weekly/blcpatrioticswatches.htm',
        'Color swatches - Pantone colors for some flags.')
    # official Pantone webpages
    write_link(f,
               'http://pantone.com/pages/pantone/Pantone.aspx?pg=19970&ca=25',
               'An official PANTONE page')
    write_link(f,
               'http://pantone.com/pages/products/product.aspx?ca=1&pid=293&',
               'Another official PANTONE page')
    # html ending
    f.write('</body>\n')
    f.write('</html>\n')
    f.close()
Пример #30
0
def shark_fin_plot ():
    '''Draw the 'shark fin' CIE chromaticity diagram of the pure spectral lines (plus purples) in xy space.'''
    # get array of (approximate) colors for the boundary of the fin
    xyz_list = ciexyz.get_normalized_spectral_line_colors (brightness=1.0, num_purples=200, dwl_angstroms=2)
    # get normalized colors
    xy_list = xyz_list.copy()
    (num_colors, num_cols) = xy_list.shape
    for i in xrange (0, num_colors):
        colormodels.xyz_normalize (xy_list [i])
    # get phosphor colors and normalize
    red   = colormodels.PhosphorRed
    green = colormodels.PhosphorGreen
    blue  = colormodels.PhosphorBlue
    white = colormodels.PhosphorWhite
    colormodels.xyz_normalize (red)
    colormodels.xyz_normalize (green)
    colormodels.xyz_normalize (blue)
    colormodels.xyz_normalize (white)

    def get_direc_to_white (xyz):
        '''Get unit vector (xy plane) in direction of the white point.'''
        direc = white - xyz
        mag = math.hypot (direc [0], direc [1])
        if mag != 0.0:
            direc /= mag
        return (direc[0], direc[1])

    # plot
    pylab.clf ()
    # draw color patches for point in xy_list
    s = 0.025     # distance in xy plane towards white point
    for i in xrange (0, len (xy_list)-1):
        x0 = xy_list [i][0]
        y0 = xy_list [i][1]
        x1 = xy_list [i+1][0]
        y1 = xy_list [i+1][1]
        # get unit vectors in direction of white point
        (dir_x0, dir_y0) = get_direc_to_white (xy_list [i])
        (dir_x1, dir_y1) = get_direc_to_white (xy_list [i+1])
        # polygon vertices
        poly_x = [x0, x1, x1 + s*dir_x1, x0 + s*dir_x0]
        poly_y = [y0, y1, y1 + s*dir_y1, y0 + s*dir_y0]
        # draw (using full color, not normalized value)
        color_string = colormodels.irgb_string_from_rgb (
            colormodels.rgb_from_xyz (xyz_list [i]))
        pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string)
    # draw the curve of the xy values of the spectral lines and purples
    pylab.plot (xy_list [:,0], xy_list [:,1], color='#808080', linewidth=3.0)
    # draw monitor gamut and white point
    pylab.plot ([red  [0], green[0]], [red  [1], green[1]], 'o-', color='k')
    pylab.plot ([green[0], blue [0]], [green[1], blue [1]], 'o-', color='k')
    pylab.plot ([blue [0], red  [0]], [blue [1], red  [1]], 'o-', color='k')
    pylab.plot ([white[0], white[0]], [white[1], white[1]], 'o-', color='k')
    # label phosphors
    dx = 0.01
    dy = 0.01
    pylab.text (red   [0] + dx, red   [1], 'Red',   ha='left',   va='center')
    pylab.text (green [0], green [1] + dy, 'Green', ha='center', va='bottom')
    pylab.text (blue  [0] - dx, blue  [1], 'Blue',  ha='right',  va='center')
    pylab.text (white [0], white [1] + dy, 'White', ha='center', va='bottom')
    # titles etc
    pylab.axis ([0.0, 0.85, 0.0, 0.85])
    pylab.xlabel (r'CIE $x$')
    pylab.ylabel (r'CIE $y$')
    pylab.title (r'CIE Chromaticity Diagram')
    filename = 'ChromaticityDiagram'
    print 'Saving plot %s' % (str (filename))
    pylab.savefig (filename)
Пример #31
0
def shark_fin_plot ():
    '''Draw the 'shark fin' CIE chromaticity diagram of the pure spectral lines (plus purples) in xy space.'''
    # get array of (approximate) colors for the boundary of the fin
    xyz_list = ciexyz.get_normalized_spectral_line_colors (brightness=1.0, num_purples=200, dwl_angstroms=2)
    # get normalized colors
    xy_list = xyz_list.copy()
    (num_colors, num_cols) = xy_list.shape
    for i in range (0, num_colors):
        colormodels.xyz_normalize (xy_list [i])
    # get phosphor colors and normalize
    red   = colormodels.PhosphorRed
    green = colormodels.PhosphorGreen
    blue  = colormodels.PhosphorBlue
    white = colormodels.PhosphorWhite
    colormodels.xyz_normalize (red)
    colormodels.xyz_normalize (green)
    colormodels.xyz_normalize (blue)
    colormodels.xyz_normalize (white)

    def get_direc_to_white (xyz):
        '''Get unit vector (xy plane) in direction of the white point.'''
        direc = white - xyz
        mag = math.hypot (direc [0], direc [1])
        if mag != 0.0:
            direc /= mag
        return (direc[0], direc[1])

    # plot
    pylab.clf ()

    # draw best attempt at pure spectral colors on inner edge of shark fin
    s = 0.025     # distance in xy plane towards white point
    for i in range (0, len (xy_list)-1):
        x0 = xy_list [i][0]
        y0 = xy_list [i][1]
        x1 = xy_list [i+1][0]
        y1 = xy_list [i+1][1]
        # get unit vectors in direction of white point
        (dir_x0, dir_y0) = get_direc_to_white (xy_list [i])
        (dir_x1, dir_y1) = get_direc_to_white (xy_list [i+1])
        # polygon vertices
        poly_x = [x0, x1, x1 + s*dir_x1, x0 + s*dir_x0]
        poly_y = [y0, y1, y1 + s*dir_y1, y0 + s*dir_y0]
        # draw (using full color, not normalized value)
        color_string = colormodels.irgb_string_from_rgb (
            colormodels.rgb_from_xyz (xyz_list [i]))
        pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string)

    # fill in the monitor gamut with true colors
    def get_brightest_irgb_string (xyz):
        '''Convert the xyz color to rgb, scale to maximum displayable brightness, and convert to a string.'''
        rgb = colormodels.brightest_rgb_from_xyz (xyz)
        color_string = colormodels.irgb_string_from_rgb (rgb)
        return color_string

    def fill_gamut_slice (v0, v1, v2):
        '''Fill in a slice of the monitor gamut with the correct colors.'''
        #num_s, num_t = 10, 10
        #num_s, num_t = 25, 25
        num_s, num_t = 50, 50
        dv10 = v1 - v0
        dv21 = v2 - v1
        for i_s in range (num_s):
            s_a = float (i_s)   / float (num_s)
            s_b = float (i_s+1) / float (num_s)
            for i_t in range (num_t):
                t_a = float (i_t)   / float (num_t)
                t_b = float (i_t+1) / float (num_t)
                # vertex coords
                v_aa = v0 + t_a * (dv10 + s_a * dv21)
                v_ab = v0 + t_b * (dv10 + s_a * dv21)
                v_ba = v0 + t_a * (dv10 + s_b * dv21)
                v_bb = v0 + t_b * (dv10 + s_b * dv21)
                # poly coords
                poly_x = [v_aa [0], v_ba [0], v_bb [0], v_ab [0]]
                poly_y = [v_aa [1], v_ba [1], v_bb [1], v_ab [1]]
                # average color
                avg = 0.25 * (v_aa + v_ab + v_ba + v_bb)
                # convert to rgb and scale to maximum displayable brightness
                color_string = get_brightest_irgb_string (avg)
                pylab.fill (poly_x, poly_y, color_string, edgecolor=color_string)
    fill_gamut_slice (white, blue,  green)
    fill_gamut_slice (white, green, red)
    fill_gamut_slice (white, red,   blue)

    # draw the curve of the xy values of the spectral lines and purples
    pylab.plot (xy_list [:,0], xy_list [:,1], color='#808080', linewidth=3.0)
    # draw monitor gamut and white point
    pylab.plot ([red  [0], green[0]], [red  [1], green[1]], 'o-', color='k')
    pylab.plot ([green[0], blue [0]], [green[1], blue [1]], 'o-', color='k')
    pylab.plot ([blue [0], red  [0]], [blue [1], red  [1]], 'o-', color='k')
    pylab.plot ([white[0], white[0]], [white[1], white[1]], 'o-', color='k')
    # label phosphors
    dx = 0.01
    dy = 0.01
    pylab.text (red   [0] + dx, red   [1], 'Red',   ha='left',   va='center')
    pylab.text (green [0], green [1] + dy, 'Green', ha='center', va='bottom')
    pylab.text (blue  [0] - dx, blue  [1], 'Blue',  ha='right',  va='center')
    pylab.text (white [0], white [1] + dy, 'White', ha='center', va='bottom')
    # titles etc
    pylab.axis ([0.0, 0.85, 0.0, 0.85])
    pylab.xlabel (r'CIE $x$')
    pylab.ylabel (r'CIE $y$')
    pylab.title (r'CIE Chromaticity Diagram')
    filename = 'ChromaticityDiagram'
    print ('Saving plot %s' % (str (filename)))
    pylab.savefig (filename)
Пример #32
0
def visible_spectrum_table (filename='visible_spectrum.html'):
    '''Write an HTML table with the visible spectrum colors.'''
    spectrum = ciexyz.empty_spectrum()
    (num_wl, num_cols) = spectrum.shape
    # get rgb colors for each wavelength
    rgb_colors_1 = numpy.empty ((num_wl, 3))
    rgb_colors_2 = numpy.empty ((num_wl, 3))
    for i in range (0, num_wl):
        xyz = ciexyz.xyz_from_wavelength (spectrum [i][0])
        rgb_1 = colormodels.rgb_from_xyz (xyz)
        rgb_2 = colormodels.brightest_rgb_from_xyz (xyz)
        rgb_colors_1 [i] = rgb_1
        rgb_colors_2 [i] = rgb_2
    # scale 1 to make brightest rgb value = 1.0
    rgb_max = numpy.max (rgb_colors_1)
    scaling = 1.0 / rgb_max
    rgb_colors_1 *= scaling
    # write HTML file

    def write_link (f, url, text):
        '''Write an html link.'''
        link = '<a href="%s">%s</a><br/>\n' % (url, text)
        f.write (link)

    f = open (filename, 'w')
    # html headers
    f.write ('<html>\n')
    f.write ('<head>\n')
    f.write ('<title>Colors of Pure Spectral Lines</title>\n')
    f.write ('</head>\n')
    f.write ('<body>\n')
    f.write ('<p><h1>Colors of Pure Spectral Lines</h1></p>\n')
    f.write ('<p>%s</p>\n' % 'White added to undisplayable pure colors to fit into rgb space.')
    f.write ('<hr/>\n')
    # table header
    f.write ('<table border cellpadding="5">\n')
    f.write ('<tr>\n')
    f.write ('<th>Wavelength</th>\n')
    f.write ('<th>R</th>\n')
    f.write ('<th>G</th>\n')
    f.write ('<th>B</th>\n')
    f.write ('<th>Hex Code</th>\n')
    f.write ('<th width=200>Full Brightness</th>\n')
    f.write ('<th width=200>Perceptual Brightness</th>\n')
    f.write ('</tr>\n')
    # each row

    for i in range (0, num_wl):
        irgb_1 = colormodels.irgb_from_rgb (rgb_colors_1 [i])
        irgb_2 = colormodels.irgb_from_rgb (rgb_colors_2 [i])
        red   = irgb_2 [0]
        green = irgb_2 [1]
        blue  = irgb_2 [2]
        hexstr_1 = colormodels.irgb_string_from_irgb (irgb_1)
        hexstr_2 = colormodels.irgb_string_from_irgb (irgb_2)

        iwl = spectrum [i][0]
        code = '%.1f nm' % iwl

        f.write ('<tr>\n')
        f.write ('<td>%s</td>\n' % (code))
        f.write ('<td>%d</td>\n' % (red))
        f.write ('<td>%d</td>\n' % (green))
        f.write ('<td>%d</td>\n' % (blue))
        f.write ('<td>%s</td>\n' % (hexstr_2))
        swatch = "&nbsp;"
        f.write ('<td bgcolor="%s">%s</td>\n' % (hexstr_2, swatch))
        f.write ('<td bgcolor="%s">%s</td>\n' % (hexstr_1, swatch))
        f.write ('</tr>\n')

    f.write ('</table>\n')
    # references
    f.write ('<hr/>\n')
    f.write ('<p>References</p>\n')
    # one source for data
    write_link (f, 'http://goffgrafix.com/pantone-rgb-100.php', 'Goffgrafix.com')
    # another source with basically the same data
    write_link (f, 'http://www.sandaleo.com/pantone.asp', 'Sandaleo.com')
    # one with more colors including metallic (also some errors), not quite consistent with the first two
    write_link (f, 'http://www.loral.org/Z/Colors/100.html',
        'Loral.org - Conversions based on CorelDRAW v12 Pantone Solid Coated or Pastel Coated tables and sRGB color space.')
    # some colors for various sports teams
    write_link (f, 'http://www.pennjersey.info/forums/questions-answers/7895-pantone-colors-colleges-university-mlb-nfl-teams.html',
        'Pantone colors for some sports teams.')
    # some colors for various national flags
    write_link (f, 'http://desktoppub.about.com/od/colorpalettes/l/aa_flagcolors.htm', 'What color is your flag? Pantone colors for some flags.')
    write_link (f, 'http://desktoppub.about.com/library/weekly/blcpflagsrwb.htm', 'Red, White, &amp Blue - Pantone colors for some flags.')
    write_link (f, 'http://desktoppub.about.com/library/weekly/blcpflagsyellow.htm', 'Yellow or Gold - Pantone colors for some flags.')
    write_link (f, 'http://desktoppub.about.com/library/weekly/blcpflagsgreen.htm', 'Green - Pantone colors for some flags.')
    write_link (f, 'http://desktoppub.about.com/library/weekly/blcpatrioticswatches.htm', 'Color swatches - Pantone colors for some flags.')
    # official Pantone webpages
    write_link (f, 'http://pantone.com/pages/pantone/Pantone.aspx?pg=19970&ca=25', 'An official PANTONE page')
    write_link (f, 'http://pantone.com/pages/products/product.aspx?ca=1&pid=293&', 'Another official PANTONE page')
    # html ending
    f.write ('</body>\n')
    f.write ('</html>\n')
    f.close()
Пример #33
0
def shark_fin_plot():
    '''Draw the 'shark fin' CIE chromaticity diagram of the pure spectral lines (plus purples) in xy space.'''
    # get array of (approximate) colors for the boundary of the fin
    xyz_list = ciexyz.get_normalized_spectral_line_colors(brightness=1.0,
                                                          num_purples=200,
                                                          dwl_angstroms=2)
    # get normalized colors
    xy_list = xyz_list.copy()
    (num_colors, num_cols) = xy_list.shape
    for i in range(0, num_colors):
        colormodels.xyz_normalize(xy_list[i])
    # get phosphor colors and normalize
    red = colormodels.PhosphorRed
    green = colormodels.PhosphorGreen
    blue = colormodels.PhosphorBlue
    white = colormodels.PhosphorWhite
    colormodels.xyz_normalize(red)
    colormodels.xyz_normalize(green)
    colormodels.xyz_normalize(blue)
    colormodels.xyz_normalize(white)

    def get_direc_to_white(xyz):
        '''Get unit vector (xy plane) in direction of the white point.'''
        direc = white - xyz
        mag = math.hypot(direc[0], direc[1])
        if mag != 0.0:
            direc /= mag
        return (direc[0], direc[1])

    # plot
    pylab.clf()

    # draw best attempt at pure spectral colors on inner edge of shark fin
    s = 0.025  # distance in xy plane towards white point
    for i in range(0, len(xy_list) - 1):
        x0 = xy_list[i][0]
        y0 = xy_list[i][1]
        x1 = xy_list[i + 1][0]
        y1 = xy_list[i + 1][1]
        # get unit vectors in direction of white point
        (dir_x0, dir_y0) = get_direc_to_white(xy_list[i])
        (dir_x1, dir_y1) = get_direc_to_white(xy_list[i + 1])
        # polygon vertices
        poly_x = [x0, x1, x1 + s * dir_x1, x0 + s * dir_x0]
        poly_y = [y0, y1, y1 + s * dir_y1, y0 + s * dir_y0]
        # draw (using full color, not normalized value)
        color_string = colormodels.irgb_string_from_rgb(
            colormodels.rgb_from_xyz(xyz_list[i]))
        pylab.fill(poly_x, poly_y, color_string, edgecolor=color_string)

    # fill in the monitor gamut with true colors
    def get_brightest_irgb_string(xyz):
        '''Convert the xyz color to rgb, scale to maximum displayable brightness, and convert to a string.'''
        rgb = colormodels.brightest_rgb_from_xyz(xyz)
        color_string = colormodels.irgb_string_from_rgb(rgb)
        return color_string

    def fill_gamut_slice(v0, v1, v2):
        '''Fill in a slice of the monitor gamut with the correct colors.'''
        #num_s, num_t = 10, 10
        #num_s, num_t = 25, 25
        num_s, num_t = 50, 50
        dv10 = v1 - v0
        dv21 = v2 - v1
        for i_s in range(num_s):
            s_a = float(i_s) / float(num_s)
            s_b = float(i_s + 1) / float(num_s)
            for i_t in range(num_t):
                t_a = float(i_t) / float(num_t)
                t_b = float(i_t + 1) / float(num_t)
                # vertex coords
                v_aa = v0 + t_a * (dv10 + s_a * dv21)
                v_ab = v0 + t_b * (dv10 + s_a * dv21)
                v_ba = v0 + t_a * (dv10 + s_b * dv21)
                v_bb = v0 + t_b * (dv10 + s_b * dv21)
                # poly coords
                poly_x = [v_aa[0], v_ba[0], v_bb[0], v_ab[0]]
                poly_y = [v_aa[1], v_ba[1], v_bb[1], v_ab[1]]
                # average color
                avg = 0.25 * (v_aa + v_ab + v_ba + v_bb)
                # convert to rgb and scale to maximum displayable brightness
                color_string = get_brightest_irgb_string(avg)
                pylab.fill(poly_x,
                           poly_y,
                           color_string,
                           edgecolor=color_string)

    fill_gamut_slice(white, blue, green)
    fill_gamut_slice(white, green, red)
    fill_gamut_slice(white, red, blue)

    # draw the curve of the xy values of the spectral lines and purples
    pylab.plot(xy_list[:, 0], xy_list[:, 1], color='#808080', linewidth=3.0)
    # draw monitor gamut and white point
    pylab.plot([red[0], green[0]], [red[1], green[1]], 'o-', color='k')
    pylab.plot([green[0], blue[0]], [green[1], blue[1]], 'o-', color='k')
    pylab.plot([blue[0], red[0]], [blue[1], red[1]], 'o-', color='k')
    pylab.plot([white[0], white[0]], [white[1], white[1]], 'o-', color='k')
    # label phosphors
    dx = 0.01
    dy = 0.01
    pylab.text(red[0] + dx, red[1], 'Red', ha='left', va='center')
    pylab.text(green[0], green[1] + dy, 'Green', ha='center', va='bottom')
    pylab.text(blue[0] - dx, blue[1], 'Blue', ha='right', va='center')
    pylab.text(white[0], white[1] + dy, 'White', ha='center', va='bottom')
    # titles etc
    pylab.axis([0.0, 0.85, 0.0, 0.85])
    pylab.xlabel(r'CIE $x$')
    pylab.ylabel(r'CIE $y$')
    pylab.title(r'CIE Chromaticity Diagram')
    filename = 'ChromaticityDiagram'
    print('Saving plot %s' % (str(filename)))
    pylab.savefig(filename)
Пример #34
0
def shark_fin_plot():
    '''Draw the 'shark fin' CIE chromaticity diagram of the pure spectral lines (plus purples) in xy space.'''
    # get array of (approximate) colors for the boundary of the fin
    xyz_list = ciexyz.get_normalized_spectral_line_colors(brightness=1.0,
                                                          num_purples=200,
                                                          dwl_angstroms=2)
    # get normalized colors
    xy_list = xyz_list.copy()
    (num_colors, num_cols) = xy_list.shape
    for i in xrange(0, num_colors):
        colormodels.xyz_normalize(xy_list[i])
    # get phosphor colors and normalize
    red = colormodels.PhosphorRed
    green = colormodels.PhosphorGreen
    blue = colormodels.PhosphorBlue
    white = colormodels.PhosphorWhite
    colormodels.xyz_normalize(red)
    colormodels.xyz_normalize(green)
    colormodels.xyz_normalize(blue)
    colormodels.xyz_normalize(white)

    def get_direc_to_white(xyz):
        '''Get unit vector (xy plane) in direction of the white point.'''
        direc = white - xyz
        mag = math.hypot(direc[0], direc[1])
        if mag != 0.0:
            direc /= mag
        return (direc[0], direc[1])

    # plot
    pylab.clf()
    # draw color patches for point in xy_list
    s = 0.025  # distance in xy plane towards white point
    for i in xrange(0, len(xy_list) - 1):
        x0 = xy_list[i][0]
        y0 = xy_list[i][1]
        x1 = xy_list[i + 1][0]
        y1 = xy_list[i + 1][1]
        # get unit vectors in direction of white point
        (dir_x0, dir_y0) = get_direc_to_white(xy_list[i])
        (dir_x1, dir_y1) = get_direc_to_white(xy_list[i + 1])
        # polygon vertices
        poly_x = [x0, x1, x1 + s * dir_x1, x0 + s * dir_x0]
        poly_y = [y0, y1, y1 + s * dir_y1, y0 + s * dir_y0]
        # draw (using full color, not normalized value)
        color_string = colormodels.irgb_string_from_rgb(
            colormodels.rgb_from_xyz(xyz_list[i]))
        pylab.fill(poly_x, poly_y, color_string, edgecolor=color_string)
    # draw the curve of the xy values of the spectral lines and purples
    pylab.plot(xy_list[:, 0], xy_list[:, 1], color='#808080', linewidth=3.0)
    # draw monitor gamut and white point
    pylab.plot([red[0], green[0]], [red[1], green[1]], 'o-', color='k')
    pylab.plot([green[0], blue[0]], [green[1], blue[1]], 'o-', color='k')
    pylab.plot([blue[0], red[0]], [blue[1], red[1]], 'o-', color='k')
    pylab.plot([white[0], white[0]], [white[1], white[1]], 'o-', color='k')
    # label phosphors
    dx = 0.01
    dy = 0.01
    pylab.text(red[0] + dx, red[1], 'Red', ha='left', va='center')
    pylab.text(green[0], green[1] + dy, 'Green', ha='center', va='bottom')
    pylab.text(blue[0] - dx, blue[1], 'Blue', ha='right', va='center')
    pylab.text(white[0], white[1] + dy, 'White', ha='center', va='bottom')
    # titles etc
    pylab.axis([0.0, 0.85, 0.0, 0.85])
    pylab.xlabel(r'CIE $x$')
    pylab.ylabel(r'CIE $y$')
    pylab.title(r'CIE Chromaticity Diagram')
    filename = 'ChromaticityDiagram'
    print 'Saving plot %s' % (str(filename))
    pylab.savefig(filename)