Gamma Calibration
This page provides instructions on how to perform gamma calibration for visual stimuli in the OpenScope Community Predictive Processing project.
What is Gamma Calibration?
Gamma calibration is essential for visual stimuli experiments, as it ensures a linear relationship between the numeric pixel intensity values in your program and the actual light intensity displayed on the monitor.
Computer monitors and projectors have non-linear relationships between the numeric values sent to them (0-255 for an 8-bit display) and the actual light intensity they produce. For example, doubling the numeric value might not double the light output.
In visual neuroscience experiments, we need precise control over the actual light intensities to ensure accurate stimuli presentation. Gamma calibration compensates for these non-linearities by creating a lookup table that transforms the desired linear intensity values into the appropriate non-linear values that will produce a linear response on the display.
Hardware Requirements
To perform gamma calibration, you need:
- Light Sensor/Photodiode:
- Data Acquisition Device (DAQ):
- Arduino board - HARP board - Any other DAQ that can be read with Bonsai
Software Requirements
Our gamma calibration workflows are built using Bonsai and require:
- Bonsai (version 2.4 or higher)
- BonVision package for Bonsai
- Our custom gamma calibration extensions (included in this repository)
Gamma Calibration Procedure
Step 1: Setup
- Connect your light sensor to an analog channel of your DAQ.
- Position the sensor facing the monitor or projector that you want to calibrate.
- Ensure no other light sources are affecting the sensor readings.
- Clone this repository and navigate to the
code/GammaCalibration
folder.
Step 2: Calibrating the Display
- Open either
GammaCalibration_FitGray.bonsai
(for grayscale calibration) - Configure the
AnalogInput
node to match your DAQ setup. - Adjust the
CreateWindow
node properties to match your display settings. - Position your photodiode on the screen.
- Run the workflow.
- The calibration process will create a gamma lookup table image that will be saved where specified in the
FileName
parameter of theSaveImage
node. - This lookup table can then be used in your BonVision workflows by adding the
GammaCorrection
node and providing the path to the saved lookup table image.
Pre-generated Lookup Tables
For convenience, we provide pre-generated gamma lookup tables for some of our standard rigs:
These BMP files contain a pixel-to-pixel mapping that transforms input pixel values (0-255) to output pixel values that will produce a linear light response on the specific display. Each row in the image represents a different color channel (R, G, B), allowing precise control over the color response of the display.
Step 3: Using the Gamma Lookup Table
After calibration, include the generated lookup table in your stimuli presentations:
- In your stimulus workflow, add the
GammaCorrection
node after your stimulus generation nodes and before rendering. - Set the
LookupTable
property to the path of your saved calibration image.
Testing the Calibration
To verify your gamma calibration and see how to use the calibrated lookup table in practice:
- Open the
GammaCalibration_Test.bonsai
workflow. - Configure the
AnalogInput
node to match your DAQ setup. - Make sure the
GammaCorrection
node is enabled in the workflow. - Set the
GammaLut
property of theGammaCorrection
node to point to your saved calibration image. - Run the workflow to display a series of intensity ramps and test patterns.
- Compare the photodiode measurements with and without gamma correction (you can toggle the
GammaCorrection
node by enabling/disabling it). - A properly calibrated display should show a linear relationship between the requested intensity values and the measured light output when gamma correction is enabled.
Before and After Gamma Correction
Below you can see the difference in measurement before and after applying gamma correction to an oscillating sinusoidal stimulus:
Before gamma correction: The photodiode response shows significant distortion of the sinusoidal pattern. Notice how the peaks are sharper than the troughs, indicating a non-linear relationship between input values and light output.
After gamma correction: The photodiode response closely follows a true sinusoid, with balanced peaks and troughs. This indicates a much more linear relationship between requested intensity values and actual light output.
References
- This implementation is based on BonVision's Gamma Calibration. Note that we modified this code as we encountered a few bugs in the original implementation.
💬 Start a discussion for this page on GitHub (A GitHub account is required to create or participate in discussions)