Exercise: camera noise, SNR and PSNR

Goal

By the end of this exercise you should be able to:

  • compute shot noise and the SNR of a pixel, and what averaging frames gains,
  • judge from a camera’s full well, read noise and ADC bits how many bits carry information,
  • say when the additive Gaussian noise model is reasonable,
  • compute a PSNR, and explain why the peak must be stated.

Do the pen-and-paper part first, then the interactive part. Questions marked (math) are for those who want the derivations; the concept questions do not depend on them.

By hand

B1. A camera has a full well of 15 000 electrons, a read noise of 3 electrons, and a 12-bit ADC whose range is matched to the full well. (a) What is the gain (electrons per ADU)? (b) What is the dynamic range, as a ratio, in dB (20\log_{10}) and in bits? (c) Is 12 bits enough? Compare one ADU with the read noise.

B2. One pixel collects on average 400 electrons, another 40 000. Give the shot noise and the SNR of each. You average 4 frames of the dim pixel: what happens to its SNR, and why?

B3. Noise model. For each case, is “additive Gaussian noise with one \sigma_n for the whole image” a reasonable model? (a) A dark-field image: almost all pixels near 5 electrons, read noise 3 electrons. (b) A fluorescence image with a background of 50 electrons and nuclei of 20 000 electrons. (c) A photo saved as a strongly compressed JPEG.

B4. An 8-bit image is corrupted by Gaussian noise with \sigma_n = 5 grey levels. (a) What are the MSE and the PSNR (peak 255)? (b) A denoiser halves the noise SD. What is the new PSNR, and by how many dB did it improve?

B5. A 12-bit camera image (values 0…4095) has noise of 80 ADU; it is saved in a 16-bit file. One paper reports its PSNR with peak 4095, another with peak 65 535. Compute both. Which one is right?

B6. The dim pixel of B2 (400 electrons) also has 3 electrons of read noise. What is its SNR in one frame? How many frames must you average to reach an SNR of at least 50?

B1. (a) g = 15\,000 / 4095 \approx 3.66 electrons per ADU. (b) 15\,000/3 = 5000 : 1, which is 20\log_{10}5000 \approx 74.0 dB, or \log_2 5000 \approx 12.3 bits. (c) Just about. One ADU (3.66 electrons) is a little larger than the read noise (3 electrons), so the quantisation noise 3.66/\sqrt{12} \approx 1.06 electrons is not negligible. Added in variance it raises the dark noise from 3 to \sqrt{3^2 + 1.06^2} \approx 3.18 electrons, about 6 % more. A 13-bit ADC would make one ADU smaller than the read noise.

B2. Shot noise \sqrt{400} = 20 and \sqrt{40\,000} = 200 electrons; SNR 400/20 = 20 and 40\,000/200 = 200. 100 times more light gives 10 times the SNR. Averaging 4 frames of the dim pixel is like collecting 4 times the light (1600 electrons, noise 40): the SNR doubles, to 40. Averaging only helps because the noise differs from frame to frame.

B3. (a) Reasonable: read noise is close to Gaussian and, at a nearly constant 5 electrons, the shot noise (\sqrt5 \approx 2.2) is about the same everywhere; total \sigma_n \approx \sqrt{5 + 9} \approx 3.7 electrons. (b) Not with one \sigma_n: the shot noise is about \sqrt{50} \approx 7 electrons in the background and \sqrt{20\,000} \approx 141 in the nuclei. Gaussian within each region, but with a signal-dependent \sigma_n. (c) No: compression errors depend on the image content and are correlated between neighbouring pixels (blocks), not independent.

B4. (a) MSE = \sigma_n^2 = 25, PSNR = 10\log_{10}(255^2/25) = 34.2 dB. (b) \sigma_n = 2.5: MSE 6.25, PSNR = 40.2 dB, an improvement of 20\log_{10}2 = 6.0 dB.

B5. Peak 4095: 10\log_{10}(4095^2/80^2) = 34.2 dB. Peak 65 535: 58.3 dB, 24.1 dB more for the same image. The peak should be the largest value the data can take, 4095 here; the container (16-bit file) does not matter. Only PSNRs computed with the same peak can be compared.

B6. Noise \sqrt{400 + 3^2} = \sqrt{409} \approx 20.2 electrons, SNR = 400/20.2 \approx 19.8 (25.9 dB), a little below the pure shot-noise value 20. Averaging n frames multiplies the SNR by \sqrt n: 19.8\sqrt n \ge 50 needs n \ge 6.4, so 7 frames.

Math questions

B7. (math) With shot noise, read noise \sigma_r and quantisation (gain g) independent, the total noise is \sigma^2 = S + \sigma_r^2 + g^2/12. For the camera of B1, compute \sigma at S = 100 electrons. Above which signal does shot noise dominate the read noise? Show that the best possible SNR is \sqrt{N_\text{max}} (ignore read and quantisation noise at the full well).

B8. (math) Show that rounding to b bits (step 1 on the scale 0 \dots 2^b - 1, error uniform) gives \text{PSNR} = 20\log_{10}(2^b - 1) + 10\log_{10}12, and evaluate it for b = 4 and b = 8.

B9. (math) K_1, \dots, K_n are independent Poisson counts with mean N. Show that their average has mean N and variance N/n, and express the gain in SNR in dB.

B7. \sigma = \sqrt{100 + 9 + 1.06^2} \approx 10.5 electrons. Shot noise exceeds read noise when \sqrt S > \sigma_r, i.e. S > \sigma_r^2 = 9 electrons. At the full well the noise is \sqrt{N_\text{max}}, so \text{SNR} = N_\text{max}/\sqrt{N_\text{max}} = \sqrt{N_\text{max}}: about 122 for 15 000 electrons.

B8. The error is uniform on [-\tfrac12, \tfrac12], so MSE = 1/12 (quantisation unit). PSNR = 10\log_{10}\big((2^b - 1)^2 \cdot 12\big) = 20\log_{10}(2^b - 1) + 10\log_{10}12. For b = 4: 23.52 + 10.79 = 34.3 dB; for b = 8: 48.13 + 10.79 = 58.9 dB.

B9. \mathbb E[\bar K] = \frac1n\sum\mathbb E[K_i] = N; by independence \operatorname{Var}(\bar K) = \frac1{n^2}\sum\operatorname{Var}(K_i) = \frac{nN}{n^2} = \frac Nn. The SNR is N/\sqrt{N/n} = \sqrt{nN}, \sqrt n times that of one frame: 20\log_{10}\sqrt n = 10\log_{10}n dB (6.0 dB for 4 frames).

Explore

A simulated camera images the micrograph. The plot shows noise against signal, in electrons: shot noise, read noise, quantisation noise, their total, and points measured on simulated flat patches.

E1. Preset sCMOS 16 bit. How large is one ADU in electrons, and the quantisation noise? Which noise source dominates in the dark, and which in the bright? Do the measured points follow the model?

E2. Same, 8-bit ADC. What happens to the gain and the quantisation noise? Why are the measured points for dark patches drawn as red triangles (measured noise 0)? Is zero noise good news here?

E3. Compare low light, 8 bit and low light, 12 bit: how many different ADU values does the image use, and what do you see?

E4. Noisy, 16-bit ADC: how many ADU is the read noise? How many bits does the readout say are needed? What do the other bits store?

E1. One ADU is 30\,000/65\,535 \approx 0.46 electrons, and the quantisation noise 0.13 electrons, far below the read noise of 1.5. In the dark the read noise dominates (the flat blue line), above a few electrons the shot noise \sqrt S takes over. The points sit on the total curve (e.g. 9.89 measured against 10.11 predicted at 100 electrons). The last point, at the full well, falls below: saturated pixels are all equal, so they have no noise left.

E2. One ADU is now about 118 electrons and the quantisation noise 34 electrons, far above the read noise. In a dark flat patch the true noise (a few electrons) is much smaller than one ADU, so every pixel rounds to the same number: the measured spread is 0. That is not good news. The signal differences below one ADU are not noisy, they are gone. The model g/\sqrt{12} also fails at 1000 electrons (measured about 59, predicted 46): it assumes the signal varies over many steps.

E3. 8 bits: only 4 different values in the image (the brightest pixel is 2.6 ADU), so the cell is a few flat patches. 12 bits: 48 values (brightest 41 ADU); the cell is recognisable, and noisy. In dim light the ADC’s step, not the sensor, decides what survives.

E4. The read noise is 10 electrons and one ADU is 10\,000/65\,535 \approx 0.15 electrons, so the read noise is about 66 ADU, around 2^6. The readout says 10 bits would do (\log_2 1000 \approx 10). The lowest ~6 bits of every pixel record read noise very precisely.

Code

Write the algorithms of this unit yourself, in Rust. Setup, and how to run and check your code: coding exercises: getting started. Your code goes in bitdepth/src/cameranoise/exercise.rs.

C1. gain(cam), dynamic_range(cam) and amplitude_db(ratio) for a camera with a full well, a read noise and b ADC bits: g = N_\text{max}/(2^b - 1), N_\text{max}/\sigma_r and 20\log_{10}. The check is B1.

C2. poisson(mean, rng): a random photon count.

if mean < 30:                         # count how many uniform numbers it takes
    p = u;  k = 0                     # u: a new uniform random number in [0, 1) each time
    while p > exp(−mean):  p = p · u;  k = k + 1
    return k
else:                                 # close to a Gaussian with variance = mean
    return round(mean + sqrt(mean) · z), at least 0          # z: Gaussian, mean 0, SD 1

The check draws 40 000 counts and compares their mean and variance with the mean.

C3. expose(cam, electrons, rng): a simulated picture, in ADU.

for every pixel:
    n = poisson(mean electrons of the pixel), at most the full well
    charge = n + read noise · z
    ADU = round(charge / gain), kept between 0 and 2^b − 1

The check is B7: at 100 electrons the camera of B1 has a noise of about 10.5 electrons.

C4. mean_and_sd(values) and predicted_noise(cam, signal) = \sqrt{S + \sigma_r^2 + g^2/12}.

C5. psnr(img, reference, peak): 10\log_{10}(\text{peak}^2/\text{MSE}). The checks are B4 and B5.

Then cargo run -p bitdepth -- cameranoise and open the pictures in out/cameranoise/.

C6. The program images the micrograph with 10, 100 and 10 000 electrons per pixel on average (an ideal camera: shot noise only). Look at cell-*-electrons.png and read the printed noise and SNR. Which rule from the lecture do they follow?

C7. Read the two photon-transfer tables (full well 30 000, read noise 1.5, with a 16-bit and an 8-bit ADC). Where does the measured noise follow the prediction, and where not? Explain the three exceptions: 1 electron with 16 bits, the last row of both tables, and the rows marked – with 8 bits. Compare lowlight-8bit.png with lowlight-12bit.png.

C8. Read the SNR of the averaged frames (400 electrons, read noise 3). Compare with B2 and B6.

The model solution is bitdepth/src/cameranoise/solution.rs in the download.

C6. The RMS noise is 3.2, 10.0 and 100.2 electrons, the SNR 3.2, 10.0 and 99.8 (10.0, 20.0 and 40.0 dB): noise \sqrt N, SNR \sqrt N. 100 times more light gives 10 times the SNR (20 dB). At 10 electrons the cell is barely visible in the speckle; at 10 000 it looks clean. (With the brightest mean count as the peak, the PSNR is 13.6, 23.6 and 43.6 dB: also 20 dB per factor 100.)

C7. With 16 bits the measured noise follows the prediction from 10 to 10 000 electrons (3.48 against 3.50, 10.28 against 10.11, …). At 1 electron it is lower, 1.37 against 1.81: the ADC cannot store negative values, so the negative half of the read noise is clipped to 0. In the last row (30 000 electrons, the full well) the noise is about 101 instead of 173: half of the pixels saturate, and saturated pixels all read the same. With 8 bits one ADU is 118 electrons: at 1, 10 and 100 electrons every pixel of the patch reads the same number, so the measured noise is 0 and there is no SNR to compute. The signal differences are not noisy, they are gone. At 1000 electrons the measurement (58.8) is above the prediction (46.4): g/\sqrt{12} assumes the values spread over many steps. With at most 300 electrons, the 8-bit picture uses only 4 ADU values (brightest 3): a few flat patches. With 12 bits it uses 49 (brightest 48) and the cell is recognisable, as in demo question E3.

C8. One frame: SNR 19.6 (B6: 19.8). 4 frames: 40.2, twice as much (B2: averaging 4 frames doubles the SNR). 7 frames: 51.1, just above 50, as B6 predicts. 16 frames: 79.3, four times one frame: \sqrt n.

Where this leads

The noise model here, Poisson shot noise plus Gaussian read noise, and the SNR and PSNR defined here are used whenever the course measures noise: denoising (denoisers, wavelet shrinkage), deconvolution with Poisson noise (Richardson–Lucy), reconstruction of CT images, compression (JPEG), and choosing exposure times in quantitative microscopy. The next unit is about storing and displaying the 12- and 16-bit numbers such cameras produce.