New to PTB - Gamma correction with gratings stimuli

Hello team,
I apologize for the trivial question but I cannot find a definitive answer otherwise. I am trying to understand how to use gamma correction in the context of having constant luminance when I shift from a black and white gratings stimuli to a grey background and back for a visual experiment. The idea is to ensure a linear gradient and constant total luminance when shifting between the gratings and grey background.
I have coded the paradigm already but I am not sure how to apply gamma correction with the available function options in PTB.

Thanks
Hyma

You could compute the correction by yourself, but I found the easy way is to use PsychImaing pipeline:

PsychImaging('AddTask', 'FinalFormatting', 'DisplayColorCorrection', 'SimpleGamma');
...
PsychColorCorrection('SetEncodingGamma', win, 1/gamma);

For details, you may check one of the demos like BitsPlusCSFDemo.m

Thank you so much! Worked well for me!

Note if you want more precise correction, you need to measure the exact gamma curve with a light meter. You can then fit a curve more precisely to the data, and then test that the result is fully linear with the same light meter. If you have access to a SpectroCal / ColorCal / i1Pro then I have a class to automate this here: