Gamma correcting a monitor

Monitors typically don’t have linear outputs; when you request luminance level of 127, it is not exactly half the luminance of value 254. For experiments that require the luminance values to be linear, a correction needs to be put in place for this nonlinearity which typically involves fitting a power law or gamma (\(\gamma\)) function to the monitor output values. This process is often referred to as gamma correction.

PsychoPy® can help you perform gamma correction on your monitor, especially if you have one of the supported photometers/spectroradiometers.

There are various different equations with which to perform gamma correction. The simple equation (1) is assumed by most hardware manufacturers and gives a reasonable first approximation to a linear correction. The full gamma correction equation (3) is more general, and likely more accurate especially where the lowest luminance value of the monitor is bright, but also requires more information. It can only be used in labs that do have access to a photometer or similar device.

Simple gamma correction

The simple form of correction (as used by most hardware and software) is this:

(1)\[L(V) = a + kV^\gamma\]

where \(L\) is the final luminance value, \(V\) is the requested intensity (ranging 0 to 1), \(a\), \(k\) and \(\gamma\) are constants for the monitor.

This equation assumes that the luminance where the monitor is set to ‘black’ (V=0) comes entirely from the surround and is therefore not subject to the same nonlinearity as the monitor. If the monitor itself contributes significantly to \(a\) then the function may not fit very well and the correction will be poor.

The advantage of this function is that the calibrating system (PsychoPy® in this case) does not need to know anything more about the monitor than the gamma value itself (for each gun). For the full gamma equation (3), the system needs to know about several additional variables. The look-up table (LUT) values required to give a (roughly) linear luminance output can be generated by:

(2)\[LUT(V) = V^{1/\gamma}\]

where V is the entry in the LUT, between 0 (black) and 1 (white).

Full gamma correction

For very accurate gamma correction PsychoPy® uses a more general form of the equation above, which can separate the contribution of the monitor and the background to the lowest luminance level:

(3)\[L(V) = a + (b+kV)^\gamma\]

This equation makes no assumption about the origin of the base luminance value, but requires that the system knows the values of \(b\) and \(k\) as well as \(\gamma\).

The inverse values, required to build the LUT are found by:

(4)\[LUT(V) = \frac{( (1-V)b^\gamma + V(b+k)^\gamma )^{1/\gamma}-b}{k}\]

This is derived below, for the interested reader. ;-)

And the associated luminance values for each point in the LUT are given by:

\[L(V) = a + (1-V)b^\gamma + V(b+k)^\gamma\]

Deriving the inverse full equation

The difficulty with the full gamma equation (3) is that the presence of the \(b\) value complicates the issue of calculating the inverse values for the LUT. The simple inverse of (3) as a function of output luminance values is:

(5)\[LUT(L) = \frac{((L-a)^{1/\gamma} - b )}{k}\]

To use this equation we need to first calculate the linear set of luminance values, \(L\), that we are able to produce the current monitor and lighting conditions and then deduce the LUT value needed to generate that luminance value.

We need to insert into the LUT the values between 0 and 1 (to use the maximum range) that map onto the linear range from the minimum, m, to the maximum M possible luminance. From the parameters in (3) it is clear that:

(6)\[ \begin{align}\begin{aligned}m = a+b^\gamma\\M = a+(b+k)^\gamma\end{aligned}\end{align} \]

Thus, the luminance value, L at any given point in the LUT, V, is given by

(7)\[\begin{split}L(V) &= m + (M-m)V \\ &= a+b^\gamma + (a+(b+k)^\gamma - a - b^\gamma)V \\ &= a + b^\gamma + ((b+k)^\gamma - b^\gamma)V \\ &= a + (1-V)b^\gamma + V(b+k)^\gamma\end{split}\]

where \(V\) is the position in the LUT as a fraction.

Now, to generate the LUT as needed we simply take the inverse of (3):

(8)\[LUT(L) = \frac{(L-a)^{1/\gamma}-b}{k}\]

and substitute our \(L(V)\) values from (7):

(9)\[\begin{split}LUT(V) &= \frac{( a + (1-V)b^\gamma + V(b+k)^\gamma -a)^{1/\gamma}-b}{k}\\ &= \frac{( (1-V)b^\gamma + V(b+k)^\gamma )^{1/\gamma}-b}{k}\end{split}\]

References


Back to top