This project provides Python classes to interface with a SpyderX Pro colorimeter for measuring and calibrating monitor gamma. It combines PyUSB for USB communication and PsychoPy for precise visual presentation of gray levels.
The project includes the following files:
-
cal_lib.py:- Contains the
SpyderXclass for communicating with the SpyderX device. - Includes
GammaFitterto fit gamma curves using luminance measurements.
- Contains the
-
cal_psy.py:- Contains the
GrayLevelsclass for measuring luminance and fitting gamma curves using PsychoPy. - Displays gray levels and measures luminance to calibrate monitor gamma.
- Contains the
-
Example Usage:
- In
Demo.pyfile you can find a demonstration on how to use the code
- In
Ensure the following libraries are installed:
- PyUSB for USB communication:
pip install pyusb
- PsychoPy for visual stimulus presentation:
pip install psychopy
- NumPy and SciPy for numerical computations:
pip install numpy scipy
- Matplotlib for plotting gamma curves:
pip install matplotlib
IMPORTANT: This step requires visual studio with several components installed.
- Clone and bootstrap vcpkg:
git clone https://github.com/microsoft/vcpkg.git cd vcpkg bootstrap-vcpkg.bat - Install libusb:
vcpkg install libusb
- Find libusb-1.0.dll in:
vcpkg\installed\x64-windows\bin\libusb-1.0.dll
Here is a demo script that performs monitor calibration:
from cal_lib import SpyderX
from cal_psy import GrayLevels
import numpy as np
# Path to the libusb-1.0.dll file
libusb_path = r"C:\path\to\libusb-1.0.dll"
# Initialize the SpyderX device
spyder = SpyderX(libusb_path)
# Initialize the GrayLevels class
gl = GrayLevels(spyder, fullscr=True)
# Perform black-level calibration
gl.calibrate()
# Measure gray levels and fit gamma
gammas = []
gfit = gl.measure(num_levels=12)
gammas.append(gfit.gamma)
# Repeat measurements for better accuracy
for i in range(3):
gfit = gl.measure(num_levels=12, wait_user=False)
gammas.append(gfit.gamma)
print(f"Average Gamma Value: {np.mean(gammas):.3f}")
# Clean up
gl.close()-
Install the libusb driver as described above.
-
Connect the SpyderX device to your computer.
-
Change the default driver to libusbK using Zadig
-
Run the script:
- Perform black calibration by covering the SpyderX sensor.
- Place the SpyderX on the monitor as instructed.
- Measure luminance values for a range of gray levels.
-
Analyze the Gamma Curve:
- The script will fit a gamma curve and compute the gamma value.
- The curve will be displayed using matplotlib.
-
Average Multiple Measurements:
- For better results, repeat the measurement process.
-
Run in Full-Screen Mode:
- Use
fullscr=Truewhen initializing the GrayLevels class to ensure precise display of gray levels.
- Use
-
Stabilize the Display:
- Allow a brief pause (e.g.,
pause=1second) after each gray level display to ensure the monitor luminance stabilizes.
- Allow a brief pause (e.g.,
-
Cover the SpyderX for Black Calibration:
- Ensure the SpyderX sensor is covered during black calibration for accurate measurements.
-
Avoid Ambient Light:
- Perform calibration in a dark room to minimize interference from ambient light.
-
Repeat Measurements:
- Repeating measurements multiple times and averaging the gamma value improves accuracy.
- If the system installs DataColor Driver remove them completely using RAPR
- Then install libusbK using Zadig
- The SpyderX class was adapted from the work (for macOS) of patrickmineault.