Example #1
0
def genKaiser(neitz=True):
    '''
    '''
    space = colorSpace()

    kaiser = np.genfromtxt('data/kaiser1987.csv', delimiter=",")
    # sort by subject:
    subj1 = np.where(kaiser[:, 3] == 1)
    subj2 = np.where(kaiser[:, 3] == 2)
    s1_xy = kaiser[subj1, :2][0]
    s2_xy = kaiser[subj2, :2][0]
    # solve for z:
    s1_z = 1.0 - (s1_xy[:, 0] + s1_xy[:, 1])
    s2_z = 1.0 - (s2_xy[:, 0] + s2_xy[:, 1])
    # combine:
    s1_xyz = np.zeros((len(s1_xy), 3))
    s1_xyz[:, :2] = s1_xy
    s1_xyz[:, 2] = s1_z
    s2_xyz = np.zeros((len(s2_xy), 3))
    s2_xyz[:, :2] = s2_xy
    s2_xyz[:, 2] = s2_z

    jv = space._genJuddVos()

    if neitz:
        JV_Neitz_transMatrix = space._genJuddVos2Neitz(jv)

        sub1_Neitz = np.dot(JV_Neitz_transMatrix, s1_xyz.T).T 
        sub2_Neitz = np.dot(JV_Neitz_transMatrix, s2_xyz.T).T
    else:
        sub1_Neitz = s1_xyz                     
        sub2_Neitz = s2_xyz 
                    
    return sub1_Neitz, sub2_Neitz, jv   
Example #2
0
def plotConeSpace():
    '''
    '''
    space = colorSpace(fundamental='neitz',
                             LMSpeaks=[559.0, 530.0, 421.0])
    space.plotColorSpace(space.Lnorm, space.Mnorm, space.spectrum)
    plt.show()
Example #3
0
def plotConfusionLines(deficit='tritan', clip=True):
    '''add confusion lines
        '''
    space = colorSpace(fundamental='neitz', LMSpeaks=[559, 530, 417])
    space.plotColorSpace()
    space.find_copunctuals()
    print deficit, ': ', space.copunctuals[deficit]
    
    if deficit.lower() == 'deutan' or deficit.lower() == 'protan':
        lambdas = [420, 460, 470, 480, 490, 500, 515,]
    elif deficit.lower() == 'tritan':
        lambdas = [420, 460, 480, 500, 520, 535, 545, 555,
                   570, 585, 600, 625, 700]
    
    space.cs_ax.plot(space.copunctuals[deficit][0],
                    space.copunctuals[deficit][1], 'ko', markersize=8)
    for lam in lambdas:
        space.cs_ax.plot([space.find_testLightMatch(lam)[0],
                         space.copunctuals[deficit][0]],
                        [space.find_testLightMatch(lam)[1],
                         space.copunctuals[deficit][1]],
                        'k-', linewidth=1)   
    
    space.cs_ax.text(0.7, 1, deficit, fontsize=18)
    if clip is True:                
        space.cs_ax.set_xlim([-0.4, 1.2])
        space.cs_ax.set_ylim([-0.2, 1.2])
    plt.show()                 
Example #4
0
def plot_dichromatic_system(hybrid='ls', clip=True):
    '''
    '''
    space = colorSpace(fundamental='neitz', LMSpeaks=[559, 530, 421])
    space.plotColorSpace()
    
    for x in np.arange(0, 1.1, 0.1):
        if hybrid.lower() == 'ls' or hybrid.lower() == 'sl':
            s = x
            m = 0
            l = -(1.0 - x)
        elif hybrid.lower() == 'lm' or hybrid.lower() == 'ml':
            s = 0
            m = x
            l = -(1.0 - x)
        elif hybrid.lower() == 'ms' or hybrid.lower() == 'sm':
            s = x
            m = -(1.0 - x)
            l = 0
        else:
            raise InputError('hybrid must be ls, lm or ms')

        copunct = space.lms_to_rgb([l, m, s])
        neutral_points = space.find_spect_neutral(copunct)
        for neut in neutral_points:
            space.cs_ax.plot([neut[0], copunct[0]], [neut[1], copunct[1]], 
                             '-o', c=(np.abs(l), np.abs(m), np.abs(s)), 
                             markersize=8, linewidth=2)

    if clip is True:                
        space.cs_ax.set_xlim([-0.4, 1.2])
        space.cs_ax.set_ylim([-0.2, 1.2])
    
    plt.show()
Example #5
0
def plotCIE():
    '''
    '''        
    space = colorSpace(fundamental='neitz',
                             LMSpeaks=[559.0, 530.0, 417.0])          
    sub1_Neitz, sub2_Neitz, jv = space.genKaiser()
    ## plot confusion lines
    clip_area = Wedge((jv[0, 0], jv[0, 1]), r=10, theta1=0, theta2=360)
    CIEcopunctuals = {'deutan': np.array([1.10, -0.1, 0.1]),
                      'protan': np.array([0.753, 0.247, 0]), 
                      'tritan': np.array([0.17, 0, 0.83]),
                      }
    for deficit in CIEcopunctuals:
        space.plotColorSpace(rVal=jv[:, 0], gVal=jv[:, 1],
                                 spec=space.spectrum)     
        
        print deficit, ': ', CIEcopunctuals[deficit]
        
        if deficit.lower() == 'deutan' or deficit.lower() == 'protan':
            lambdas = [420, 460, 470, 480, 490, 500, 515,]
        elif deficit.lower() == 'tritan':
            lambdas = [420, 460, 480, 500, 520, 535, 545, 555,
                       570, 585, 600, 625, 700]
        
        space.cs_ax.plot(CIEcopunctuals[deficit][0],
                        CIEcopunctuals[deficit][1], 'ko', markersize=8)
        for lam in lambdas:
            R, G, B = jv[:, 0], jv[:, 1], jv[:, 2]
            space.cs_ax.plot([space.find_testLightMatch(lam, 
                                R, G, B)[0],
                             CIEcopunctuals[deficit][0]],

                            [space.find_testLightMatch(lam, 
                                R, G, B)[1],
                             CIEcopunctuals[deficit][1]],
                            'k-', linewidth=1) 
            space.cs_ax.plot([jv[-1, 0], jv[0, 0]], 
                    [jv[-1, 1], jv[0, 1]], 'k-', linewidth=3)
                    
            space.cs_ax.set_clip_path(clip_area)
            
        space.cs_ax.set_ylim([-0.12, 0.9])
        space.cs_ax.set_xlim([-0.05, 1.15])          
        space.cs_ax.set_xlabel('x', fontsize=10)
        space.cs_ax.set_ylabel('y', fontsize=10)
        space.cs_ax.text(0.8, 1, deficit, fontsize=18,
                        horizontalalignment='right',
                        verticalalignment='top',
                        transform=space.cs_ax.transAxes)
        fig.set_tight_layout(True)
        plt.show()        
Example #6
0
def plotCMFs():
    '''
    '''
    space = colorSpace()

    fig = plt.figure()
    fig.set_tight_layout(True)
    ax = fig.add_subplot(111)
    pf.AxisFormat()
    pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
    ax.plot(space.spectrum, space.CMFs[0, :], 'r', linewidth=2)
    ax.plot(space.spectrum, space.CMFs[1, :], 'g', linewidth=2)
    ax.plot(space.spectrum, space.CMFs[2, :], 'b', linewidth=2)
    ax.set_xlim([space.spectrum[0], space.spectrum[-1]])
    ax.set_xlabel('wavelength (nm)')
    ax.set_ylabel('sensitivity')
    plt.show()
Example #7
0
def plotcoeff():
    '''
    '''
    space = colorSpace()

    fig = plt.figure()
    fig.set_tight_layout(True)
    ax = fig.add_subplot(111)
    pf.AxisFormat()
    pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
    ax.plot(space.spectrum, space.rVal, 'r', linewidth=2)
    ax.plot(space.spectrum, space.gVal, 'g', linewidth=2)
    ax.plot(space.spectrum, space.bVal, 'b', linewidth=2)
    ax.set_xlim([space.spectrum[0], space.spectrum[-1]])
    ax.set_xlabel('wavelength (nm)')
    ax.set_ylabel('coefficients')
    plt.show()
Example #8
0
def plotLUV():
    '''
    '''
    # make sure stim is cie 1931 and fundamentals neitz
    space = colorSpace(fundamental='neitz',
                             LMSpeaks=[559.0, 530.0, 421.0],
                             stim='cie 1931')
    
    space.genXYZ()
    u = 4 * space.X / (-2 * space.X + 12 * space.Y + 3)
    v = 9 * space.Y / (-2 * space.X + 12 * space.Y + 3)
    
    ind1 = np.where(space.spectrum == 420)[0]
    ind2 = np.where(space.spectrum == 700)[0]
    spectrum = space.spectrum[ind1:ind2+1]
    u = u[ind1:ind2]
    v = v[ind1:ind2]
    
    space.plotColorSpace(u, v, spectrum, ee=False, Luv=True, 
                         skipLam=[530, 550])
    space.cs_ax.axes.get_xaxis().set_visible(False)
    space.cs_ax.axes.get_yaxis().set_visible(False)
    plt.axis('off')
    plt.show()
Example #9
0
def plotRGsystem(PRINT=False, clip=True):
    '''
    '''
    space = colorSpace(fundamental='neitz', LMSpeaks=[559, 530, 419])
    space._plotColorSpace()
    
    for l in range(0, 11):
        m = (10.0 - l) / 10.0
        l = l / 10.0
        
        neut, RG = space.RG2lambda(0, m, l, True)
        
        if PRINT is True:
            #print RG
            #print neut
            print space.find_testlightFromRG(neut[0], neut[1])
        space.cs_ax.plot([neut[0], RG[0]], [neut[1], RG[1]], 
                        '-o', c=(l, m, 0), markersize=8, linewidth=2)
    
    if clip is True:                
        space.cs_ax.set_xlim([-0.4, 1.2])
        space.cs_ax.set_ylim([-0.2, 1.2])
    
    plt.show()
Example #10
0
def plotColorSpace(color):
    '''
    '''
    space = colorSpace(fundamental='neitz', LMSpeaks=[559, 530, 421])
    space.plotColorSpace(color=color)
    plt.show()
Example #11
0
def plotKaiser(neitz=True, showBY=True, clip=True,
               showSub1=False, showSub2=True, stockman=False,
               series=True):
    '''
    '''
    space = colorSpace(fundamental='neitz',
                             LMSpeaks=[559.0, 530.0, 421.0])        
    sub1_Neitz, sub2_Neitz, jv = genKaiser()

    if neitz:
        space._plotColorSpace()

    else:
        space._plotColorSpace(rVal=jv[:, 0], gVal=jv[:, 1],
                             spec=space.spectrum)
        space.cs_ax.plot([jv[-1, 0], jv[0, 0]], 
                        [jv[-1, 1], jv[0, 1]], 'k-', linewidth=3)
        space.cs_ax.set_ylim([0, 0.9])
        space.cs_ax.set_xlim([-0.05, 0.8])
    if showSub1:     
        space.cs_ax.plot(sub1_Neitz[:, 0], sub1_Neitz[:, 1], 'ko', 
                        markersize=8, markeredgewidth=2,
                        markerfacecolor='w',
                        linewidth=2)
    if showSub2:
        space.cs_ax.plot(sub2_Neitz[:, 0], sub2_Neitz[:, 1], 'kx',
                        markersize=8, markeredgewidth=2, linewidth=2)

    if showBY:
        if stockman:
            neut2, RG2 = space.BY2lambda(0, 0, 1., True)
            c2 = (1, 0, 0)
            c3 = (0.5, 0.5, 0)
            neut3, RG3 = space.lambda2RG(522, False, True)
        else:
            neut2, RG2 = space.BY2lambda(1, 0, 0, True)
            c2 = (0, 0, 1)
            c3 = (0, 0.5, 0.5)
            neut3, RG3 = space.lambda2BY(522, True)
        neut1, RG1 = space.BY2lambda(0, 1., 0, True)

        c1 = (0, 1, 0)
        # plot green copunctual line
        space.cs_ax.plot([neut1[0], RG1[0]], [neut1[1], RG1[1]], 
                        '-o', c=c1, markersize=8, linewidth=2)  
        # plot red or blue copunctual depending on neitz or stockman
        space.cs_ax.plot([neut2[0], RG2[0]], [neut2[1], RG2[1]], 
                        '-o', c=c2, markersize=8, linewidth=2)  
        # plot 
        space.cs_ax.plot([neut3[0], RG3[0]], [neut3[1], RG3[1]], 
                        '-o', c=c3, markersize=8, linewidth=2)  

    if stockman and series:

        for lam in [500, 505, 510, 515]:
            neut3, RG3 = space.lambda2RG(lam, False, True)
            space.cs_ax.plot([neut3[0], RG3[0]], [neut3[1], RG3[1]], 
                '-o', c=c3, markersize=8, linewidth=2)  


    if clip is True:                
        space.cs_ax.set_xlim([-0.4, 1.2])
        space.cs_ax.set_ylim([-0.2, 1.2])
    
    space.cs_ax.set_xlabel('x', fontsize=10)
    space.cs_ax.set_ylabel('y', fontsize=10)
    
    plt.show()
Example #12
0
import matplotlib.pylab as plt
import numpy as np

from base import plot as pf
from colorSpace import colorSpace


space = colorSpace()

def trichromaticAnalysis(Lmax=560, Smax=417):
    '''
    '''
    M_lamMax = []
    volume = []
    for i in range(420, 561):
        M_lamMax.append(i)
        space.genLMS('Neitz', [Lmax, i, Smax])
        space.setLights('stiles and burch')
        space.genConvMatrix()
        volume.append(np.linalg.det(space.convMatrix))
    fig = plt.figure()
    fig.set_tight_layout(True)
    ax = fig.add_subplot(111)
    pf.AxisFormat()
    pf.TufteAxis(ax, ['left', 'bottom'], Nticks=[5, 5])
    
    ax.plot(M_lamMax, volume, 'k', linewidth=3)
    
    ind = np.where(np.array(M_lamMax) == 530)[0]
    ax.plot(M_lamMax[ind], volume[ind], 'g+', markersize=15, 
            markeredgewidth=3)