Example #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()'
Example #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()')
Example #3
0
def perceptually_uniform_spectral_colors():
    '''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)
    (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 xrange(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 xrange(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_list = []
    index = 0
    count = 0
    need = 0.0
    while True:
        while need > 1.0e-10:
            need -= dss[index]
            index += 1
        E_list.append(uniforms[index])
        need += ds_avg
        count += 1
        if count >= num_samples:
            break
    # patch plot
    xyz_list = []
    for uniform in E_list:
        xyz = xyz_from_uniform(uniform)
        xyz_list.append(xyz)
    plots.xyz_patch_plot(xyz_list,
                         None,
                         'Perceptually (almost) Equally Spaced Pure Colors',
                         'PerceptuallyEqualColors',
                         num_across=20)
Example #4
0
def spectral_colors_plus_purples_patch_plot():
    '''Colors of the pure spectral lines plus purples.'''
    xyzs = ciexyz.get_normalized_spectral_line_colors(brightness=1.0,
                                                      num_purples=200,
                                                      dwl_angstroms=10)
    plots.xyz_patch_plot(xyzs,
                         None,
                         'Colors of pure spectral lines plus purples',
                         'SpectralPlusPurples',
                         num_across=20)
Example #5
0
def perceptually_uniform_spectral_colors ():
    '''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)
    (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 xrange (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 xrange (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_list = []
    index = 0
    count = 0
    need = 0.0
    while True:
        while need > 1.0e-10:
            need -= dss [index]
            index += 1
        E_list.append (uniforms [index])
        need += ds_avg
        count += 1
        if count >= num_samples:
            break
    # patch plot
    xyz_list = []
    for uniform in E_list:
        xyz = xyz_from_uniform (uniform)
        xyz_list.append (xyz)
    plots.xyz_patch_plot (
        xyz_list, None, 'Perceptually (almost) Equally Spaced Pure Colors', 'PerceptuallyEqualColors', num_across=20)
    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)
Example #7
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)
Example #8
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)
Example #9
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)
Example #10
0
def spectral_colors_plus_purples_patch_plot ():
    '''Colors of the pure spectral lines plus purples.'''
    xyzs = ciexyz.get_normalized_spectral_line_colors (brightness=1.0, num_purples=200, dwl_angstroms=10)
    plots.xyz_patch_plot (
        xyzs, None, 'Colors of pure spectral lines plus purples', 'SpectralPlusPurples', num_across=20)
Example #11
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)
Example #12
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)
Example #13
0
import ciexyz
import colormodels

# This script prints CIE xy coordinates for the monochromatic "rainbow" colors as a C++ array.

# Wavelenghts: begin, end and increment.
begin_wl = 360  # hardcoded in get_normalized_spectral_line_colors
end_wl = 830
delta_wl = 20

xyz_list = ciexyz.get_normalized_spectral_line_colors(brightness=1.0,
                                                      dwl_angstroms=delta_wl *
                                                      10)
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])

entries = len(xy_list)

# print array
print "int begin_wl = {begin_wl};".format(begin_wl=begin_wl)
print "int end_wl = {end_wl};".format(end_wl=end_wl)
print "int delta_wl = {delta_wl};".format(delta_wl=delta_wl)
print "int entries = {entries};".format(entries=entries)
print "qreal monochromatic_xy[{entries}][2] = {{".format(entries=entries)
for xyz in xy_list:
    x = xyz[0]
    y = xyz[1]
    print("    {{ {x:.10f}, {y:.10f} }},").format(x=x, y=y)
print "};"