コード例 #1
0
ファイル: MonitorCenter.py プロジェクト: salnajashi/psychopy
    def doGammaFits(self, levels, lums):
        linMethod = self.currentMon.getLinearizeMethod()

        if linMethod == 4:
            msg = 'Fitting gamma equation (%i) to luminance data'
            logging.info(msg % linMethod)
            currentCal = numpy.ones([4, 6], 'f') * numpy.nan
            for gun in [0, 1, 2, 3]:
                gamCalc = monitors.GammaCalculator(
                    levels, lums[gun, :], eq=linMethod)
                currentCal[gun, 0] = gamCalc.min  # min
                currentCal[gun, 1] = gamCalc.max  # max
                currentCal[gun, 2] = gamCalc.gamma  # gamma
                currentCal[gun, 3] = gamCalc.a  # gamma
                currentCal[gun, 4] = gamCalc.b  # gamma
                currentCal[gun, 5] = gamCalc.k  # gamma
        else:
            currentCal = numpy.ones([4, 3], 'f') * numpy.nan
            msg = 'Fitting gamma equation (%i) to luminance data'
            logging.info(msg % linMethod)
            for gun in [0, 1, 2, 3]:
                gamCalc = monitors.GammaCalculator(
                    levels, lums[gun, :], eq=linMethod)
                currentCal[gun, 0] = lums[gun, 0]  # min
                currentCal[gun, 1] = lums[gun, -1]  # max
                currentCal[gun, 2] = gamCalc.gamma  # gamma

        self.gammaGrid.setData(currentCal)
        self.currentMon.setGammaGrid(currentCal)
        self.unSavedMonitor = True
コード例 #2
0
ファイル: MonitorCenter.py プロジェクト: yvs/psychopy
    def doGammaFits(self, levels, lums):
        linMethod = self.currentMon.getLineariseMethod()
        currentCal = self.currentMon.currentCalib['gammaGrid']
        if linMethod == 3:
            #create new interpolator functions for the monitor
            log.info('Creating linear interpolation for gamma')
            self.currentMon.lineariseLums(0.5, newInterpolators=True)
            for gun in [0, 1, 2, 3]:
                currentCal[gun, 0] = lums[gun, 0]  #min
                currentCal[gun, 1] = lums[gun, -1]  #max
                currentCal[gun,
                           2] = -1.0  #gamma makes no sense for this method
        else:
            log.info('Fitting gamma equation(%i) to luminance data' %
                     linMethod)
            for gun in [0, 1, 2, 3]:
                gamCalc = monitors.GammaCalculator(levels,
                                                   lums[gun, :],
                                                   eq=linMethod)
                currentCal[gun, 0] = lums[gun, 0]  #min
                currentCal[gun, 1] = lums[gun, -1]  #max
                currentCal[gun, 2] = gamCalc.gammaVal  #gamma

        self.gammaGrid.setData(currentCal)
        self.unSavedMonitor = True
コード例 #3
0
    def get_gamma(self):

        if len(self.lums) != 4:
            raise Exception('need 4 lum measurements')

        gamma_grid = []
        for chan in self.lums:
            model = monitors.GammaCalculator(inputs = self.levels,
                lums = chan, eq = 4)
            gamma_grid.append([model.min, model.max, model.gamma, model.a, model.b, model.k])

        return gamma_grid
コード例 #4
0
def calculate_gamma():

    def monitor_function(x, a, b, c, d):
        return a*((x + b)**c) + d
    
    # gamma = 1.95
    # brightness 24%
    # contrast 88%
    
    # test
    stimulus_input = numpy.linspace(0, 1, 5)
    corrected_output = numpy.array([0.8, 25.3, 49.5, 83.8, 112.0])
        
    # data collected at 30% brightness, 88% contrast
    #stimulus_input = numpy.linspace(0, 1, 5)
    #corrected_output = numpy.array([1.1, 1.2, 8.1, 38.8, 111.5])
    
    # data collected at %60 brightness, %50 contrast
    #stimulus_input = numpy.linspace(0, 1, 3)
    #corrected_output = numpy.array([1.4, 27.8, 100.7])
    
    # data collected at 25% brightness, 75% contrast
    #stimulus_input = numpy.linspace(0, 1, 21)
    #corrected_output = numpy.array([0.8, 0.8, 0.8, 0.8, 0.8, 1.1, 1.8, 3.0, 4.5, 6.6, 9.0, 12.3, 16.4, 21.4, 26.8, 34.1, 42.9, 53.5, 70.9, 93.4, 103.6])
    
    pyplot.plot(stimulus_input, corrected_output)
    
    # this is for the old monitor
    #corrected_output = numpy.array([1.0, 3.0, 6.0, 11.0, 18.0, 26.0, 38.0, 51.0, 66.0, 83.0, 104.0])
    
    #minimum = numpy.min(corrected_output)
    #maximum = numpy.max(corrected_output)
    
    #corrected_output[:] = corrected_output[:] - (maximum - 3.0*minimum)/2.0
    
    #corrected_output[:] = corrected_output[:]/numpy.max(corrected_output)
    
    #parameters, covariance = optimize.curve_fit(monitor_function, stimulus_input, corrected_output, p0 = [1.0, 1.0, 2.0, -0.5])
    
    table = monitors.GammaCalculator(inputs = stimulus_input, lums = corrected_output)
    
    return table.gamma
コード例 #5
0
# Filename: monitor_gamma.py

from psychopy import monitors
import matplotlib.pyplot as plt

# photometer measurements
pix_inp = [
    0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 255
]
lum = [
    6.08, 8.2, 11.4, 15.8, 21.59, 28.73, 37.32, 47.4, 59.14, 71.43, 86.3,
    102.4, 120.9, 141.5, 166.7, 188.6, 214.8
]

# create a GammaCalculator
g_cal = monitors.GammaCalculator(pix_inp, lum)
# fit the gamma function
g_cal.fitGammaFun(pix_inp, lum)
# print out the fited gamma value
print(g_cal.gamma)

# generate data points for the fitted gamma function and plot
g_fun = monitors.gammaFun(pix_inp, lum[0], lum[-1], g_cal.gamma)
plt.plot(pix_inp, g_fun, 'k-', lw=2)
plt.xlabel('Pixel bit value')
plt.ylabel('Luminance (cd/m^2)')
plt.show()
コード例 #6
0
lums_m = np.array([lums['k'], lums['r'], lums['g'], lums['b']])


mon = monitors.Monitor('labDELL')
mon.setCurrent('calib')

mon.setDistance(40)
mon.setWidth(52)
mon.setSizePix([1920, 1200])

levels = np.linspace(0, 255, 32).tolist()
levels = [int(x) for x in levels]


mon.setLevelsPre(levels)
mon.setLumsPre(lums_m)

gammaGrid = []
for chan in ['k', 'r', 'g', 'b']:

    gamma = monitors.GammaCalculator(inputs = levels, lums = lums[chan], eq = 4)
    print gamma.a, gamma.b, gamma.k
    row = [gamma.min, gamma.max, gamma.gamma, gamma.a, gamma.b, gamma.k]
    gammaGrid.append(row)

gammaGrid = np.array(gammaGrid)
mon.setGammaGrid(gammaGrid)

print mon.currentCalib
mon.saveMon()
コード例 #7
0
]

#Rlvls = [(val - min(Rlvls))/(max(Rlvls) - min(Rlvls)) for val in Rlvls]
#Glvls = [(val - min(Glvls))/(max(Glvls) - min(Glvls)) for val in Glvls]
#Blvls = [(val - min(Blvls))/(max(Blvls) - min(Blvls)) for val in Blvls]
#Wlvls = [(val - min(Wlvls))/(max(Wlvls) - min(Wlvls)) for val in Wlvls]

plt.title('Gamma')
plt.xlabel('Input')
plt.ylabel('Lums')
plt.plot(vals, Rlvls, color='red')
plt.plot(vals, Glvls, color='green')
plt.plot(vals, Blvls, color='blue')
plt.plot(vals, Wlvls, color='black')

Rcalc = monitors.GammaCalculator(inputs=vals, lums=Rlvls)
Gcalc = monitors.GammaCalculator(inputs=vals, lums=Glvls)
Bcalc = monitors.GammaCalculator(inputs=vals, lums=Blvls)
Wcalc = monitors.GammaCalculator(inputs=vals, lums=Wlvls)

Rgamma = Rcalc.gamma
Ggamma = Gcalc.gamma
Bgamma = Bcalc.gamma
Wgamma = Wcalc.gamma

R_steps = [max(Rlvls) * ((i / 20.0)**(1 / Rgamma)) for i in range(21)]
G_steps = [max(Glvls) * ((i / 20.0)**(1 / Ggamma)) for i in range(21)]
B_steps = [max(Blvls) * ((i / 20.0)**(1 / Bgamma)) for i in range(21)]
W_steps = [max(Wlvls) * ((i / 20.0)**(1 / Wgamma)) for i in range(21)]

#plt.plot(vals, R_steps, color = 'red', ls = 'dashed')
コード例 #8
0
mon.setDistance(40)
mon.setWidth(52)
mon.setSizePix([1920, 1200])
mon.setLevelsPre(levels)
mon.setLumsPre(lums)
mon.setLineariseMethod(4)
mon.setGammaGrid(gammaGrid)
mon.setNotes('matlab')


# Psychopy's method
mon.setCurrent('psychopy')
gammaGrid = []
for chan in lums:
    model = monitors.GammaCalculator(inputs = levels, lums = chan, eq = 4)
    gammaGrid.append([model.min, model.max, model.gamma, model.a, model.b, model.k])

mon.setDistance(40)
mon.setWidth(52)
mon.setSizePix([1920, 1200])
mon.setLevelsPre(levels)
mon.setLumsPre(lums)
mon.setLineariseMethod(4)
mon.setGammaGrid(gammaGrid)
mon.setNotes('psychopy')



# Get the spectra data
datafile = './spectra_data/spectra.csv'