コード例 #1
0
ファイル: MonitorCenter.py プロジェクト: NSalem/psychopy
    def plotGamma(self, event=None):
        figTitle = _translate('%(monName)s %(calibName)s Gamma Functions') % {
                        'monName': self.currentMonName,
                        'calibName': self.currentCalibName}
        plotWindow = PlotFrame(self,1003,figTitle)

        figure = Figure(figsize=(5,5), dpi=80)
        figureCanvas = FigureCanvas(plotWindow, -1, figure)
        plt = figure.add_subplot(111)
        plt.hold('off')

        gammaGrid = self.currentMon.getGammaGrid()
        lumsPre = self.currentMon.getLumsPre()
        levelsPre = self.currentMon.getLevelsPre()
        lumsPost = self.currentMon.getLumsPost()
        if lumsPre!=None:
            colors='krgb'
            xxSmooth = monitors.numpy.arange(0,255.5, 0.5)
            eq = self.currentMon.getLinearizeMethod()
            for gun in range(4): #includes lum
                gamma = gammaGrid[gun,2]
                minLum = gammaGrid[gun,0]
                maxLum = gammaGrid[gun,1]
                if  eq<=2:
                    #plot fitted curve
                    curve = monitors.gammaFun(xxSmooth, minLum, maxLum, gamma,
                        eq=eq, a=None, b=None, k=None)
                    plt.plot(xxSmooth, curve, colors[gun]+'-', linewidth=1.5)
                if self.currentMon.getLinearizeMethod() ==4:
                    a,b,k = gammaGrid[gun,3:]
                    #plot fitted curve
                    curve = monitors.gammaFun(xxSmooth, minLum, maxLum, gamma,
                        eq=eq, a=a, b=b, k=k)
                    plt.plot(xxSmooth, curve, colors[gun]+'-', linewidth=1.5)
                else:
                    pass
                    #polyFit = self.currentMon._gammaInterpolator[gun]
                    #curve = xxSmooth*0.0
                    #for expon, coeff in enumerate(polyFit):
                        #curve += coeff*xxSmooth**expon
                    #plt.plot(xxSmooth, curve, colors[gun]+'-', linewidth=1.5)
                #plot POINTS
                plt.plot(levelsPre, lumsPre[gun,:], colors[gun]+'o', linewidth=1.5)

            lumsPost = self.currentMon.getLumsPost()
            levelsPost = self.currentMon.getLevelsPost()
        if lumsPost!=None:
            for gun in range(4): #includes lum,r,g,b
                lums=lumsPost[gun,:]
                gamma = gammaGrid[gun,2]
                gamma = gammaGrid[gun,2]
                minLum = min(lums)
                maxLum = max(lums)
                #plot CURVE
                plt.plot([levelsPost[0], levelsPost[-1]], [minLum, maxLum], colors[gun]+'--', linewidth=1.5)
                #plot POINTS
                plt.plot(levelsPost,lums,'o', markerfacecolor = 'w', markeredgecolor=colors[gun], linewidth=1.5)
        figureCanvas.draw()#update the canvas
        plotWindow.addCanvas(figureCanvas)
コード例 #2
0
    def plotGamma(self, event=None):
        figTitle = _translate('%(monName)s %(calibName)s Gamma Functions') % {
                        'monName': self.currentMonName,
                        'calibName': self.currentCalibName}
        plotWindow = PlotFrame(self,1003,figTitle)

        figure = Figure(figsize=(5,5), dpi=80)
        figureCanvas = FigureCanvas(plotWindow, -1, figure)
        plt = figure.add_subplot(111)
        plt.hold('off')

        gammaGrid = self.currentMon.getGammaGrid()
        lumsPre = self.currentMon.getLumsPre()
        levelsPre = self.currentMon.getLevelsPre()
        lumsPost = self.currentMon.getLumsPost()
        if lumsPre!=None:
            colors='krgb'
            xxSmooth = monitors.numpy.arange(0,255.5, 0.5)
            eq = self.currentMon.getLinearizeMethod()
            for gun in range(4): #includes lum
                gamma = gammaGrid[gun,2]
                minLum = gammaGrid[gun,0]
                maxLum = gammaGrid[gun,1]
                if  eq<=2:
                    #plot fitted curve
                    curve = monitors.gammaFun(xxSmooth, minLum, maxLum, gamma,
                        eq=eq, a=None, b=None, k=None)
                    plt.plot(xxSmooth, curve, colors[gun]+'-', linewidth=1.5)
                if self.currentMon.getLinearizeMethod() ==4:
                    a,b,k = gammaGrid[gun,3:]
                    #plot fitted curve
                    curve = monitors.gammaFun(xxSmooth, minLum, maxLum, gamma,
                        eq=eq, a=a, b=b, k=k)
                    plt.plot(xxSmooth, curve, colors[gun]+'-', linewidth=1.5)
                else:
                    pass
                    #polyFit = self.currentMon._gammaInterpolator[gun]
                    #curve = xxSmooth*0.0
                    #for expon, coeff in enumerate(polyFit):
                        #curve += coeff*xxSmooth**expon
                    #plt.plot(xxSmooth, curve, colors[gun]+'-', linewidth=1.5)
                #plot POINTS
                plt.plot(levelsPre, lumsPre[gun,:], colors[gun]+'o', linewidth=1.5)

            lumsPost = self.currentMon.getLumsPost()
            levelsPost = self.currentMon.getLevelsPost()
        if lumsPost!=None:
            for gun in range(4): #includes lum,r,g,b
                lums=lumsPost[gun,:]
                gamma = gammaGrid[gun,2]
                gamma = gammaGrid[gun,2]
                minLum = min(lums)
                maxLum = max(lums)
                #plot CURVE
                plt.plot([levelsPost[0], levelsPost[-1]], [minLum, maxLum], colors[gun]+'--', linewidth=1.5)
                #plot POINTS
                plt.plot(levelsPost,lums,'o', markerfacecolor = 'w', markeredgecolor=colors[gun], linewidth=1.5)
        figureCanvas.draw()#update the canvas
        plotWindow.addCanvas(figureCanvas)
コード例 #3
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()