How to apply color profile + gamma correction in Psychotoolbox

I am conducting a visual stimulation experiment where I am using sinusoidal gratings.
Two requirements are necessary:

  1. Linearize the display, so that there is a linear relationship between pixel value and luminance. This should have in account the white and black levels, not just a power law transform.
  2. Ensure the white point temperature is 6500K, i.e., the D65 illuminant, to be sure real gray gratings are being used.

I have a SpyderX device. I have no clue how to use it with Psychotoolbox, and don’t even know if it is possible. Instead, I have been using the software DisplayCal and created a profile with my desired specs. Then I simply loaded it in the operative system, and used MATLAB normally (without Psychotoolbox, as my experiment did not require accurate timing).

I recognize this solution is not ideal. I would prefer using Psychotoolbox. So what I would like to ask is the following:

  • Is there any way to import my color profile from DisplayCal into Psychotoolbox? I have both a “.icm” file and a “.cal” file, both exported from DisplayCal.
  • Alternatively, is there any way I can use a SpyderX (requires a colorimetric correction which I have available!!!) to fulfill the two requirements I listed above, using Psychotoolbox directly?
  • I have also a file I send in attachment, which contains some uncalibrated profile information, exported from DisplayCal. Does that file contain enough information for Psychotoolbox to do what I listed above? If that is the case, how can I do it in the most precise way?

Attachment:
Report on uncalibrated profile:
14:05:27,799 Setting up the instrument
14:05:27,799 Instrument Type: Datacolor SpyderX
14:05:27,799 Serial Number: 61076384
14:05:27,799 Hardware version: 4.91
14:05:27,799 Uncalibrated response:
14:05:27,799 Black level = 0.1306 cd/m^2
14:05:27,799 50% level = 32.44 cd/m^2
14:05:27,799 White level = 166.80 cd/m^2
14:05:27,799 Aprox. gamma = 2.36
14:05:27,799 Contrast ratio = 1278:1
14:05:27,799 White chromaticity coordinates 0.3114, 0.3310
14:05:27,799 White Correlated Color Temperature = 6559K, DE 2K to locus = 6.6
14:05:27,799 White Correlated Daylight Temperature = 6559K, DE 2K to locus = 2.5
14:05:27,799 White Visual Color Temperature = 6313K, DE 2K to locus = 6.4
14:05:27,799 White Visual Daylight Temperature = 6475K, DE 2K to locus = 2.4
14:05:27,799 Effective Video LUT entry depth seems to be 8 bits

I have also a specrophotometer available, which I used for the SpyderX colorimetric correction, but I prefer not having to use it, as I need to request permissions for use. Please don’t tell me that SpyderX sucks and I should buy another device, I already know that. But this is what I have.

As a simple search on this forum for the term “SpyderX” shows, there is a whole 3rd party open-source toolbox called PsyCalibrator for use with Psychtoolbox to use the SpyderX and similar models for calibration:
Software: GitHub - yangzhangpsy/PsyCalibrator: PsyCalibrator
Article: OSF

So that’s one way to do it. Wrt. to applying gamma correction curves, that was already answered in a similar question of yours a couple of months ago. Wrt. white-point etc., PTB’s imaging pipeline has functions to apply 4x4 color conversion matrices, which may help with gamut / white-point adjustments etc. help PsychColorCorrection and demos like RenderDemo.m. No premade demos specific to white-point setting though.

I think as long as you only need a standard SDR framebuffer, that might also work with Psychtoolbox, ie. setting it in the operating system, although I never tried it explicitely. At least the gamma tables set in the operating system via some color profile should peacefully coexist with PTB.

Wrt. your remaining questions I don’t have any ready answers, only that I don’t think we have any code to read .icm files or similar as far as I know, but Matlab’s image processing toolbox has iccread() which might help. Others would have to chime in…

I tried Psycalibrator unsuccessfuly before, but now I tried again and it seemed to work fine. Seems I can use DisplayCal to generate reports on calibrations created and activated by Psycalibrator, which is really good to check on my calibration.
The only thing Psycalibrator is lacking is the colorimetric correction that is well known to be necessary in Spyder devices.

I think PsyCalibrator doesn’t do more than use Psychtoolbox Screen('LoadNormalizedGammaTable', ...), unless you also use it to do the actual measurement procedure via SpyderX?

For the color correction beyond gamma tables, PTB has the mentioned fast gpu accelerated color correction functions from PsychColorCorrection(), e.g., for application of a color transformation matrix which would allow to convert color pixel values from one input colorspace/gamut to another one. You’d need to define your source color gamut, and the measured destination gamut of your actual display device to then compute the proper matrix for Psychtoolbox to apply. We have whole folders with conversion routines help PsychColorimetric - written by actual experts from the Brainard lab, they are as sophisticated as they are poorly documented :wink: .

The only one I wrote, mostly for use with HDR display functionality, is ConvertRGBSourceToRGBTargetColorSpace() which can return a proper color conversion matrix for use by PsychColorCorrection(), and takes a source and destination gamut as input, ie., the 2D chromaticity coordinates of the red, green and blue primaries and of the white-point. No guarantee for correctness of that specific function - I’m not an expert, but so far nobody complained about it being wrong in any way.

I found a workaround. I am only interested in the gamma table, as it will correct each channel individually. As long as the whitepoint is accurate, everything should be fine.
So I used DisplayCal with the color correction to calibrate my display. It outputs a “.cal” file in addition to that “.icm” file, and in this “.cal” file I found the calibration gamma table. So I just copied and pasted it into Screen(‘LoadNormalizedGammaTable’) and everything seems good.

Only drawback is when I want to use PsyCalibrator to measure my screen, as it does not apply the color correction. I had to do it manually. The color correction file from DisplayCal has a XYZ matrix with the color correction. So I copied it into MATLAB, and then applied the color correction with the help of the MATLAB functions makecform and applycform to convert the SpyderX output between xyY and XYZ (the color correction matrix requires the data to be in XYZ coordinates).

Again, a look at RenderDemo.m and the gpu accelerated PsychColorCorrection() functions may be helpful in some way for what you or others with similar needs want to do.

Not in this case. I wanted to apply the color correction to Spyder itself, not to my monitor. Otherwise, measurements would be innacurate and so the monitor calibration.
It is known that most colorimeters are usually innacurate and must be color corrected for each display. Since I had access to a Jeti Specbos spectroradiometer, I computed the correction matrix for my monitor using the program DisplayCal. However, if I wanted to use that matrix in MATLAB, so I had to export the data from the file, import into MATLAB, and do the color correction manually using the method I explained above. This way, I can color correct the Spyder measurements from Psycalibrator, and ultimately measure accurately whatever I want in my monitor.