Hi @Zhang, thanks for posting.
The paper is accompanied by a code archive, which includes scripts to acquire the calibration images and perform all the processing steps. However, this focuses on full matrix unmixing to correct everything, and only works with raw images (so is pretty slow).
Probably the most useful code actually lives inside the microscope software here:
That file can be used as a stand-alone module (it doesn’t depend on the microscope server software). The code at the end of the file (in the __name__ == "__main__"
block) is out of date, but the example code at the top is correct. There are functions provided that:
- Auto-expose (adjusting exposure time and gain) so that the image is reasonably bright
- Adjust the white balance gains so the colours are neutral in the middle.
- Set the lens shading table (that will remove the pink tint at the edges)
You should be able to drop that file into your project and import the relevant functions. Then, assuming you have picamerax
(you can install it using pip install picamerax
), you should be able to run:
import recalibrate_utils as ru
picamera = picamerax.PiCamera()
ru.adjust_shutter_and_gain_from_raw(picamera)
ru.adjust_white_balance_from_raw(picamera)
lst = ru.lst_from_camera(picamera)
picamera.lens_shading_table = lst
Run that code while the camera is pointing at a uniform white target - the image should now be uniform and white.
This code also freezes the camera settings - it will not now auto-expose, or change its white balance. That should be what you need.
It is important to mention that the colour response will not be uniform: you will probably see a decrease in saturation at the edges of the image. That’s what the more complicated correction described in the paper is designed to fix, but for many applications it’s not a big issue.
I hope that helps! The only thing I’ve not covered is how to save and restore the camera settings from a file. The OpenFlexure Microscope software does do this, but if you are not using it, there are simpler ways to manage it!