Exercise: image formation and the PSF
Before this unit: Day 1: Images, filters and frequencies.
See also: Day 3: Bit depth and noise; Day 2: Edges, blobs and ridges.
Goal
By the end of this exercise you should be able to:
- describe the imaging chain as a forward model and say where blur, sampling and noise enter,
- blur a small object by hand with a PSF, and read the contrast of a grating from an OTF curve,
- compute the Rayleigh and Abbe distances and the cut-off 2\mathrm{NA}/\lambda for an objective,
- recognise defocus and motion blur from their PSF and OTF, and explain reversed contrast and vanishing stripes,
- (math) derive the cut-off from the pupil, and the OTF of motion blur.
Do the pen-and-paper part first, then the demo. Questions marked (math) are for those who want the derivations; the concept questions do not depend on them.
Background
| Word | Meaning |
|---|---|
| Forward model | image = sample(object ∗ PSF) + noise: what the instrument does to the truth |
| PSF h | the image of a point; normalised to sum 1 |
| OTF H | Fourier transform of the PSF; contrast kept at each frequency; H(0) = 1 |
| MTF | \lvert H\rvert, the magnitude of the OTF |
| NA | numerical aperture, n\sin\alpha (half-angle \alpha of the light cone, refractive index n) |
| Cut-off | 2\mathrm{NA}/\lambda: the OTF is zero beyond it |
| Rayleigh distance | 0.61\lambda/\mathrm{NA}, the radius of the first dark ring of the Airy pattern |
| Abbe distance | \lambda/2\mathrm{NA}, the finest grating period that passes |
| Gaussian approximation | \sigma = 0.21\lambda/\mathrm{NA} |
By hand
B1. A row of pixels (0, 0, 3, 0, 0, 0, 1, 1, 0) is blurred with the PSF (1, 2, 1)/4 (outside the row, take 0). (a) Compute the blurred row. (b) Check that the total brightness is unchanged. Why must it be? (c) Can you still see from the blurred row that the object had a single bright point on the left and two neighbouring points on the right?
B2. Compute the Rayleigh distance, the Abbe distance and the cut-off frequency (in cycles/µm) for (a) a water objective, NA 1.2, at λ = 488 nm; (b) a dry objective, NA 0.75, at λ = 600 nm.
B3. Two objectives, NA 1.4 and NA 1.2, image blue light (450 nm). Which of them resolves two points 200 nm apart by the Rayleigh criterion?
B4. Use the OTF curve of the lecture (NA 1.4, 520 nm; right panel of the Airy figure). (a) Read off the contrast kept for gratings of period 1 µm, 400 nm and 250 nm. (b) What happens to a grating of period 180 nm?
B5. A 100 nm fluorescent bead is imaged with an NA 0.3 and an NA 1.4 objective (same wavelength). The two images look alike, but one is much larger. Why do they have the same shape? How much larger is the NA 0.3 image?
B6. During an exposure the stage drifted by 0.5 µm along x. (a) What does the PSF look like (ignoring diffraction)? (b) Which grating periods along x vanish completely? (c) What happens to a grating with stripes running along x (its frequency is along y)?
B7. In a defocused image of a striped test chart, the stripes in one region look inverted. A colleague concludes the camera’s colour table is wrong. Explain what actually happened.
B1. (a) Each pixel becomes \tfrac14 left neighbour + \tfrac12 itself + \tfrac14 right neighbour: (0,\ 0.75,\ 1.5,\ 0.75,\ 0,\ 0.25,\ 0.75,\ 0.75,\ 0.25). (b) Object total 3 + 1 + 1 = 5; blurred total 0.75 + 1.5 + 0.75 + 0.25 + 0.75 + 0.75 + 0.25 = 5. The PSF sums to 1: every point’s light is spread over its neighbours, none is lost (no light falls off the ends here). (c) Yes, here: the left blob is symmetric with peak 1.5, the right one is flat-topped (0.75, 0.75) and wider. With a wider PSF the two right points would merge into a single blob: that is the resolution question of the next unit.
B2. (a) Rayleigh 0.61 \cdot 488/1.2 = 248 nm; Abbe 488/2.4 = 203 nm; cut-off 2.4/0.488 = 4.92 cycles/µm. (b) Rayleigh 0.61 \cdot 600/0.75 = 488 nm; Abbe 600/1.5 = 400 nm; cut-off 1.5/0.6 = 2.5 cycles/µm.
B3. NA 1.4: 0.61 \cdot 450/1.4 = 196 nm < 200 nm: resolved. NA 1.2: 0.61 \cdot 450/1.2 = 229 nm > 200 nm: not resolved by Rayleigh’s criterion.
B4. (a) The cut-off is 5.4 cycles/µm. Period 1 µm = 1 cycle/µm: about 0.77. Period 400 nm = 2.5 cycles/µm: about 0.43. Period 250 nm = 4 cycles/µm: about 0.15. (From the formula: 0.765, 0.431, 0.150.) (b) Period 180 nm = 5.6 cycles/µm, beyond the cut-off: contrast 0. The grating is not in the image at all.
B5. A 100 nm bead is much smaller than both PSFs, so in both cases the image of the bead is essentially the PSF itself, an Airy pattern. The Airy pattern of a perfect lens always has the same shape; only its scale \lambda/\mathrm{NA} changes. At NA 0.3 it is 1.4/0.3 = 4.7 times larger (first dark ring at 1.06 µm instead of 227 nm at 520 nm).
B6. (a) A short line of length 0.5 µm along x, uniform brightness (constant speed). (b) The OTF along x is \mathrm{sinc}(Lk) with zeros at k = 1/L, 2/L, \dots = 2, 4, 6, … cycles/µm: periods 500 nm, 250 nm, 167 nm, …. Each of these is averaged over exactly a whole number of periods during the motion. (c) Nothing: moving along the stripes does not change what each pixel sees. The OTF along y is 1 (apart from the lens’s own blur).
B7. Not the colour table: defocus. The OTF of a defocused lens becomes negative at some frequencies. A stripe pattern with such a frequency is imaged as 1 + H\cos(\dots) with H < 0: shifted by half a period, so bright and dark swap. Only the stripes in that frequency band are inverted; coarser stripes keep their sign.
Math questions
B8. (math) The pupil of a lens is a disc of radius \rho_0 = \mathrm{NA}/\lambda in frequency space, and the incoherent OTF is the autocorrelation of the pupil, H(\mathbf k) \propto \int P(\boldsymbol\rho)\,P(\boldsymbol\rho + \mathbf k)\,d\boldsymbol\rho. (a) Explain why H(\mathbf k) = 0 for |\mathbf k| > 2\rho_0. (b) Compute H for a one-dimensional “pupil” P(\rho) = 1 for |\rho| \le \rho_0 (a slit), normalised so that H(0) = 1. What shape is it?
B9. (math) Show that a PSF with h(-\mathbf x) = h(\mathbf x) has a real OTF. Give an example of a symmetric PSF whose OTF is negative somewhere.
B10. (math) Motion blur over a length L along x: h(x) = \tfrac1L for |x| \le L/2, else 0. (a) Compute H(k) and its zeros. (b) The image of the grating 1 + \cos(2\pi k x) is 1 + H(k)\cos(2\pi kx). For L = 1 µm, what is the image of a grating with period 700 nm?
B8. (a) P(\boldsymbol\rho)P(\boldsymbol\rho + \mathbf k) is non-zero only where the disc and its copy shifted by -\mathbf k overlap. Two discs of radius \rho_0 whose centres are more than 2\rho_0 apart do not overlap: H = 0 for |\mathbf k| > 2\rho_0 = 2\mathrm{NA}/\lambda. (b) The overlap of two intervals of length 2\rho_0 shifted by k has length 2\rho_0 - |k| for |k| \le 2\rho_0. Normalised: H(k) = 1 - |k|/(2\rho_0), a triangle, falling linearly from 1 to 0 at the cut-off. (The circular pupil gives the curved version \tfrac2\pi(\arccos s - s\sqrt{1 - s^2}), which also starts with a straight fall.)
B9. H(\mathbf k) = \int h(\mathbf x)\,e^{-2\pi i\mathbf k\cdot\mathbf x}d\mathbf x. Its complex conjugate is \int h(\mathbf x)\,e^{2\pi i\mathbf k\cdot\mathbf x}d\mathbf x; substituting \mathbf x \to -\mathbf x and using h(-\mathbf x) = h(\mathbf x) gives H(\mathbf k) back. A number equal to its conjugate is real. Example: the uniform line of B10, H = \mathrm{sinc}(Lk), negative between 1/L and 2/L; or a uniform disc (geometric defocus), whose OTF 2J_1(x)/x is negative between its first two zeros.
B10. (a) H(k) = \frac1L\int_{-L/2}^{L/2}e^{-2\pi ikx}dx = \frac{e^{-i\pi Lk} - e^{i\pi Lk}}{-2\pi i L k} = \frac{\sin(\pi Lk)}{\pi Lk}, zero at k = m/L, m = \pm1, \pm2, \dots (b) Period 700 nm: k = 1.43 cycles/µm, \pi L k = 4.49, H = \sin(4.49)/4.49 = -0.217. The image is 1 - 0.217\cos(2\pi kx): the grating with 22 % of its contrast, inverted.
Explore
The demo computes the PSF of an ideal lens from its pupil on a 256 × 256 grid of 40 nm pixels (a 10 µm field), and blurs a test object with it. Panels: the PSF (2.6 µm wide; tick “log scale” to see the rings), the OTF as an image up to ±8 cycles/µm with the cut-off circle 2\mathrm{NA}/\lambda in red (tick “signed” to see negative values in blue), the object and its image. The plot shows the OTF along the horizontal frequency axis with the curve of an ideal in-focus lens (dashed). The PSF menu adds defocus, motion blur, or the Gaussian approximation. The micrograph is treated as the true object with 40 nm pixels (it is itself already a blurred image).
E1. Preset oil objective, NA 1.4. Write down the Rayleigh distance, the Abbe distance, the cut-off and the PSF FWHM. Check the FWHM against 0.51\lambda/\mathrm{NA}. Where does the blue curve reach zero?
E2. Lower the NA to 0.3 (preset dry objective). By what factor do the FWHM and the cut-off change? Compare with the ratio of the NAs. What happens to the micrograph?
E3. Choose the Siemens star as object. Its 16 bright spokes have period 2\pi r/16 at radius r. At NA 1.4 and at NA 0.3, estimate the radius of the grey disc in the middle where the spokes disappear, and predict it from the Abbe distance.
E4. Preset blue vs red (NA 0.8, bar groups with periods 160–800 nm, finest top left). Which groups show bars at 450 nm? Move λ to 650 nm: which groups disappear? Use the Abbe distance to explain.
E5. Preset defocus: contrast reversal (NA 0.7, 2 µm out of focus). In which frequency range is the OTF negative? Find a spoke of the star that changes from bright to dark along its length. Then set the defocus to 0: does any part of the OTF stay negative?
E6. Preset motion blur (1 µm along x). Where are the zeros of the OTF, and how negative does it get? Change the motion length to 0.5 µm and the angle to 90°: where are the zeros now, and which spokes of the star are affected?
E7. Preset Gaussian approximation. Compare its FWHM with the Airy PSF’s (switch the PSF menu to “lens”). Where do the two OTF curves differ most? What does the Gaussian OTF do beyond the cut-off?
E1. Rayleigh 227 nm, Abbe 186 nm, cut-off 5.38 cycles/µm, PSF FWHM 192 nm. 0.51 \cdot 520/1.4 = 191 nm: they agree (the demo measures on 40 nm pixels). The blue curve follows the dashed ideal curve and reaches zero at the red line, 5.38 cycles/µm.
E2. At NA 0.3: FWHM 891 nm and cut-off 1.15 cycles/µm. The FWHM grows by 891/192 = 4.6 and the cut-off falls by 5.38/1.15 = 4.7, both the ratio of the NAs, 1.4/0.3 = 4.7. The micrograph keeps only its coarse structure (the nucleus outline); the fine granules are gone, and the red circle in the OTF panel has shrunk to a small disc.
E3. The spokes vanish where their period 2\pi r/16 drops below the Abbe distance: r = 16 \cdot \lambda/(2\mathrm{NA})/(2\pi). NA 1.4: 16 \cdot 186/(2\pi) = 0.47 µm, about 12 pixels; NA 0.3: 16 \cdot 867/(2\pi) = 2.2 µm, about 55 pixels, a quarter of the field. Inside that radius the star is uniformly grey.
E4. At 450 nm (Abbe 450/1.6 = 281 nm) the groups with periods 320 nm (faint, tick “stretch”) and 400 nm and above show bars; 160–240 nm are grey. At 650 nm (Abbe 650/1.6 = 406 nm) the 320 nm and 400 nm groups disappear too; 480 nm is still faintly visible. Their frequency is now beyond the cut-off. The readout’s cut-off moves from 3.56 to 2.46 cycles/µm.
E5. The OTF is negative from about 0.55 to 2.3 cycles/µm (most negative about −0.06 near 0.7 cycles/µm), then slightly positive until the cut-off 2.69 cycles/µm. On the star these frequencies lie between radii of about 1.1 and 4.6 µm: a spoke that is bright near the rim becomes dark in that band. With defocus 0 the OTF is positive everywhere up to the cut-off: the in-focus lens never reverses contrast.
E6. Zeros at 1 and 2 cycles/µm (every 1/L); the curve dips to about −0.14 near 1.4 cycles/µm. With 0.5 µm the zeros move to 2 and 4 cycles/µm (fewer within the cut-off). At 90° the motion is vertical: the stripes in the OTF image turn by 90°, the curve along the horizontal axis is the lens’s own OTF again, and now the horizontal spokes of the star (whose stripes vary along y) lose contrast instead of the vertical ones.
E7. FWHM 186 nm for the Gaussian, 192 nm for the lens. The OTF curves differ most at low frequencies (at 1 cycle/µm: 0.89 for the Gaussian against 0.77) and near the cut-off; around 3–4 cycles/µm they nearly agree. Beyond the cut-off the Gaussian OTF is small but not zero (0.03 at 5.4 cycles/µm): it lets through a little of what a real lens cannot pass. In log scale the Gaussian PSF has no rings.
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/psf/exercise.rs.
C1. image_of_points(points, psf): the image of a row of point sources as a sum of shifted copies of the PSF, one per point, scaled by its brightness. Light that falls off the ends of the row is lost.
image = row of zeros
for every point p:
for every PSF element j: # r = the middle of the PSF
image[p + j − r] = image[p + j − r] + brightness[p] · psf[j] # if inside the row
The checks are the three points of the lecture (brightness 1, 2, 1 at positions 1, 4, 6) and your answer to B1.
C2. gaussian_psf(sigma): the Gaussian approximation of the PSF on a square of 2\lceil 3\sigma\rceil + 1 pixels, normalised to sum 1; motion_psf(length): a line of length pixels along x, each 1/\text{length}.
C3. blur(img, psf, border): blur a whole image with a PSF of any (odd) size. The same sum of shifted PSFs, written the other way round: each output pixel collects the light that reaches it.
for every pixel (x, y):
sum = 0
for every PSF pixel (i, j): # offset from the PSF's centre: (dx, dy)
sum = sum + psf(i, j) · I(x − dx, y − dy) # outside the image: the border rule
out(x, y) = sum
The minus signs flip the PSF, unlike the filters of the filtering unit: the check blurs a single bright pixel with a lopsided PSF and expects the PSF itself, the right way round.
C4. otf(psf, k): the OTF of a symmetric 1D PSF at k cycles per pixel, H(k) = \sum_j h_j \cos\big(2\pi k (j - r)\big). The checks: (1, 2, 1)/4 keeps the three waves of the frequency unit by 1, 0.5 and 0, and motion over 5 pixels has zeros at k = 1/5 and 2/5 (B6).
C5. lens_mtf(k, na, wavelength): the MTF of an ideal lens, the formula of the slide “The math: the pupil and the Airy pattern”. The check is B4.
Then cargo run -p imageformation -- psf and open the pictures in out/psf/. The micrograph is treated as the true object with 40 nm pixels and imaged through two lenses (Gaussian approximation, 520 nm), and through 1 µm of motion along x. The program also images gratings of several periods and prints their contrast.
C6. Compare image-na14.png and image-na5.png with object.png. What is left of the small dark granules, and of the outline of the nucleus? Then look at image-motion.png: in which direction is the image still sharp?
C7. In the table for NA 1.4, compare the column “contrast in the image” with “OTF of the PSF”. Why must they agree? Then compare the Gaussian with the ideal lens: where does the Gaussian approximation keep too much contrast, and what does it do with the 160 nm grating?
C8. In the table for motion, which gratings vanish, and which one comes out with negative contrast? Open grating-700nm.png and grating-700nm-motion.png side by side: where are the bright stripes of the image?
The model solution is imageformation/src/psf/solution.rs in the download.
C6. At NA 1.4 (\sigma = 1.95 pixels = 78 nm) the granules are still visible but soft, and the outline of the nucleus is a thin, blurred line. At NA 0.5 (\sigma = 5.46 pixels = 218 nm) the granules are gone and only the dark shape of the nucleus and the large structures remain. With motion along x everything is smeared into horizontal streaks 25 pixels (1 µm) long, and the steep left and right edges of the nucleus are wide ramps. Along y nothing is blurred: the streaks change sharply from one row to the next, as in B6(c).
C7. A grating 0.5 + 0.5\cos(2\pi k x) is imaged as 0.5 + 0.5\,H(k)\cos(2\pi k x) (slide “The math: convolution and the OTF”), so the contrast that is measured is H(k): 0.888, 0.620, 0.309, 0.146 and 0.009 in both columns. The Gaussian keeps too much at low frequencies (0.888 against 0.765 for the ideal lens at period 1 µm, 0.620 against 0.538 at 500 nm), agrees well around 3–4 cycles/µm (0.309 against 0.305, 0.146 against 0.150), and lets through a trace (0.009) of the 160 nm grating, which lies beyond the cut-off of 5.38 cycles/µm, where a real lens passes nothing.
C8. The gratings with periods 1000 nm and 500 nm vanish (contrast 0.000): 1 µm of motion averages exactly one or two whole periods (zeros of the OTF at 1 and 2 cycles/µm). The 2000 nm grating keeps 0.637 of its contrast. The 700 nm grating comes out with −0.218, the value of B10: the image has bright stripes exactly where the object has dark ones, shifted by half a period, at 22 % of the contrast.
Where this leads
The OTF says which frequencies the optics deliver. The next unit asks the practical questions that follow: when are two points resolved, how large may a pixel be (Nyquist for a microscope), why is the PSF longer along the optical axis, and how do we measure a PSF with beads. Later, the forward model is run backwards (deconvolution), spot detectors are tuned to the PSF (point detection), and tomography replaces the PSF by line integrals (the Radon transform).