Skip to content

MATLAB code and instructions for routine camera calibration

Notifications You must be signed in to change notification settings

TheLeeLab/cameraCalibrationCMOS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 

Repository files navigation

DOI

RRID:SCR_025339

cameraCalibrationCMOS

Why calibrate your camera? If you want to compare the intensities of images recorded on different instruments or images recorded with different acquisition settings (e.g. different em-gain), you need to convert the pixel values from analog-to-digital (ADU) units to photoelectrons:

intensity (photoelectrons) = [intensity (ADU counts) - offset (ADU counts)]/gain (ADU counts/photoelectron)

intensity (photons) = intensity (photoelectrons)/QE (photoelectrons/photon)

Any analysis that takes photon statistics into account (e.g. many localisation algorithms for SMLM) will ask you for the camera gain and offset to do this conversion internally. The offset and gain can be measured by doing a camera calibration which involves recording uniform intensity images at different brightnesses. You can also look these values up in the birth certificate of your camera, but the gain of EMCCD cameras can drift over time so it's recommended to regularly calibrate your camera. Unlike EMCCD cameras, CMOS cameras have a pixel-dependent offset, variance and gain. Some localisation algorithms (Huang et al., Lin et al.) use those pixel-dependent offset, variance and gain maps and you can measure them by calibrating your camera.

Instructions for quick routine camera calibration:

Calibrating your camera is very easy when your microscope has a brightfield lamp with an intensity that you can vary. Follow the following steps:

  • After recording your data, take off your sample and replace it with a piece of paper or a lens tissue. Don't change the settings of your camera, you want to use the same gain, roi etc that you used for recording your sample. The purpose of placing a piece of paper or lens tissue as a sample is that it acts like a diffuser to get an approximately uniform intensity in the image.
  • Acquire 100 dark frames (all lights and lasers off) and call the stack 'dark.tif'
  • Turn the brightfield lamp on and acquire 100 frames at a low intensity. Call the stack 'int1.tif'.
  • Repeat the previous step multiple times, each time using a higher intensity of the brightfield lamp. Call the stacks 'int2.tif', 'int3.tif' and 'int4.tif' etc.

Instructions for analysing the data:

  • Double-check that you used the correct filenaming convention as explained in the instructions above. All the data for the camera calibration should be in one folder.
  • Open the script calibrateCamera.m in MATLAB and fill in the parameters: the path to the folder containing the stacks and part of the name of the dark and bright images.
  • Run the script. It will create a new folder inside the folder that contains the calibration data and save
    • a file 'results.mat' which you can load in matlab and contains a structure with 6 elements: the average offset, variance and gain, and the pixel-dependent offset, variance and gain maps
    • a tif file for the pixel-dependent offset, variance and gain maps
    • 3 matlab figures showing the pixel-dependent maps and corresponding histograms of their pixel values
    • a matlab figure showing the data and linear fit used to estimate the gain

The estimation of the offset, variance and gain was implemented as described in the supplementary material of Huang et al.

Troubleshooting and tips:

Tip 1: The more frames you measure, the better. If you just want an average offset, variance and gain, 100 frames is enough. If you have an sCMOS camera and want to get pixel-dependent gain, offset and variance maps, you should take more than 100 frames for each stack. Aim for something on the order of 10k-60k frames per intensity level (these numbers come from the methods section of Huang et al. and Diekmann et al.). I know that's a lot of data. When recording these long stacks (especially when you are calibrating the full chip) MicroManager or whatever software you are using for image acquisition might start chopping up the stacks into 'dark_0.tif', 'dark_1.tif', 'dark_2.tif' etc. The code will automatically group these stacks. The code also never reads a whole stack into memory, only a single frame at a time.

Tip 2: The more different intensities you measure, the better your estimate of the gain will be. In principle 2 are enough, but to have more confidence in the results, use at least 4 levels. Ideally, 1) the lowest intensity level has pixel values close to the dark image, 2) the highest intensity level has pixel values close to the maximum pixel values you see in your data and 3) the other intensity levels are more or less equally spaced between the lowest and highest intensity levels.

Tip 3: If you don't have a brightfield lamp on your microscope with adjustable brightness, you can use another lamp and layer lens tissues to decrease the intensity in steps. You can also use your laser as a light source if you have a fluorescent slide (e.g. from Chroma) instead of a piece of paper. The latter works best when your illumination profile is flat over your roi.

Tip 4: The brightness of your lamp should be constant during each stack. If your lamp is unstable or has a fluctuating brightness, this will mess up the calibration. Diekmann et al. used a TN-LED laptop screen as a light source.

About

MATLAB code and instructions for routine camera calibration

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages