Exercise: resolution, sampling and measuring the PSF

Goal

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

  • say when two points are resolved (Rayleigh, Sparrow) and why noise changes the answer,
  • compute the pixel size in the sample plane and check it against Nyquist, \lambda/4\mathrm{NA},
  • compare the lateral and axial extent of the PSF, and choose a z-step,
  • describe how a PSF is measured from beads, and correct for the bead size,
  • (math) derive the Sparrow distance of a Gaussian, the axial Nyquist step, and the bead-size correction.

Do the pen-and-paper part first, then the three demos. Questions marked (math) are for those who want the derivations.

Background

Word Meaning
Rayleigh distance 0.61\lambda/\mathrm{NA}; two equal points show a dip of about 26 %
Sparrow distance 0.47\lambda/\mathrm{NA} (Airy), 2\sigma (Gaussian); the dip just vanishes
Pixel in the sample plane camera pixel ÷ total magnification
Lateral Nyquist \Delta x \le \lambda/4\mathrm{NA}
Axial Nyquist \Delta z \le \lambda/\big(2n(1 - \cos\alpha)\big), \sin\alpha = \mathrm{NA}/n; about n\lambda/\mathrm{NA}^2 for small NA
Axial extent of the PSF about 2n\lambda/\mathrm{NA}^2 (small NA); 2.5–6 times the lateral
Bead-size correction \text{FWHM}_\text{meas}^2 \approx \text{FWHM}_\text{PSF}^2 + (0.53D)^2, bead diameter D
Averaging N beads noise ÷ \sqrt N

Unless stated otherwise, λ = 520 nm, immersion oil n = 1.518, and a camera with 6.5 µm pixels.

By hand

B1. For each objective, compute the pixel size in the sample plane, compare it with Nyquist, and give the number of pixels across the Rayleigh distance. (a) 100× / 1.4 oil; (b) 63× / 1.4 oil; (c) 40× / 0.95 dry; (d) 20× / 0.75 dry.

B2. A widefield microscope in a teaching lab has a camera with 2048 × 2048 pixels of 6.5 µm and four objectives: 10× / 0.45, 20× / 0.8, 40× / 1.3 oil and 60× / 1.4 oil. Make a table: pixel in the sample, Nyquist pixel, Nyquist met?, width of the field of view. Which objective would you choose to count cells in a large tissue section, and which to measure the width of microtubules?

B3. Two points are 300 nm apart. (a) Express the distance in units of \lambda/\mathrm{NA} for NA 1.4 and for NA 0.95 (dry). (b) Are they resolved by Rayleigh’s criterion in each case? (The dips are 71 % and 11 %.)

B4. Two molecules at the Rayleigh distance, imaged with 65 nm pixels. About 9 % of each molecule’s photons land in its peak pixel. (a) With 20 photons per molecule, how many photons are in the peak pixel and how large is the Poisson noise there? (b) Suppose the dip (26 % of the peak) must be at least 3 times the noise of a pixel, 0.26N_p \ge 3\sqrt{N_p}, to be seen reliably. How many photons N_p does the peak pixel need, and how many photons per molecule is that?

B5. A widefield z-stack is taken with an NA 1.4 oil objective and steps of 1 µm. (a) What is the axial Nyquist step? (b) What happens to a 100 nm bead halfway between two planes?

B6. Use the rule of thumb 2n\lambda/\mathrm{NA}^2 for the axial extent and 0.61\lambda/\mathrm{NA} for the lateral, for NA 0.8 (air, n = 1) and NA 1.4 (oil). What is the ratio axial/lateral in each case? Which objective gives the more “isotropic” voxels?

B7. The true PSF has an FWHM of 191 nm. (a) What FWHM do you measure with 100 nm beads, and with 200 nm beads? (b) A colleague measured 230 nm with 200 nm beads. Estimate the true FWHM.

B8. One bead’s profile has a noise of 10 % of its peak. How many beads must you average to bring it to 2 %? What else must be done before averaging, and why?

B1. Nyquist 520/(4\mathrm{NA}), Rayleigh 0.61 \cdot 520/\mathrm{NA}:

objective pixel Nyquist ratio pixels across Rayleigh
100× / 1.4 65 nm 93 nm 0.70: fine 227/65 = 3.5
63× / 1.4 103 nm 93 nm 1.11: slightly undersampled 2.2
40× / 0.95 163 nm 137 nm 1.19: slightly undersampled 2.1
20× / 0.75 325 nm 173 nm 1.88: undersampled 1.3

B2.

objective pixel Nyquist met? field of view
10× / 0.45 650 nm 289 nm no (2.3×) 1.33 mm
20× / 0.8 325 nm 163 nm no (2.0×) 666 µm
40× / 1.3 163 nm 100 nm no (1.6×) 333 µm
60× / 1.4 108 nm 93 nm almost (1.2×) 222 µm

Counting cells in a large section: the 10× or 20×; nuclei are many micrometres wide, so undersampling the optics does not matter, and the field is large. Microtubule widths (25 nm, far below the resolution) can only be measured as the PSF width; at least the 60× is needed, ideally with an extra magnifier to reach Nyquist, and even then the measured width is about the PSF’s FWHM, not the microtubule’s.

B3. (a) NA 1.4: \lambda/\mathrm{NA} = 371 nm, so d = 0.81\lambda/\mathrm{NA}. NA 0.95: \lambda/\mathrm{NA} = 547 nm, d = 0.55\lambda/\mathrm{NA}. (b) NA 1.4: yes, well above 0.61 (dip 71 %). NA 0.95: below the Rayleigh distance (334 nm) but above Sparrow (0.47 \cdot 547 = 257 nm): a small dip (11 %), not resolved by Rayleigh’s criterion.

B4. (a) 0.09 \cdot 20 \approx 1.8 photons, noise \pm\sqrt{1.8} = \pm 1.3 photons, about 75 %. The 26 % dip drowns. (b) 0.26\sqrt{N_p} \ge 3 gives N_p \ge (3/0.26)^2 = 133 photons in the peak pixel, i.e. about 133/0.09 \approx 1500 photons per molecule.

B5. (a) \sin\alpha = 1.4/1.518 = 0.922, \cos\alpha = 0.387; \Delta z \le 520/(2 \cdot 1.518 \cdot 0.613) = 279 nm. The 1 µm step is 3.6 times too large. (b) It is 0.5 µm from both planes. The axial FWHM is about 0.5 µm (half-width 0.26 µm), so at 0.5 µm the bead’s peak brightness has dropped to a few per cent (about 4 %): it appears in the stack only as a faint, spread-out blob, or not at all.

B6. NA 0.8: axial 2 \cdot 1 \cdot 520/0.64 = 1625 nm, lateral 397 nm, ratio 4.1. NA 1.4: axial 2 \cdot 1.518 \cdot 520/1.96 = 805 nm, lateral 227 nm, ratio 3.5. The high-NA objective gives the more isotropic voxels: the axial extent falls with \mathrm{NA}^2, the lateral only with NA. (The exact calculation in the demo gives FWHM ratios of 3.5 and 2.7: the rule overestimates the axial extent at high NA.)

B7. (a) \sqrt{191^2 + 53^2} = 198 nm (+4 %); \sqrt{191^2 + 105^2} = 218 nm (+14 %). (b) \sqrt{230^2 - (0.53 \cdot 200)^2} = \sqrt{230^2 - 105^2} \approx 204 nm.

B8. Noise falls as 1/\sqrt N: 10\,\%/\sqrt N = 2\,\% gives N = 25 beads. Before averaging, subtract each bead’s background (otherwise the average sits on a pedestal and looks too wide), and centre each bead with sub-pixel accuracy (otherwise the average is blurred by the random offsets of the beads relative to the pixel grid).

Math questions

B9. (math) Two equal Gaussian spots, h(x) = e^{-x^2/2\sigma^2}, at \pm d/2. Show that the midpoint of h(x - d/2) + h(x + d/2) is a maximum for d < 2\sigma and a minimum for d > 2\sigma. With \sigma = 0.21\lambda/\mathrm{NA}, compare with the Sparrow distance of the Airy pattern, 0.47\lambda/\mathrm{NA}.

B10. (math) The widefield OTF extends along the axis to k_z = \frac{n}{\lambda}(1 - \cos\alpha). (a) Derive the axial Nyquist step. (b) Evaluate it for a water objective, NA 1.2, n = 1.33, at 520 nm. (c) Show that for small NA it is about n\lambda/\mathrm{NA}^2.

B11. (math) (a) Show that the variances of two normalised, centred profiles add under convolution: \mathrm{Var}(f \ast g) = \mathrm{Var}(f) + \mathrm{Var}(g). (b) A uniform sphere of radius R is viewed along z. Show that its brightness profile along x (integrated over y and z) is proportional to R^2 - x^2, with variance R^2/5. (c) Derive the bead-size correction (0.53D)^2 from (a) and (b), treating the profiles as Gaussians for the FWHM.

B9. I(x) = h(x - d/2) + h(x + d/2) is symmetric, so I'(0) = 0, and I''(0) = h''(-d/2) + h''(d/2) = 2h''(d/2). For the Gaussian h''(x) = \big(x^2/\sigma^4 - 1/\sigma^2\big)h(x), negative for |x| < \sigma and positive for |x| > \sigma. So I''(0) < 0 (a maximum, one peak) for d < 2\sigma and > 0 (a minimum, a dip) for d > 2\sigma. With \sigma = 0.21\lambda/\mathrm{NA}: 2\sigma = 0.42\lambda/\mathrm{NA}, a little below the Airy value 0.47: the Gaussian’s tails differ from the Airy rings, so the criterion moves slightly.

B10. (a) The image is band-limited along z to |k_z| \le k_{z,\max}; two samples per period of the finest component: \Delta z \le 1/(2k_{z,\max}) = \lambda/\big(2n(1 - \cos\alpha)\big). (b) \sin\alpha = 1.2/1.33 = 0.902, \cos\alpha = 0.431: \Delta z \le 520/(2 \cdot 1.33 \cdot 0.569) = 344 nm. (c) \cos\alpha = \sqrt{1 - \sin^2\alpha} \approx 1 - \tfrac12\sin^2\alpha = 1 - \mathrm{NA}^2/(2n^2), so 2n(1 - \cos\alpha) \approx \mathrm{NA}^2/n and \Delta z \le n\lambda/\mathrm{NA}^2.

B11. (a) For profiles with \int f = \int g = 1 and zero mean, f \ast g is the density of the sum of two independent random variables with densities f and g; variances of independent variables add. (Directly: \int x^2 (f \ast g)(x)\,dx = \iint (y + t)^2 f(y)g(t)\,dy\,dt = \mathrm{Var}f + 2\cdot 0 \cdot 0 + \mathrm{Var}g.) (b) At position x the sphere’s cross-section is a disc of radius \sqrt{R^2 - x^2}, area \pi(R^2 - x^2). Normalised: p(x) = \tfrac{3}{4R^3}(R^2 - x^2) on [-R, R]. \int x^2 p = \tfrac{3}{4R^3}\big(\tfrac{2R^5}{3} - \tfrac{2R^5}{5}\big) = \tfrac{3}{4R^3}\cdot\tfrac{4R^5}{15} = R^2/5. (c) Measured variance = PSF variance + R^2/5. For Gaussians FWHM = 2.355\,\sigma, so \text{FWHM}_\text{meas}^2 = \text{FWHM}_\text{PSF}^2 + 2.355^2 R^2/5 = \text{FWHM}_\text{PSF}^2 + (1.053R)^2 = \text{FWHM}_\text{PSF}^2 + (0.53D)^2.

Explore: two points on pixels

Two points (or a sinusoidal grating) imaged by an ideal lens and recorded on a pixel grid. The image shows the pixels of a 2 × 1 µm field; the plot shows the profile through both points: blue the optical image (no pixels, no noise), red the recorded pixels. The readout gives the dip in the optical image and in the pixels, and the Nyquist pixel. Tick photon noise for seeded Poisson noise.

P1. Preset Rayleigh. What is the dip in the optical image and in the pixels? Lower the distance until the dip disappears and compare with the Sparrow distance.

P2. Preset Rayleigh, 20 photons. How many photons are in the peak pixel? Is the dip in the pixels meaningful? Raise the photons to 2000: what is the dip in the pixels now? Compare with B4.

P3. Back to Rayleigh (no noise). Increase the pixel size: 93 nm (Nyquist), 150 nm, 200 nm. What happens to the dip in the pixels?

P4. Preset undersampled: aliasing (grating of period 300 nm, 200 nm pixels). What period do the pixels show? Lower the pixel size to 150 nm and then 100 nm. When does the true period come back?

P5. Preset oversampled: noisier pixels (300 nm apart, 500 photons, 20 nm pixels). How many photons are in the peak pixel, and how noisy is it? Change the pixel to 65 nm.

P6. At d = 227 nm (Rayleigh for 520 nm), change the wavelength to 450 nm and 650 nm. What happens to the dip, and why?

P1. Dip 26.8 % in the optical image and 25.6 % in the 40 nm pixels (each pixel averages over 40 nm, which fills the dip a little). The dip disappears at about 176 nm, the Sparrow distance 0.47 \cdot 520/1.4 = 175 nm in the readout.

P2. About 2 photons in the peak pixel (the readout’s “peak pixel ≈ 2.0 photons”); with noise \pm\sqrt2 the pixel profile is mostly noise, and the “dip in the pixels” (100 % in this seed: the middle pixel happened to receive 0 photons) means nothing. With 2000 photons the peak pixel holds about 167 photons (noise ±8 %) and the dip in the pixels is 23 %, close to the noise-free 22.7 % on 65 nm pixels: clearly resolved, as B4 predicts for more than about 1500 photons.

P3. Pixel dip 20.1 % at 93 nm, 4.0 % at 150 nm, and at 200 nm no dip at all: the middle pixel now collects light from both points and is the brightest. The optical image still has its 26.8 % dip; the coarse pixels destroy it.

P4. With 200 nm pixels the pixel values repeat every 3 pixels: an apparent period of 600 nm (the readout: “looks like period 600 nm”). At 150 nm the pixels are exactly half the period and the 300 nm period is recorded (2 pixels per period); at 100 nm it is clearly recorded. The grating passes the optics with 26.6 % contrast; it is the pixels that alias it.

P5. With 20 nm pixels the peak pixel holds about 6.5 photons (noise ±39 %): the profile is ragged. With 65 nm pixels about 50 photons (±14 %), and the dip (67 % noise-free) is clear. The same photons over 10 times fewer pixels.

P6. At 450 nm the dip grows to 51 %; at 650 nm it nearly vanishes (0.6 %). The Rayleigh distance scales with λ: 196 nm for blue, 283 nm for red, so 227 nm is comfortably resolved in blue and just at Sparrow-like merging in red.

Explore: the axial PSF

The xz slice of the PSF of an ideal lens (optical axis vertical), and the same PSF recorded as a stack with planes every Δz. The plot shows the profiles across (blue) and along (red) the axis; red dots mark the planes.

A1. Preset NA 1.4: lateral and axial FWHM, their ratio, and the axial Nyquist step. Compare with B5 and B6.

A2. Preset NA 0.5 (air). How do the FWHMs and the ratio change? What z-step does Nyquist ask for?

A3. Preset z-step too large (1 µm at NA 1.4). How many planes fall within the axial FWHM? Shift the z-step to 300 nm and then 250 nm.

A4. Preset out-of-focus light (log). Describe the shape. Then preset confocal: what changes in the image and in the FWHMs?

A1. Lateral 191 nm, axial 515 nm, ratio 2.7; axial Nyquist 279 nm. The first axial minimum is at about \lambda/n(1 - \cos\alpha) = 558 nm, smaller than the rule of thumb’s 805 nm: at high NA the rule overestimates the axial extent.

A2. At NA 0.5 in air: lateral 535 nm, axial 3.44 µm, ratio 6.4; axial Nyquist 1.94 µm. The axial extent grows like 1/\mathrm{NA}^2, the lateral like 1/\mathrm{NA}: low-NA PSFs are long needles.

A3. With 1 µm steps, at most one plane falls inside the 515 nm FWHM (here the one at the focus; a point between planes would fall between them), and the plot shows the dots jumping from the peak straight to the near-zero tails. The readout says 3.6× too large. At 300 nm the dots trace the curve coarsely (still 1.1× too large); at 250 nm the step is within Nyquist.

A4. An hourglass: two cones of light opening above and below the focus, each plane carrying the same total light, spread wider and wider. In the confocal PSF the cones are gone (the product of two PSFs squares the faint out-of-focus values away), and both FWHMs shrink: 138 nm and 369 nm.

Explore: measuring a PSF from beads

A simulated bead slide: 30 beads (40 nm unless changed), NA 1.4, 520 nm, 65 nm pixels, seeded photon noise and a uniform background. The demo subtracts the background (median of each bead’s patch border), finds each bead’s centre with sub-pixel accuracy, shifts it to the patch centre and averages the first N beads (orange boxes). Panels: one raw bead, the average, and the true PSF (a point as these pixels record it, FWHM 195 nm; the optical Airy FWHM is 191 nm).

E1. Preset one bead, noisy. What FWHM is measured, and how far from the true one? How many photons are in the bead’s peak pixel?

E2. Move beads averaged from 1 to 30 and note the FWHM. How much does it scatter for N \le 5, and for N \ge 20? Compare with the \sqrt N rule.

E3. Preset forgot the background. What is the measured FWHM, and what does the profile show? Tick subtract the background.

E4. Preset beads too large (200 nm beads, 2000 photons, 30 beads). Compare the measured FWHM with your prediction from B7. Then try 300 and 400 nm.

E5. With 30 beads and background subtraction, set the background to 50 photons per pixel. Does the average still converge? What does that say about how well the background must be known?

E1. 204 nm, +4.6 % from the true 195 nm; the peak pixel holds about 54 photons on a background of 10, and the averaged image of one bead is lumpy (the noise is shifted along with it).

E2. For N = 1 to 5 the FWHM jumps between 188 and 206 nm (−3.4 % to +5.8 %); from about 13 beads on it stays between 193 and 195 nm, within 1 % of the true value (30 beads: 194 nm, −0.4 %). Noise of one bead ÷ \sqrt{30} = 0.18: the scatter shrinks roughly five-fold, as observed.

E3. 223 nm (+14.3 %): the profile sits on a pedestal (the background, normalised along with the PSF), so the peak is low and the half-maximum is reached far out. With subtraction: 194 nm again.

E4. 215 nm with 200 nm beads, 10.6 % too wide; B7 predicts 218–222 nm (with a PSF of 191–195 nm). With 300 nm beads 255 nm, with 400 nm beads 316 nm (+62 %): the measurement now mostly reports the bead.

E5. With a background of 50 photons per pixel (more than a bead’s own peak, about 44 photons above the background) the average gives 180 nm, 7.5 % too narrow: the noisy background estimate and the higher noise bias the centring and the subtraction. Without subtraction it would be 473 nm. The background must be known well, and the beads must be bright compared with it.

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 imageformation/src/resolution/exercise.rs. The Airy pattern of an ideal lens is given, as airy(r, na, wavelength).

C1. two_points(h, d, xs): the profile through two equal points d apart, I(x) = h(x - d/2) + h(x + d/2), at the positions xs.

C2. dip(profile): how far the middle of the profile drops below its highest point, 1 - I(\text{middle})/I_\text{max}; 0 when the middle is the highest point. The checks are the numbers of the lecture: 26 % at the Rayleigh distance, none at the Sparrow distance, about 51 % and 0.6 % for two points 227 nm apart in blue and red light, and B9 for Gaussian spots.

C3. fwhm(profile, dx): the full width at half maximum of a sampled peak:

peak = the largest sample, at index p;  half = peak / 2
walk right from p to the first sample below half:
    the crossing lies between it and the sample before, placed by linear interpolation
walk left from p in the same way
FWHM = (right crossing − left crossing) · dx

The checks: a triangle, 2.355\,\sigma for a Gaussian, and 191 nm (0.51\lambda/\mathrm{NA}) for the Airy pattern at NA 1.4 and 520 nm.

C4. centroid(img, radius, background): a bead’s centre with sub-pixel accuracy, the brightness-weighted mean position of the pixels near the brightest one, after subtracting the background (values below 0 count as 0).

C5. average_beads(img, centres, n, step, background): the recipe of the slide “Measuring a PSF from beads”.

sum = all zeros, (2n + 1) × (2n + 1) points
for every bead centre (cx, cy):
    for every point (i, j):
        sum(i, j) = sum(i, j) + I(cx + (i − n)·step, cy + (j − n)·step) − background
                                          # between pixels: bilinear interpolation
PSF = sum / (total of sum)        # normalised to sum 1

The checks: four clean beads at different sub-pixel positions average to the PSF, and with noise the average of 16 beads is about 4 times less noisy than one bead (B8).

Then cargo run -p imageformation -- resolution and open the pictures in out/resolution/. The program prints the dips for two points, then simulates a bead slide: 30 beads of 500 photons each, imaged through an ideal lens (NA 1.4, 520 nm) onto 65 nm pixels, on a background of 10 photons per pixel, with photon noise (bead-slide.png). It finds the beads’ centres, averages 1 to 30 of them, and prints the FWHM of each average. The averaged PSFs are drawn 4 times enlarged, with 0 as black.

C6. Before you run: order 450, 520 and 650 nm by the dip they give for two points 227 nm apart. Then check with the printed numbers.

C7. How does the measured FWHM change from 1 to 30 beads? Compare with the FWHM of the true PSF printed above the table. Compare psf-1-beads.png with psf-30-beads.png.

C8. The last line averages 30 beads without subtracting the background (also when finding the centres). How much too wide is the PSF? Where do you see the reason in psf-30-beads-no-background.png?

The model solution is imageformation/src/resolution/solution.rs in the download.

C6. The shorter the wavelength, the smaller the Airy pattern, and the deeper the dip: 50.7 % at 450 nm, 26.8 % at 520 nm, only 0.6 % at 650 nm. At 650 nm the Rayleigh distance is 0.61 \cdot 650/1.4 = 283 nm, so 227 nm is close to the Sparrow distance (218 nm), where the dip vanishes. (At exactly the Rayleigh distance for 520 nm the dip is 26.5 %; at the Sparrow distance 0.0 %.)

C7. One bead gives 226 nm, 14 % too wide against the true 199 nm (the Airy pattern’s 191 nm, recorded on 65 nm pixels and sampled between them). Two beads give 216 nm, 3 beads 198 nm, then the values settle within a few per cent: 195, 204, 200 and 196 nm for 5, 10, 20 and 30 beads. The brightest pixel of a bead holds only about 49 photons, so one bead’s profile is lumpy (psf-1-beads.png: a blob with dark and bright patches around it); the average of 30 is a smooth, round spot, with the noise reduced by \sqrt{30} \approx 5.5. The centres were found to about 9 nm, a seventh of a pixel.

C8. 224 nm instead of 196 nm, 14 % too wide (compare E3 of the demo, 223 nm). In the picture the area around the spot is grey instead of black: the background, normalised along with the PSF, lifts the whole profile, so half of the peak is reached further out.

Where this leads

We now know what the microscope does to an object: blur by the PSF, sampling, noise. The last unit of the day asks the natural question: if we know the PSF, can we run the model backwards and get the object back? Later, fitting a spot with a PSF model locates it far more precisely than the resolution limit (sub-pixel fitting), and the resolution limit decides what colocalisation can mean (colocalisation).