Confocal Microscopy & Wavefront Control

Introduction: Ideal Pupils and Real Aberrations

In Lectures 8 and 9, we established the Optical Transfer Function (OTF) framework for understanding microscope resolution. The OTF connects the pupil function \(P(\mathbf{k})\) to image contrast through the autocorrelation: \[\text{OTF}(\mathbf{k}) = \frac{\mathcal{F}\{|\text{PSF}|^2\}(\mathbf{k})}{\text{OTF}(0)}\]

In those lectures, we assumed an ideal, aberration-free pupil. Real microscopes are not so fortunate: a cover slip of wrong thickness causes spherical aberration; misalignment introduces coma; high-NA systems suffer field curvature. All of these distortions modify the pupil function—and hence degrade the OTF and resolution.

Learning objectives:

  • Understand how confocal microscopy improves the OTF by combining illumination and detection in Fourier space
  • Recognize that aberrations are pupil-plane defects: real \(P(\rho) = A(\rho) \exp(i W(\rho))\) where \(W\) is wavefront error
  • Use Zernike polynomials to decompose and visualize aberrations on circular apertures
  • Learn wavefront sensing (Shack-Hartmann) as a measurement tool
  • Apply adaptive optics to correct aberrations and recover diffraction-limited performance
  • Connect all concepts to practical tools used in the MoNa lab: SLMs, AOMs, and deformable mirrors

1. Confocal Microscopy Revisited: The OTF Perspective

Beyond Widefield: Confocal Fluorescence Detection

In Lecture 9, we briefly introduced confocal microscopy. Recall the setup: - Illumination: Focused laser beam (illumination PSF: \(\text{PSF}_\text{ill}\)) - Detection: Fluorescence collected through a pinhole (detection PSF: \(\text{PSF}_\text{det}\)) - Effective PSF: Product of the two: \(\text{PSF}_\text{conf} = \text{PSF}_\text{ill} \times \text{PSF}_\text{det}\)

Confocal PSF in Real Space

The key insight is that the confocal PSF is narrower than widefield. For a pinhole diameter comparable to the Airy disk, the axial FWHM narrows by ~40 %, and lateral resolution improves by ~1.4×.

Confocal OTF: Fourier-Space View

In Fourier space, multiplication becomes convolution: \[\text{OTF}_\text{conf}(\mathbf{k}) = \text{OTF}_\text{ill}(\mathbf{k}) \otimes \text{OTF}_\text{det}(\mathbf{k})\]

What this means: - Each OTF independently is real and non-negative (pupil is real and positive) - Their convolution is the product of autocorrelations - The result: higher contrast at high spatial frequencies - Missing cone is filled: the axial frequencies that widefield cannot capture are recovered by confocal detection

This is the essence of confocal’s advantage: it exploits the fact that illumination and detection can be independently controlled in Fourier space.

Pinhole as Spatial Frequency Filter

The pinhole diameter directly controls the width of \(\text{OTF}_\text{det}\): - Large pinhole → broad \(\text{OTF}_\text{det}\) → approaches widefield behavior - Small pinhole (≪ Airy disk) → narrow \(\text{OTF}_\text{det}\) → strong rejection of out-of-focus light, but signal loss - Optimal pinhole (~0.5–1.0 Airy unit): best trade-off between contrast and signal

Fast Beam Scanning: AOMs and Mirrors

To build a practical confocal microscope, the illumination beam must scan the specimen in \(x\), \(y\), and \(z\). Two approaches dominate:

Acousto-Optic Modulators (AOMs): - Diffract a laser beam using an acoustic wave traveling through a crystal - Frequency shift: \(\nu_\text{out} = \nu_\text{in} \pm \nu_\text{acoustic}\) - Beam deflection angle proportional to acoustic frequency (tunable) - Speed: microsecond switching, MHz modulation bandwidth - Application in MoNa: Fast beam steering, modulation, and raster scanning - Advantage: no moving parts, electrically controlled

Galvanometric Mirrors (Galvos): - Electromagnetically controlled mirrors for \(x\) and \(y\) beam deflection - Speed: kHz scanning rates for video-rate imaging - Common in commercial confocal systems

Both tools exploit the pupil plane (back aperture of the objective): modulating the beam’s angle there directly translates to lateral scan position at the specimen plane.


2. Aberrations and the Pupil Function

The General Pupil Function

We now recognize that the pupil function is not always ideal. The general form is: \[P(\rho, \theta) = A(\rho) \, e^{i W(\rho, \theta)}\]

where: - \(A(\rho)\) is the aperture function (amplitude; typically = 1 inside the pupil, 0 outside) - \(W(\rho, \theta)\) is the wavefront error (in units of length, or often in units of wavelength) - \((\rho, \theta)\) are polar coordinates in the pupil plane

Physical sources of wavefront error: 1. Cover slip mismatch: Incorrect cover slip thickness introduces spherical aberration 2. Refractive index mismatch: Specimen immersion medium differs from design medium (water vs. oil) 3. Misalignment: Objective not perpendicular to specimen plane → coma 4. Field curvature: Aberration increases toward the edge of the field 5. Lens defects: Manufacturing imperfections in optical coatings or surfaces

How Aberrations Degrade the OTF

The aberrated OTF is: \[\text{OTF}_\text{aberr}(\mathbf{k}) \propto \left| \mathcal{F}\left\{ P(\mathbf{r}) \right\}(\mathbf{k}) \right|^2 = \left| \int e^{i W(\mathbf{r})} e^{i \mathbf{k} \cdot \mathbf{r}} d^2\mathbf{r} \right|^2\]

Key observation: Even small wavefront errors reduce the contrast of the OTF, especially at high spatial frequencies. The effect is multiplicative: if \(W \ll 1\) rad, the OTF scales approximately as: \[\text{OTF}_\text{aberr} \approx \text{OTF}_\text{ideal} \cdot \exp(-\sigma_W^2 / 2)\]

where \(\sigma_W^2 = \langle W^2 \rangle\) is the variance of the wavefront error.

The Strehl Ratio: A Quantitative Measure

The Strehl ratio \(S\) measures the reduction in peak intensity of the PSF due to aberrations: \[S = \frac{\max(\text{PSF}_\text{aberr})}{\max(\text{PSF}_\text{ideal})} = \left| \langle e^{i W} \rangle \right|^2\]

where the angle brackets denote averaging over the pupil.

For small aberrations (Maréchal approximation): \[S \approx e^{-\sigma_W^2} \approx 1 - \sigma_W^2\]

Rule of thumb: - \(S > 0.8\) (good): system diffraction-limited - \(S = 0.5\)–0.8: noticeable degradation - \(S < 0.5\): severe, visible loss of resolution

Wavelength dependence: Aberrations are always expressed relative to \(\lambda\). A fixed defocus (e.g., 1 μm) is worse for shorter wavelengths (where it corresponds to more wavelengths) and negligible for longer wavelengths.

Example: Spherical Aberration from Cover Slip Mismatch

A typical case: specimen imaged through a 170 μm cover slip with water immersion (\(n = 1.33\)), but objective designed for oil (\(n = 1.515\)).

The aberration magnitude is roughly: \[W_\text{sph} \sim (n_\text{oil} - n_\text{water}) \cdot t / \text{NA}^2\]

where \(t\) is the mismatch. For \(\Delta n \sim 0.2\), \(t \sim 10\) μm, \(\text{NA} = 1.4\): \[W_\text{sph} \sim 1 \text{ μm} \sim 3 \text{ wavelengths at } 488 \text{ nm}\]

This causes a dramatic loss of contrast and axial resolution—a major problem in deep-tissue imaging.


3. Zernike Polynomials: The Natural Pupil-Plane Basis

Why Zernike?

Circular apertures (objectives) naturally admit an orthonormal basis of functions: the Zernike polynomials. These are defined on the unit disk and indexed by two integers: - \(n\) = radial order (polynomial degree) - \(m\) = azimuthal order (angular frequency)

Orthonormality

The Zernike polynomials \(Z_n^m(\rho, \theta)\) satisfy: \[\int_0^{2\pi} \int_0^1 Z_n^m(\rho, \theta) \, Z_{n'}^{m'}(\rho, \theta) \, \rho \, d\rho \, d\theta = \delta_{nn'} \delta_{mm'}\]

This makes them ideal for decomposing any wavefront error on a circular pupil: \[W(\rho, \theta) = \sum_{n,m} c_{n,m} \, Z_n^m(\rho, \theta)\]

The coefficients \(c_{n,m}\) directly represent the “strength” of each aberration mode.

Low-Order Zernike Modes and Physical Meaning

The first 15 Zernike modes are shown below with their conventional names (using Noll indexing):

Mode \(n\) \(m\) Name Physical Meaning
1 0 0 Piston Uniform phase shift (no effect)
2–3 1 ±1 Tip/Tilt Linear phase; equivalent to beam pointing error
4 2 0 Defocus Quadratic wavefront; changes focal plane
5–6 2 ±2 Astigmatism Cylindrical lens effect; different focus in \(x\), \(y\)
7–8 3 ±1 Coma Asymmetric aberration from misalignment
9–10 3 ±3 Trefoil Three-fold asymmetry
11 4 0 Spherical Aberration Paraxial and marginal rays focus differently
12–13 4 ±2 Secondary Astigmatism Higher-order version of astigmatism
14–15 4 ±4 Quatrefoil Four-fold asymmetry

Physical importance: - Piston (mode 1): Just a global phase shift; doesn’t affect intensity (image-forming modes start at 2) - Tip/Tilt (modes 2–3): Beam walk; can be corrected by an AOM - Defocus (mode 4): Most common aberration; easily corrected by z-stage adjustment - Astigmatism (modes 5–6): Common in high-NA systems; requires SLM or deformable mirror to correct - Coma (modes 7–8): Signature of misalignment; usually fixed mechanically - Spherical aberration (mode 11): Depth-dependent; increases with depth in scattering tissue; adaptive optics gold standard target


4. Zernike Visualization and Aberration Impact

Code
fig, axes = plt.subplots(3, 5, figsize=get_size(15, 9))
axes = axes.flatten()

# Noll indexing: map linear index to (n, m)
noll_modes = [
    (0, 0),   # 1: piston
    (1, -1),  # 2: tip
    (1, 1),   # 3: tilt
    (2, 0),   # 4: defocus
    (2, -2),  # 5: astigmatism
    (2, 2),   # 6: astigmatism
    (3, -1),  # 7: coma
    (3, 1),   # 8: coma
    (3, -3),  # 9: trefoil
    (3, 3),   # 10: trefoil
    (4, 0),   # 11: spherical
    (4, -2),  # 12: secondary astigmatism
    (4, 2),   # 13: secondary astigmatism
    (4, -4),  # 14: quatrefoil
    (4, 4),   # 15: quatrefoil
]

names = ['Piston', 'Tip', 'Tilt', 'Defocus', 'Astig. x', 'Astig. y',
         'Coma x', 'Coma y', 'Trefoil x', 'Trefoil y', 'Sph. Aber.',
         'Sec. Astig. x', 'Sec. Astig. y', 'Quatrefoil x', 'Quatrefoil y']

# Radial Zernike polynomials (standard definition)
def zernike_radial(n, m, rho):
    """Radial part of Zernike polynomial"""
    if (n - m) % 2 != 0:
        return np.zeros_like(rho)

    result = np.zeros_like(rho, dtype=float)
    for k in range((n - m) // 2 + 1):
        coeff = ((-1)**k * math.factorial(n - k) /
                (math.factorial(k) * math.factorial((n + m) // 2 - k) *
                 math.factorial((n - m) // 2 - k)))
        result += coeff * rho**(n - 2*k)
    return result

def zernike_mode(n, m, rho, theta):
    """Full Zernike polynomial Z_n^m"""
    rad = zernike_radial(n, abs(m), rho)
    if m < 0:
        return rad * np.sin(abs(m) * theta)
    elif m > 0:
        return rad * np.cos(m * theta)
    else:
        return rad

# Generate grid
rho_grid = np.linspace(0, 1, 200)
theta_grid = np.linspace(0, 2*np.pi, 200)
Rho, Theta = np.meshgrid(rho_grid, theta_grid)

for idx, ((n, m), name) in enumerate(zip(noll_modes, names)):
    ax = axes[idx]

    # Compute Zernike mode
    Z = zernike_mode(n, m, Rho, Theta)

    # Mask outside unit circle
    mask = Rho <= 1
    Z[~mask] = 0

    # Plot
    im = ax.contourf(Theta, Rho, Z, levels=20, cmap='RdBu_r', vmin=-1, vmax=1)
    circle = plt.Circle((np.pi, 0), 1, fill=False, edgecolor='black', linewidth=1)
    ax.add_patch(circle)

    ax.set_xlim(0, 2*np.pi)
    ax.set_ylim(0, 1.1)
    ax.set_aspect('equal')
    ax.set_title(f'{idx+1}: {name}', fontsize=9)
    ax.set_xticks([])
    ax.set_yticks([])

plt.tight_layout()
plt.savefig('img/zernike_modes.png', dpi=150, bbox_inches='tight')
plt.show()

print("✓ Zernike polynomial modes visualized")
Figure 5.1— Zernike polynomial modes (first 15, Noll indexing). Each panel shows the phase pattern \(Z_n^m(\rho, \theta)\) on the unit disk. Colors represent phase from \(-\pi\) (blue) to \(+\pi\) (red). Modes 2–3 (tip/tilt) are linear; mode 4 (defocus) is parabolic; mode 11 (spherical aberration) is quartic.
✓ Zernike polynomial modes visualized

5. Impact of Aberrations on PSF and OTF

To understand how aberrations degrade imaging performance, we now visualize the effect on PSF and OTF for realistic aberration magnitudes.

Code
fig = plt.figure(figsize=get_size(15, 10))
gs = fig.add_gridspec(3, 3, hspace=0.35, wspace=0.3)

# Parameters
wavelength = 488e-9  # nm
NA = 1.4
n_med = 1.33  # water
k0 = 2*np.pi / wavelength
k_cutoff = NA * k0

# Grid in pupil plane
pupil_size = 100
rho_pupil = np.linspace(0, 1, pupil_size)
theta_pupil = np.linspace(0, 2*np.pi, pupil_size)
Rho_p, Theta_p = np.meshgrid(rho_pupil, theta_pupil)

# Aperture function (circular)
aperture = (Rho_p <= 1).astype(float)

# Grid in real space
real_size = 256
x = np.linspace(-5e-6, 5e-6, real_size)
y = np.linspace(-5e-6, 5e-6, real_size)
X, Y = np.meshgrid(x, y)

# Aberration cases
cases = [
    ('Ideal', np.zeros_like(Rho_p)),
    ('Spherical Aber.', 2.0 * (Rho_p**4 - 1.5*Rho_p**2 + 0.5)),  # ~2 wavelengths
    ('Coma', 1.5 * Rho_p**2 * np.cos(Theta_p))  # ~1.5 wavelengths
]

for col, (label, W) in enumerate(cases):
    # Pupil function
    P = aperture * np.exp(1j * W * wavelength / wavelength)  # W in units of wavelength

    # PSF: FFT of pupil, squared magnitude
    P_padded = np.pad(P, ((0, 256), (0, 256)), mode='constant')
    PSF_ft = fftshift(fft2(ifftshift(P_padded)))
    PSF = np.abs(PSF_ft)**2
    PSF /= np.max(PSF)  # Normalize

    # OTF: autocorrelation of pupil (or FFT of PSF magnitude squared)
    OTF = np.abs(fftshift(fft2(PSF)))**2
    OTF /= np.max(OTF)

    # --- Row 1: Pupil plane (phase) ---
    ax = fig.add_subplot(gs[0, col])
    # Mask outside aperture for visualization
    W_vis = np.where(Rho_p <= 1, W, np.nan)
    im = ax.contourf(Rho_p, Theta_p, W_vis, levels=15, cmap='hsv', vmin=-3, vmax=3)
    circle = plt.Circle((0.5, 0), 1, fill=False, edgecolor='black', linewidth=1.5)
    ax.set_xlim(-1.2, 1.2)
    ax.set_ylim(-1.2, 1.2)
    ax.set_aspect('equal')
    ax.set_title(label, fontsize=10, fontweight='bold')
    ax.set_xticks([])
    ax.set_yticks([])

    # --- Row 2: PSF (lateral cross-section) ---
    ax = fig.add_subplot(gs[1, col])
    # Extract 1D profile along y=0
    center = PSF.shape[0] // 2
    psf_1d = PSF[center, :]
    x_psf = np.linspace(-5, 5, len(psf_1d))
    ax.plot(x_psf, psf_1d, 'b-', linewidth=2)
    ax.fill_between(x_psf, 0, psf_1d, alpha=0.3, color='blue')
    ax.set_xlim(-5, 5)
    ax.set_ylim(0, 1.1)
    ax.set_xlabel('Position (μm)')
    ax.set_ylabel('Intensity')
    ax.grid(True, alpha=0.3)

    # Compute Strehl ratio
    strehl = np.max(PSF)
    ax.text(0.95, 0.95, f'Strehl: {strehl:.3f}', transform=ax.transAxes,
            ha='right', va='top', fontsize=9, bbox=dict(boxstyle='round', facecolor='wheat', alpha=0.5))

    # --- Row 3: OTF (magnitude) ---
    ax = fig.add_subplot(gs[2, col])
    # Normalize frequency axis
    freq_size = OTF.shape[0]
    freq_max = 2 * k_cutoff / (2*np.pi)  # In units of 1/micron
    freq_axis = np.linspace(-freq_max, freq_max, freq_size)

    # Extract 1D OTF profile
    otf_1d = OTF[freq_size//2, :]
    ax.plot(freq_axis, otf_1d, 'r-', linewidth=2)
    ax.fill_between(freq_axis, 0, otf_1d, alpha=0.3, color='red')
    # Mark cutoff frequency
    ax.axvline(freq_max/2, color='cyan', linestyle='--', linewidth=1.5, alpha=0.7, label='Cutoff')
    ax.set_xlim(-freq_max, freq_max)
    ax.set_ylim(0, 1.1)
    ax.set_xlabel('Spatial freq. (μm$^{-1}$)')
    ax.set_ylabel('OTF magnitude')
    ax.grid(True, alpha=0.3)
    if col == 2:
        ax.legend(fontsize=8)

plt.tight_layout()
plt.savefig('img/aberration_impact.png', dpi=150, bbox_inches='tight')
plt.show()

print("✓ Aberration impact on PSF and OTF visualized")
print("\nStrehl ratio relationship: good (>0.8), acceptable (0.5-0.8), poor (<0.5)")
Figure 6.1— Effect of aberrations on PSF and OTF. Top row: pupil phase (hsv colormap, units of \(\lambda\)) for ideal (aberration-free), spherical aberration (~2 wavelengths), and coma (~1.5 wavelengths). Middle row: corresponding point-spread functions (lateral cross-section). Bottom row: magnitude of the OTF (frequency response), showing degradation of contrast at high spatial frequencies.
✓ Aberration impact on PSF and OTF visualized

Strehl ratio relationship: good (>0.8), acceptable (0.5-0.8), poor (<0.5)

6. Wavefront Sensing: The Shack-Hartmann Sensor

To correct aberrations, we must first measure them. The most common wavefront sensing technique is the Shack-Hartmann sensor.

Principle: From Wavefront Slope to Phase

A Shack-Hartmann sensor comprises a microlens array (typically 10×10 to 40×40 lenslets) placed at the pupil plane, with a detector at the focal plane.

Key insight: Each lenslet measures the local slope of the wavefront: \[\frac{\partial W}{\partial x} \bigg|_{(\rho,\theta)} = \text{slope in } x \text{ direction}\]

The centroid shift of the focused spot from each lenslet is proportional to the local slope. By measuring all lenslet spots, we reconstruct the 2D slope field: \[\nabla W = \left( \frac{\partial W}{\partial x}, \frac{\partial W}{\partial y} \right)\]

Then we integrate to recover the phase \(W(\mathbf{r})\).

Fourier-Space Perspective: Connection to Slope and Frequency

In Fourier space, taking a spatial derivative is equivalent to multiplication by \(i \mathbf{k}\): \[\mathcal{F}\left\{ \frac{\partial W}{\partial x} \right\}(\mathbf{k}) = i k_x \, \widetilde{W}(\mathbf{k})\]

The Shack-Hartmann measurement is thus a high-pass filter on the phase: it emphasizes high-frequency ripples and is blind to low-frequency (piston, tip, tilt) modes.

This is identical to the mathematical principle of Differential Interference Contrast (DIC) microscopy, where a pair of orthogonal Wollaston prisms create an interference between light that is spatially shifted by ~\(\lambda/2\). Both techniques exploit spatial derivatives in the Fourier domain.

Reconstruction Algorithm

Once slopes are measured: 1. Compute \(\nabla W\) at all lenslet positions (from spot centroid displacements) 2. Reconstruct \(W(\mathbf{r})\) by least-squares integration (Zonal method): \[W(\mathbf{r}) = \arg \min \sum_{\text{grid points}} \left| \nabla W_\text{meas}(\mathbf{r}) - \nabla W_\text{recon}(\mathbf{r}) \right|^2\] 3. Decompose into Zernike modes to identify which aberrations are present 4. Send correction signal to deformable mirror or SLM


7. Adaptive Optics for Microscopy

Wavefront Correction Devices

Once aberrations are measured, we correct them by modulating the wavefront. Two complementary approaches:

Spatial Light Modulators (SLMs)

Liquid-Crystal SLMs apply a spatially varying phase shift to the incident beam: \[\Delta \phi(\mathbf{r}) = \frac{2\pi \Delta n(\mathbf{r}) \, d}{\lambda}\]

where \(\Delta n\) is the liquid-crystal birefringence (controlled electrically, 0–1 V) and \(d\) is the cell thickness.

Advantages: - Arbitrary phase patterns (Zernike modes, holograms, custom aberration correction) - Reconfigurable in real time (frame rate: 60–1000 Hz) - Compact; can be placed at pupil plane or in Fourier plane

MoNa lab connection: SLMs are used for: - Beam shaping: Creating flat-top or Bessel beams - Holographic optical trapping: Generating multiple foci for particle manipulation - Aberration correction: Real-time feedback to flatten wavefront

Limitations: - Phase-only (cannot modulate amplitude in traditional LC-SLMs) - Pixelation limits high-frequency content - Efficiency ~70–90% (residual diffraction orders)

Deformable Mirrors

Membrane or Piezo Mirrors physically deform a mirror surface to introduce a desired phase shift: \[\Delta \phi = \frac{2 \times \text{surface deflection}}{\lambda} \times 2\pi\]

(Factor of 2 because light reflects, doubling the optical path.)

Advantages: - Higher reflectance (>95%) - Can correct large aberrations (many waves) - Continuous surface (no pixelation)

Disadvantages: - Limited to low-order corrections (typically <50 actuators → low-order Zernike only) - Slower response time (ms)

Choice: - SLM: Fast correction, arbitrary modes, lab demonstration - Deformable mirror: High-NA systems, deep-tissue imaging where many aberration modes matter

Sensorless Adaptive Optics

When a wavefront sensor is unavailable or impractical, we use sensorless AO: directly optimize an image quality metric (e.g., intensity variance, maximum intensity, or a deconvolution cost function) by iteratively adjusting Zernike coefficients.

Algorithm: 1. Start with \(W = 0\) (flat wavefront) 2. Vary Zernike coefficient \(c_{n,m}\) (e.g., defocus) and measure the quality metric 3. Move in the direction that improves metric 4. Repeat for all low-order modes 5. Refine with finer steps until convergence

Speed: 1–10 seconds per correction (much slower than sensor-based, but requires no extra hardware)

Best for: Deep-tissue imaging, where aberrations increase with depth and drift slowly over time.


8. Application: Deep-Tissue Confocal Imaging with Adaptive Optics

The Problem: Spherical Aberration at Depth

In thick, scattering tissue (e.g., brain, muscle), refractive index variations accumulate as light propagates. A homogeneous spherical aberration develops due to mismatched refractive indices (tissue ≠ design medium).

Effect: - PSF degrades: side lobes increase, peak intensity drops (Strehl → 0.3–0.5) - Axial resolution worsens dramatically - Image contrast collapses within 50–100 μm depth

Adaptive Correction Strategy

  1. Measure the wavefront using Shack-Hartmann (either on a guide star or back-reflected from deep structures)
  2. Decompose into Zernike modes: typically spherical aberration dominates (mode 11), with secondary astigmatism (modes 12–13)
  3. Correct using an SLM or deformable mirror in the pupil plane
  4. Iterate as you move deeper: aberration increases slowly; re-correct every 10–20 μm

Result: Confocal PSF remains ~1 μm lateral, ~2–3 μm axial, even at 200 μm depth.

Without AO: PSF broadens to 2–3 μm lateral, 10–15 μm axial at the same depth.


9. Fourier Optics Thread: Summary Table

All concepts in this lecture are connected through the pupil function and its Fourier properties:

Concept Pupil-Plane Representation Fourier-Space Meaning
Confocal detection Product of two apertures OTF is convolution of two OTFs → higher contrast
Aberrations \(P = A \exp(iW)\) with \(W \neq 0\) OTF is autocorrelation of aberrated pupil → lower contrast
Zernike modes Basis expansion: \(W = \sum c_{n,m} Z_n^m\) Orthonormal set on unit disk; separates aberration types
Wavefront slope \(\nabla W(\mathbf{r})\) Multiplication by \(i\mathbf{k}\) in Fourier space; same as DIC
SLM correction Modulate \(P\) with \(\exp(i\Delta\phi_\text{SLM})\) Alter OTF by changing pupil; directly improve high-freq contrast
Shack-Hartmann Measure local slopes via lenslet array High-pass filtered wavefront measurement; insensitive to piston/tip/tilt

10. Code Example: Comparing PSF and OTF (Widefield vs. Confocal)

Code
fig = plt.figure(figsize=get_size(15, 9))
gs = fig.add_gridspec(1, 3, wspace=0.3)

# Parameters
wavelength = 488e-9
NA = 1.4
n_med = 1.33
k0 = 2*np.pi / wavelength

# Create ideal pupil (circular aperture)
pupil_size = 256
rho_p = np.linspace(-1.5, 1.5, pupil_size)
Rho_p = np.abs(np.fft.fftfreq(pupil_size, rho_p[1] - rho_p[0]))[:, None]
Rho_p = np.broadcast_to(Rho_p, (pupil_size, pupil_size))

pupil = (Rho_p <= 1).astype(complex)

# PSF: amplitude is pupil, intensity is |PSF|^2
PSF_raw = fftshift(fft2(ifftshift(pupil)))
PSF_widefield = np.abs(PSF_raw)**2
PSF_widefield /= np.max(PSF_widefield)

# Confocal: PSF is product of illumination and detection PSFs
# Confocal PSF in real space ~ |PSF_widefield|^2 (or equivalent, illumination × detection)
PSF_confocal = PSF_widefield**2
PSF_confocal /= np.max(PSF_confocal)

# OTF: autocorrelation of pupil (for widefield)
OTF_widefield = np.abs(fftshift(fft2(pupil * np.conj(pupil))))**2
OTF_widefield /= np.max(OTF_widefield)

# Confocal OTF: convolution of illumination and detection OTFs
# Approximation: convolve two copies of the OTF
OTF_confocal = np.zeros_like(OTF_widefield)
for i in range(pupil_size):
    for j in range(pupil_size):
        # Simplified: confocal is convolution-like
        OTF_confocal[i, j] = np.sum(OTF_widefield * np.roll(np.roll(OTF_widefield, i - pupil_size//2, axis=0), j - pupil_size//2, axis=1))

OTF_confocal /= np.max(OTF_confocal)

# --- Plot 1: PSF Comparison ---
ax = fig.add_subplot(gs[0, 0])
center = pupil_size // 2
psf_1d_wf = PSF_widefield[center, :]
psf_1d_conf = PSF_confocal[center, :]
x_psf = np.linspace(-10, 10, len(psf_1d_wf))

ax.plot(x_psf, psf_1d_wf, 'b-', linewidth=2.5, label='Widefield', alpha=0.8)
ax.plot(x_psf, psf_1d_conf, 'r-', linewidth=2.5, label='Confocal', alpha=0.8)
ax.fill_between(x_psf, 0, psf_1d_wf, alpha=0.2, color='blue')
ax.fill_between(x_psf, 0, psf_1d_conf, alpha=0.2, color='red')

ax.set_xlabel('Distance (μm)')
ax.set_ylabel('Intensity (norm.)')
ax.set_xlim(-5, 5)
ax.set_ylim(0, 1.1)
ax.legend(fontsize=10, loc='upper right')
ax.grid(True, alpha=0.3)
ax.set_title('Real Space: PSF', fontweight='bold')

# --- Plot 2: OTF Comparison (1D) ---
ax = fig.add_subplot(gs[0, 1])
otf_1d_wf = OTF_widefield[center, :]
otf_1d_conf = OTF_confocal[center, :]
freq_max = 4.0
x_freq = np.linspace(-freq_max, freq_max, len(otf_1d_wf))

ax.plot(x_freq, otf_1d_wf, 'b-', linewidth=2.5, label='Widefield OTF', alpha=0.8)
ax.plot(x_freq, otf_1d_conf, 'r-', linewidth=2.5, label='Confocal OTF', alpha=0.8)
ax.fill_between(x_freq, 0, otf_1d_wf, alpha=0.2, color='blue')
ax.fill_between(x_freq, 0, otf_1d_conf, alpha=0.2, color='red')

ax.axvline(2.0, color='cyan', linestyle='--', linewidth=1.5, label='Cutoff')
ax.set_xlabel('Spatial frequency (1/μm)')
ax.set_ylabel('OTF magnitude')
ax.set_xlim(-freq_max, freq_max)
ax.set_ylim(-0.1, 1.1)
ax.legend(fontsize=9, loc='upper right')
ax.grid(True, alpha=0.3)
ax.set_title('Fourier Space: OTF (1D)', fontweight='bold')

# --- Plot 3: 2D Confocal OTF ---
ax = fig.add_subplot(gs[0, 2])
im = ax.contourf(x_freq, x_freq, OTF_confocal, levels=20, cmap='hot')
ax.set_xlabel('$k_x$ (1/μm)')
ax.set_ylabel('$k_y$ (1/μm)')
ax.set_aspect('equal')
ax.set_title('2D Confocal OTF', fontweight='bold')
# Draw circle showing diffraction limit
circle = plt.Circle((0, 0), 2.0, fill=False, edgecolor='cyan', linewidth=1.5, linestyle='--')
ax.add_patch(circle)

fig.set_layout_engine('constrained')
plt.savefig('img/confocal_otf.png', dpi=150, bbox_inches='tight')
plt.show()

print("✓ Confocal vs. widefield PSF and OTF comparison visualized")
Figure 11.1— Widefield vs. confocal microscopy in real space and Fourier space. Left: PSF (lateral cross-section) showing confocal narrowing (blue: widefield, red: confocal). Middle: OTF magnitude (1D profile) showing confocal gain at high frequencies (blue: widefield, red: confocal, cyan dashed: cutoff). Right: Full 2D confocal OTF (hot colormap), illustrating recovery of the missing cone.
✓ Confocal vs. widefield PSF and OTF comparison visualized

11. Experimental Connections

Building a Simple Confocal Path

A teaching-lab confocal microscope can be built from: 1. Laser source (e.g., 488 nm diode laser, 5 mW) 2. Dichroic mirror to combine excitation and collection paths 3. Objective lens (40× or 60×, high NA) 4. Pinhole (adjustable aperture, ~20–50 μm diameter) 5. PMT or avalanche photodiode for point detection

Procedure: - Align laser to objective back aperture - Focus on fluorescent sample (e.g., beads, labeled cells) - Mechanically or acousto-optically scan the beam - Adjust pinhole diameter to observe trade-off: signal vs. contrast

Key observation: As you close the pinhole, out-of-focus haze disappears, but signal drops. The optimal point is ~0.5–1.0 Airy unit (AU).

Measuring Zernike Aberrations with a Hartmann Sensor

A Hartmann test requires: 1. Collimated beam through the microscope objective (reverse direction) 2. Microlens array (40×40, ~300 μm focal length; can use printed diffractive element) 3. CCD camera at focal distance 4. Software to find lenslet spot centroids and compute slopes

Steps: - Acquire reference image (flat wavefront) - Acquire test image (with aberrations present) - Compute difference in centroid positions - Integrate slopes → recover phase map - Decompose into Zernike modes

Observation: You will see predominantly defocus and spherical aberration. Remove mechanical defects (tilted objective), and astigmatism typically vanishes.

Adaptive Optics in Practice: SLM-Based Correction

With an SLM at the pupil plane: 1. Apply an initial correction pattern (e.g., measured aberration phase) 2. Image the specimen; compute a quality metric (e.g., Laplacian variance) 3. Slightly perturb one Zernike coefficient; re-measure metric 4. Move in direction of improvement; repeat 5. Cycle through 5–10 low-order Zernike modes

Result: PSF sharpness visibly improves; axial sectioning becomes tighter; high-freq contrast recovers.


12. Summary: Fourier Optics in Microscopy

Key Concepts Revisited

  1. Confocal microscopy uses the product of two PSFs (illumination × detection) to improve OTF, particularly at high spatial frequencies

  2. Aberrations modify the pupil function \(P = A \exp(iW)\); even small wavefront errors degrade OTF and reduce Strehl ratio

  3. Zernike polynomials provide an orthonormal basis on the unit disk; low-order modes (defocus, astigmatism, coma, spherical) account for most real-world aberrations

  4. Wavefront sensing (Shack-Hartmann) measures the gradient of the phase field—a Fourier operation (\(\nabla W \leftrightarrow i\mathbf{k} \widetilde{W}\))—and reconstructs the full phase by integration

  5. Adaptive optics uses SLMs or deformable mirrors to correct measured aberrations, restoring diffraction-limited PSF even in aberrating media (thick tissue)

  6. SLMs and AOMs are essential tools in modern microscopy and in the MoNa lab for beam shaping, holographic manipulation, and real-time wavefront control

All of these phenomena have a unified Fourier-optics interpretation: the pupil function is the master object that controls resolution, contrast, and aberration behavior.


Further Reading

The following resources expand on the topics in this lecture:

  • Mertz (2019)Introduction to Optical Microscopy, Chapters 2–4. Comprehensive treatment of confocal imaging and the OTF framework.
  • Goodman (2017), Ch. 6–7 — Fourier optics foundations and propagation through optical systems.
  • Born & Wolf (1999), Ch. 8 — Aberrations, Zernike polynomials, and the theory of optical systems.
  • Tyson (2015)Principles of Adaptive Optics, 3rd ed. Standard reference for wavefront sensing and correction.
  • Booth, M.J., et al. (2021) — “Adaptive optics in microscopy.” Phil. Trans. R. Soc. A 379, 20200110. Review of AO in biomedical imaging.
  • Shack, R.V. & Platt, B.C. (1971) — “Production and use of a lenticular Hartmann screen.” J. Opt. Soc. Am. 61, 656–660. Foundational Shack-Hartmann paper.

Lecture 10: Confocal Microscopy & Wavefront Control — Introduction to Photonics