Foundations

Aperture and F-Number

The opening that limits the cone of light a lens accepts, its f-number N = f/d, why N rather than the diameter sets exposure, the marked stop sequence and its rounding, the working f-number at close focus, and how the aperture trades light against depth of field, diffraction, vignetting and the shape of out-of-focus blur.

beginner

The aperture of a lens is the opening that limits the cone of light it accepts from each point of the scene, and the f-number N=f/dN = f/d, the focal length divided by the diameter of that opening, is the number by which cameras set and report it. The aperture decides how much light reaches the sensor, and with it three properties of the image that a vision system cares about: the range of depths that look sharp, the diffraction blur that every finite opening adds, and the shape and fall-off of light across the frame. Photographers call the settings f-stops and write them as f/2, f/2.8, f/4; a “wide” or “fast” aperture has a small f-number, and “stopping down” means raising it.

Exposure introduces the f-number as one of the three exposure settings, with the 2\sqrt{2} stop spacing and reciprocity, and image formation gives the irradiance formula behind 1/N21/N^2 and the diffraction radius 1.22λN1.22\lambda N. This article covers the aperture itself: what the f-number is relative to, why it, rather than the diameter, is the useful number, how the marked values are rounded, how the effective f-number grows at close focus, and how the aperture’s side effects pull in opposite directions. Its example computes the blur of a defocused point across the whole f-stop sequence and shows that the sharpest setting lies between the extremes, at a place that depends on the depth, on how blur is measured and, much less, on the pixel.

Definition

In the thin lens model the aperture is a circular hole of diameter dd in the plane of the lens. Visionbook (§6.3.1) defines a camera’s f-number as the focal length divided by the diameter of the lens that light passes through, called the aperture: N=f/AN = f/A in its symbols, N=f/dN = f/d in this article’s, as in exposure and image formation. Levoy (Image Formation, slide 55) calls NN the relative aperture and dd the absolute aperture, and notes that writing “f/2” records how the diameter is obtained: divide the focal length by 2.

A real lens is a stack of elements. The following terms are standard optics, given here as our statement because no source read for this article defines them: the element that limits the cone of rays from an on-axis point, on a photographic lens an adjustable iris inside the barrel, is the aperture stop; its image formed by the elements in front of it, as seen from the object, is the entrance pupil, and its image seen from the sensor is the exit pupil. The f-number of a real lens is taken with the entrance pupil’s diameter for dd. ISETCam’s opticsGet.m has a “pupil magnification”, the ratio of the exit pupil’s diameter to the entrance pupil’s, and sets it to 1 for every model except a ray-traced lens, which in our reading is the thin-lens case where both pupils coincide with the lens. EMVA 1288 (§6.1) notes as a weak point of its own measurement geometry that it specifies the f-number but not the position of the exit pupil.

Intuition

Levoy (Image Formation, slides 52–53) explains why the ratio matters. Irradiance on the sensor is proportional to the square of the aperture diameter, because doubling the diameter quadruples the area that admits light, and inversely proportional to the square of the distance to the sensor, roughly the focal length: think of the lens as a collection of pinholes, each sending a cone of fixed angle, so that a sensor twice as far away spreads the same light over four times the area. The two effects cancel in the ratio f/df/d, so the f-number is defined relative to focal length “so that aperture values give irradiance regardless of lens” (slide 54). An f/2 setting gives the same exposure on a 50 mm lens, whose opening is then 25 mm wide, as on a 100 mm lens, whose opening is 50 mm; it follows, as the slide puts it, that low f-numbers on long telephoto lenses require fat lenses.

A note on the same slide answers a related question. On a zoom lens, holding the physical diameter fixed and zooming to a shorter focal length lowers NN and does gather more light; but if the camera is set to a fixed f-number, zooming wider is implemented by shrinking the physical aperture, and no extra light is gathered.

The same opening sets the width of the cone of rays from each scene point, and three side effects follow from that width. A wide cone widens quickly on either side of its apex: points away from the focus distance spread into large discs, so depth of field is shallow. A narrow cone stays thin over a longer stretch: depth of field is deep, but a narrow opening diffracts light more. And because each out-of-focus disc is a scaled image of the opening, the opening’s shape shows in the blur.

Formal Definition

The f-number and the light

With dd the aperture diameter and ff the focal length,

N=fd,E∝1N2,N = \frac{f}{d}, \qquad E \propto \frac{1}{N^2},

where EE is the irradiance on the sensor for a lens focused far away; the exact thin-lens irradiance formula, with its cos⁡4α\cos^4\alpha fall-off, is in image formation. Doubling NN halves the diameter and cuts the light by four, so a factor of two in light, one stop, is a factor 2\sqrt{2} in NN (Levoy, Image Formation, slide 56). This is where the marked sequence comes from: starting at N=1N = 1, the full stops are 2 k\sqrt{2}^{\,k}, written f/1.4, f/2, f/2.8, f/4, f/5.6, f/8, f/11, f/16, f/22, the values Levoy lists from f/2.8 to f/22 on the same slide. The marked values are rounded, as exposure notes; the example below computes the error in stops of each.

How small N can be

Levoy (Optics I, slide 49, crediting Kingslake) gives a definition that does not rely on the thin-lens picture. For a lens focused at infinity, the f-number is set by the angle θ′\theta' of the steepest ray that converges on the image point:

N=12sin⁡θ′.N = \frac{1}{2\sin\theta'}.

Since sin⁡θ′≤1\sin\theta' \le 1, the lowest possible f-number in air is f/0.5. Levoy reports f/1.0 as the lowest he had seen on an SLR lens (a discontinued Canon 50 mm f/1.0), and describes the Zeiss 50 mm f/0.7 lens that Kubrick used to film by candlelight in Barry Lyndon (slides 49–51).

Relation to numerical aperture

Microscope objectives are described instead by their numerical aperture NA=nsin⁡θ\mathrm{NA} = n\sin\theta, which optical microscopy defines and uses for resolution. Levoy (Optics II, slide 39) gives NA≈1/(2N)\mathrm{NA} \approx 1/(2N), and ISETCam’s opticsGet.m computes the numerical aperture as exactly 1/(2N)1/(2N), with a comment asking whether it should use the effective f-number instead. In our reading, the two are the same relation when n=1n = 1 and θ\theta is the image-side angle θ′\theta' in Levoy’s definition above; in the thin-lens picture with tan⁡θ′=d/(2f)\tan\theta' = d/(2f) it holds only for small angles.

The working f-number at close focus

The ratio f/df/d describes a lens focused at infinity, where the sensor is at distance ff. At a finite object distance the sensor moves back to the image distance ziz_i (see the thin lens model), and the cone that reaches it is narrower. ISETCam’s opticsGet.m makes the distinction explicit: its “fnumber” is “the f# assuming an object is infinitely far away”, and its “effective fnumber”, “the f# if the object is not at infinity”, is computed as N(1−m)N(1 - m) with the magnification mm negative for an inverted image. In the thin-lens model, the image distance is zi=f(1+∣m∣)z_i = f(1 + |m|), so the ratio of image distance to diameter is (our derivation)

Nw=zid=(1+∣m∣) N.N_w = \frac{z_i}{d} = (1 + |m|)\,N .

Levoy (Optics I, slide 60) gives the same rule, “use N’ = (1+MT)N at short conjugates”, for a Canon MP-E 65 mm macro lens at 5:1 magnification, with MT=5M_T = 5 entered as a positive number; his slides 41 and 53 define the transverse magnification with a sign, MT=−si/soM_T = -s_i/s_o, so the rule takes its magnitude. At 1:1, Nw=2NN_w = 2N: an f/8 lens at life size behaves like f/16 for light and diffraction. Levoy (slides 63–64) adds that extension tubes and teleconverters both raise the f-number and so reduce the light.

ISETCam’s diffraction code uses the same image-side quantity: dlMTF.m takes the incoherent cutoff frequency as the aperture diameter divided by the distance from the optics to the focal plane and the wavelength, d/(λzi)d/(\lambda z_i), which is 1/(λNw)1/(\lambda N_w). (A comment in the same file calls the ratio of aperture diameter to focal-plane distance “the f#”, the inverse of the definition; the code computes the cutoff correctly.) The f-number of EMVA 1288’s sensor test (§6.1, Eq. 46) is a different use of the same ratio: there no lens is mounted, and the f-number is the distance dd from the sensor to a disc-shaped light source divided by the source’s diameter DD; standard measurements require f-number 8, and with Release 4 they may optionally be made through a lens set to f/8 and focused at infinity.

Properties

Depth of field

The defocus disc of a point away from the focus distance is a scaled copy of the aperture, with diameter

c=f2 ∣z−zf∣N z (zf−f)c = \frac{f^2\,|z - z_f|}{N\,z\,(z_f - f)}

for a lens focused at zfz_f and a point at zz (the thin lens model derives it; image formation gives it as a derivation). It is inversely proportional to NN. Levoy (Optics I, slide 48) puts the consequence in one line, that a lower NN means a wider aperture and less depth of field, and (Image Formation, slide 57) that doubling NN, two stops, doubles the depth of field; visionbook (§6.3.1) derives the approximation D≈2NCU2/f2D \approx 2NCU^2/f^2 for the total depth of field at focus distance UU with an acceptable circle of confusion CC, and shows a ruler photographed at f/2, f/4 and f/8 whose sharp region doubles at each step (its Fig. 6.12). The limits, their asymmetry and the hyperfocal distance are worked out in depth of field.

Diffraction

A finite opening diffracts light, so even a perfect lens images a point as an Airy pattern. Levoy (Optics II, slide 36) notes that the blur grows as the aperture shrinks and as the distance to the sensor grows, so its size varies with N=f/dN = f/d, and that well-corrected lenses are called diffraction-limited. ISETCam’s airyDisk.m returns the radius of the pattern’s central disc, to its first dark ring, as 1.22 λN1.22\,\lambda N, and returns a diameter only when asked; image formation evaluates it as 1.9 µm at f/2.8, 5.4 µm at f/8 and 10.7 µm at f/16 for green light. In the frequency domain the same aperture sets the cutoff 1/(λN)1/(\lambda N) above which no contrast passes, which the point spread function article derives.

Levoy (Optics II, slide 39) writes the size as d=0.61λ/NA≈1.2Nλd = 0.61\lambda/\mathrm{NA} \approx 1.2N\lambda under the heading “The Abbe diffraction limit”. Optical microscopy names these quantities differently: 0.61λ/NA0.61\lambda/\mathrm{NA} is the Airy radius and the Rayleigh resolution distance, while Abbe’s limit is λ/(2 NA)\lambda/(2\,\mathrm{NA}); this article follows optical microscopy’s names. Levoy’s worked example is the iPhone 4 at f/3 in green light, d=2d = 2 µm against 1.75 µm pixels, so that it would be roughly diffraction-limited if its lenses were free of aberrations; the smaller the pixels, the more of them the pattern covers (slide 38). His summary slide (40) advises avoiding f-numbers above f/13 on a full-frame camera, a rule of thumb for that format.

Aberrations and vignetting

Stopping down also removes the outer rays of each cone. Levoy (Optics II, slide 24) states that all of the Seidel aberrations except distortion can be reduced by closing down the aperture, and that of the two chromatic aberrations only the longitudinal one can. Vignetting has several causes, which Levoy separates (slides 29–31): the natural cos⁡4θ\cos^4\theta fall-off; optical vignetting from multiple lens elements, especially at wide apertures (his slide shows the same lens at f/1.4 and f/5.6); mechanical vignetting from add-ons such as lens hoods; and pixel vignetting inside the sensor. Image formation calls the blocking of rays by the elements of a compound lens mechanical vignetting, where Levoy’s slide calls it optical, and adds that it shrinks when the aperture is reduced. Levoy (slide 31) notes that vignetting also affects the bokeh of out-of-focus features.

The shape of out-of-focus blur

Because the defocus disc is a scaled image of the aperture, a non-circular iris gives non-circular blur. Levoy (Optics I, slide 73) describes “bokeh”, the appearance of small out-of-focus features in a photograph with shallow depth of field, as determined by the boundary of the aperture, and shows (slide 75) a student’s misfocused photograph of Christmas lights taken through a heart-shaped mask in front of the lens. Image deblurring uses the same fact when it models the defocus point spread function as the image of the aperture.

The trade-off

Defocus blur shrinks as 1/N1/N and diffraction blur grows as NN, so for a point at a given distance from the focus plane there is an f-number that minimizes the combined blur. Exposure states the trade-off in words: stopping down one stop shrinks defocus by 2\sqrt{2} and halves the light, until diffraction limits the gain in sharpness. A rough estimate of where the balance lies (our derivation) adds the two blur radii in quadrature. A uniform disc of diameter cc holds half its energy within radius c/(22)c/(2\sqrt{2}), and the Airy pattern holds half within about 0.535 λNw0.535\,\lambda N_w (the example’s in-focus rows give this constant: at f/8, λNw=0.55×8×1.0256=4.513\lambda N_w = 0.55 \times 8 \times 1.0256 = 4.513 µm, and the printed 2.4136 µm is 0.5348 λNw0.5348\,\lambda N_w). Writing c=a/Nc = a/N, the quadrature sum (a/(22N))2+(0.535λNw)2(a/(2\sqrt{2}N))^2 + (0.535\lambda N_w)^2 is smallest at

N∗≈a/(22)0.535 λ Nw/N,N^* \approx \sqrt{\frac{a/(2\sqrt{2})}{0.535\,\lambda\, N_w/N}} ,

which grows with the square root of the defocus constant a=cNa = cN. The estimate ignores that the two blurs combine by convolution, not by adding radii, and that different measures of blur weigh the two shapes differently; the example computes the actual combination.

Examples

Defocus against diffraction across the f-stop sequence

The script computes the blur of a point imaged by an ideal 50 mm thin lens focused at 2 m, for every marked full stop from f/1.4 to f/22, at three object distances: 1.9 m (100 mm in front of the focus plane), 2.0 m (in focus) and 2.4 m (400 mm behind). The light is monochromatic, λ=0.55\lambda = 0.55 µm, and incoherent. The point spread function is the convolution of three blurs:

  • the defocus disc of diameter cc from the formula above;
  • the Airy pattern of the aperture, entered through its transfer function, the diffraction-limited OTF of a circular pupil in the form ISETCam’s dlCore.m computes, with its cutoff d/(λzi)d/(\lambda z_i) taken from the image distance as in dlMTF.m, so that at 2 m it uses the working f-number 1.026N1.026N;
  • optionally, a square pixel of 6 µm pitch with 100% fill: Levoy (Optics I, slide 52) gives 6 µm, one pixel, as the typical circle of confusion of a high-end SLR, and that value is used here as a pitch.

The convolution is computed exactly in the frequency domain, as the product of the three transfer functions; the point spread function article derives the disc’s transfer function and the pixel’s. Because the diffraction term is zero above the cutoff, the blur is band-limited, and two measures of its size can be written as finite sums over a frequency grid with step 1/L1/L, L=1024L = 1024 µm, which equal integrals of the PSF repeated with period LL (our construction; L is more than six times the largest disc). The measures are:

  • the 50% encircled-energy radius (EE50): the radius of the circle that holds half the light;
  • the RMS radius within a window of radius WW, ∫∣x∣<W∣x∣2h / ∫∣x∣<Wh\sqrt{\int_{|x|<W} |x|^2 h \,/\, \int_{|x|<W} h}, for W=100W = 100 and 200 µm.

The window is needed (our derivation): the Airy pattern’s energy outside radius rr falls only as about 2λN/(π2r)2\lambda N/(\pi^2 r), so its second moment grows in proportion to the window and has no finite value over the whole plane. The plan therefore fixed two windows and prints both. The script also checks its components: the energy of the PSF is 1 (C0); the Airy pattern alone has the analytic encircled energy 1−J0(v)2−J1(v)21 - J_0(v)^2 - J_1(v)^2, v=πr/(λNw)v = \pi r/(\lambda N_w) (C1); an independent radial quadrature of the Hankel transforms, without periodization, reproduces the grid’s numbers for every optics-only case (C2); with the pixel, the in-focus f/1.4 blur, where the Airy pattern is much smaller than the pixel, is within 5% of the pixel’s own EE50, p/2π=2.3937p/\sqrt{2\pi} = 2.3937 µm (C3); and the RMS radius grows with the window everywhere (C4). Finally it tabulates the rounding of the marked f-numbers in stops and the working f-number at 1:1.

The two defocused depths were chosen at planning with the quadrature estimate above, which, with a=cN=67.5a = cN = 67.5 µm at 1.9 m and 213.7 µm at 2.4 m (the printed cc at f/1.4 times 1.4), puts the balance near f/8.9 and f/15.8, “so that the balance falls inside the sequence”, in the words of the plan; the example therefore illustrates the trade-off rather than testing whether it exists. The planned hypotheses were: (H1) at each defocused depth, with and without the pixel, and for each of the three measures, the minimizing f-number is neither f/1.4 nor f/22; (H1c) in focus, the minimum is at f/1.4 in every case; (H2) every marked f-number is within a sixth of a stop of 2 k\sqrt{2}^{\,k}; (H3) at 1:1 the three forms of the working f-number agree and equal 2N2N, and the Airy EE50 radius at f/8 doubles. The tolerances of the checks were set before the pilot from a planning script with the same grid and code. The script runs in about two minutes (96 to 117 s in three timed runs on a shared machine).

import os
os.environ["OPENBLAS_NUM_THREADS"] = os.environ["OMP_NUM_THREADS"] = "1"
import numpy as np
from scipy.special import j0, j1, jv
from scipy.optimize import brentq

# Units: lens distances in mm, image-plane lengths in um, spatial frequencies in cycles/um.
# Thin lens at z = 0, light towards +z, distances positive when real; m = -z_i/z_o.
f, z_f, lam, p = 50.0, 2000.0, 0.55, 6.0      # focal length, focus distance, wavelength, pixel pitch
s_f = f * z_f / (z_f - f)                      # sensor distance for focus at z_f (mm)
L = 1024.0                                     # period of the frequency grid (frequency step 1/L)
W1, W2 = 100.0, 200.0                          # windows for the RMS radius (um)
MARKED = [1.4, 2, 2.8, 4, 5.6, 8, 11, 16, 22]  # marked full stops; exact values are sqrt(2)**k
DEPTHS = [1900.0, 2000.0, 2400.0]              # object distances (mm); 2000 is in focus

def coc(z, N):                                 # thin-lens circle of confusion (um)
    return f ** 2 * abs(z - z_f) / (N * z * (z_f - f)) * 1e3

def otf_diff(rho, nu_c):                       # incoherent diffraction-limited OTF, circular pupil
    s = np.clip(rho / nu_c, 0, 1)
    return (2 / np.pi) * (np.arccos(s) - s * np.sqrt(1 - s ** 2))

def otf_disc(rho, c):                          # uniform disc of diameter c
    a = np.pi * c * rho
    out = np.ones_like(a)
    nz = a > 0
    out[nz] = 2 * j1(a[nz]) / a[nz]
    return out

class Grid:
    """OTF on the quadrant nu_x, nu_y >= 0 of a grid with step 1/L, inside the cutoff.
    Weighted sums over it are exact integrals of the PSF periodized with period L."""
    def __init__(self, N, c, pixel, s=s_f):
        d = f / N * 1e3                        # aperture diameter (um)
        self.nu_c = d / (lam * s * 1e3)        # cutoff uses the image distance s: 1/(lam N_w)
        dnu = 1 / L
        k = np.arange(int(np.floor(self.nu_c / dnu)) + 1)
        kx, ky = np.meshgrid(k, k, indexing="ij")
        nx, ny = kx * dnu, ky * dnu
        rho = np.hypot(nx, ny)
        m = rho < self.nu_c
        w = np.where(kx > 0, 2.0, 1.0) * np.where(ky > 0, 2.0, 1.0)
        H = otf_diff(rho, self.nu_c) * otf_disc(rho, c)
        if pixel:
            H = H * np.sinc(p * nx) * np.sinc(p * ny)
        self.rho, self.H, self.w = rho[m], H[m], w[m] * dnu ** 2
        self.npts = int(m.sum())
    def energy(self):                          # integral of the PSF over one period = H(0)
        return float(self.H[(self.rho == 0)][0])
    def ee(self, r):                           # encircled energy inside radius r
        x = 2 * np.pi * r * self.rho
        K = np.full_like(x, np.pi * r ** 2)
        nz = x > 0
        K[nz] = r * j1(x[nz]) / self.rho[nz]
        return float(np.sum(self.w * self.H * K))
    def m2(self, W):                           # integral of |x|^2 PSF inside radius W
        a = 2 * np.pi * self.rho
        G = np.full_like(a, np.pi * W ** 4 / 2)
        nz = a > 0
        G[nz] = 2 * np.pi * (W ** 3 * j1(a[nz] * W) / a[nz] - 2 * W ** 2 * jv(2, a[nz] * W) / a[nz] ** 2)
        return float(np.sum(self.w * self.H * G))
    def ee50(self, rmax):
        return brentq(lambda r: self.ee(r) - 0.5, 1e-3, rmax, xtol=1e-7)
    def rms(self, W):                          # RMS radius of the PSF inside radius W
        return np.sqrt(self.m2(W) / self.ee(W))

class Radial:
    """Independent check for radially symmetric optics (no pixel): Gauss-Legendre quadrature
    of the Hankel transforms, without periodization."""
    def __init__(self, N, c):
        d = f / N * 1e3
        self.nu_c = d / (lam * s_f * 1e3)
        n = int(20 * np.ceil(self.nu_c * (c + W2))) + 400
        x, wq = np.polynomial.legendre.leggauss(n)
        self.rho = (x + 1) / 2 * self.nu_c
        self.wq = wq / 2 * self.nu_c
        self.H = otf_diff(self.rho, self.nu_c) * otf_disc(self.rho, c)
    def ee(self, r):
        return float(2 * np.pi * r * np.sum(self.wq * self.H * j1(2 * np.pi * self.rho * r)))
    def ee50(self, rmax):
        return brentq(lambda r: self.ee(r) - 0.5, 1e-3, rmax, xtol=1e-7)
    def rms(self, W):
        h = min(1 / (16 * self.nu_c), W / 2000)
        r = np.arange(0, W + h / 2, h)
        prof = np.empty_like(r)
        for i in range(0, len(r), 256):        # PSF profile p(r) = 2 pi int H J0(2 pi rho r) rho drho
            rr = r[i:i + 256, None]
            prof[i:i + 256] = 2 * np.pi * np.sum(self.wq * self.H * self.rho * j0(2 * np.pi * self.rho * rr), axis=1)
        return np.sqrt(np.trapezoid(2 * np.pi * r ** 3 * prof, r) / np.trapezoid(2 * np.pi * r * prof, r))

v50 = brentq(lambda v: 1 - j0(v) ** 2 - j1(v) ** 2 - 0.5, 0.5, 3.0, xtol=1e-12)
def airy_ee50(N, s=s_f):                       # analytic: EE(v) = 1 - J0^2 - J1^2, v = pi r/(lam N_w)
    return v50 * lam * N * (s / f) / np.pi

# C0: data checks on the grids
cmax = max(coc(z, 1.4) for z in DEPTHS)
g14, g22 = Grid(1.4, coc(2400.0, 1.4), True), Grid(22, coc(2400.0, 22), True)
c0 = L / cmax >= 4 and abs(g14.energy() - 1) <= 1e-12 and abs(g22.energy() - 1) <= 1e-12
print(f"C0 L/largest disc {L / cmax:.2f}; energy f/1.4 {g14.energy():.12f}, f/22 {g22.energy():.12f}; "
      f"grid points {g14.npts}, {g22.npts}: {'held' if c0 else 'failed'}")

# Sweep: EE50 and windowed RMS radius against N, per depth, without and with the pixel
res = {}
for z in DEPTHS:
    for pixel in (False, True):
        print(f"\nz = {z:.0f} mm ({'in focus' if z == z_f else f'{z - z_f:+.0f} mm from focus'}), "
              f"{'optics + 6 um pixel' if pixel else 'optics only'}")
        print("  N     c um      1.22 lam N_w  EE50 um   RMS(100) um  RMS(200) um")
        rows = []
        for N in MARKED:
            c = coc(z, N)
            g = Grid(N, c, pixel)
            row = (g.ee50(150.0), g.rms(W1), g.rms(W2))
            rows.append(row)
            print(f"  {N:<5} {c:<9.3f} {1.22 * lam * N * s_f / f:<13.3f} "
                  f"{row[0]:<9.4f} {row[1]:<12.4f} {row[2]:.4f}")
        rows = np.array(rows)
        res[z, pixel] = rows
        best = [MARKED[i] for i in rows.argmin(axis=0)]
        print("  minimum at: EE50 f/{}, RMS(100) f/{}, RMS(200) f/{}".format(*best))

print("\nH1 interior minimum (defocused), H1c minimum at f/1.4 (in focus):")
for (z, pixel), rows in res.items():
    for j, name in enumerate(("EE50", "RMS(100)", "RMS(200)")):
        i = int(rows[:, j].argmin())
        if z == z_f:
            ok = i == 0
            tag = "H1c"
        else:
            ok = 0 < i < len(MARKED) - 1
            tag = "H1 "
        print(f"  {tag} z {z:.0f} {'pixel' if pixel else 'optics':<6} {name:<9} min f/{MARKED[i]:<4} "
              f"{'held' if ok else 'failed'}")

n4 = sum(int(np.sum(rows[:, 2] > rows[:, 1])) for rows in res.values())
print(f"C4 RMS(200) > RMS(100) in {n4} of {len(res) * len(MARKED)} conditions: "
      f"{'held' if n4 == len(res) * len(MARKED) else 'failed'}")

# C1: the Airy component (in focus, no pixel) against the analytic encircled energy
e1 = [abs(Grid(N, 0.0, False).ee50(50.0) - airy_ee50(N)) / airy_ee50(N) for N in MARKED]
print(f"\nC1 Airy EE50 grid vs analytic: max rel err {max(e1):.3e} (tol 2e-6): "
      f"{'held' if max(e1) <= 2e-6 else 'failed'}")

# C2: grid against the independent radial quadrature, optics only, 27 conditions
e2 = {"EE50": [], "RMS(100)": [], "RMS(200)": []}
for z in DEPTHS:
    for N in MARKED:
        c = coc(z, N)
        g, r = Grid(N, c, False), Radial(N, c)
        e2["EE50"].append(abs(g.ee50(150.0) - r.ee50(150.0)) / r.ee50(150.0))
        e2["RMS(100)"].append(abs(g.rms(W1) - r.rms(W1)) / r.rms(W1))
        e2["RMS(200)"].append(abs(g.rms(W2) - r.rms(W2)) / r.rms(W2))
for (k, v), tol in zip(e2.items(), (4e-6, 3e-3, 2e-2)):
    print(f"C2 {k:<9} grid vs radial: max rel err {max(v):.3e} (tol {tol:g}): "
          f"{'held' if max(v) <= tol else 'failed'}")

# C3: the pixel factor, f/1.4 in focus + pixel against the pixel-alone EE50 p/sqrt(2 pi)
box = p / np.sqrt(2 * np.pi)
e3 = abs(Grid(1.4, 0.0, True).ee50(50.0) - box) / box
print(f"C3 f/1.4 in focus + pixel EE50 vs pixel alone {box:.4f} um: rel diff {e3:.3e} (tol 0.05): "
      f"{'held' if e3 <= 0.05 else 'failed'}")

# H2: marked f-numbers against exact powers of sqrt(2), as exposure error in stops
print("\nH2 marked   exact sqrt(2)^k  error (stops)")
err = []
for k, Nm in enumerate(MARKED, start=1):
    Ne = np.sqrt(2) ** k
    err.append(2 * np.log2(Nm / Ne))
    print(f"   f/{Nm:<6} {Ne:<16.4f} {round(err[-1], 4) + 0.0:.4f}")
print(f"H2 max |error| {max(map(abs, err)):.4f} stop < 1/6: {'held' if max(map(abs, err)) < 1 / 6 else 'failed'}")

# H3: working f-number at 1:1 (object at 2f, image at 2f, m = -1)
N, m = 8.0, -1.0
s11 = f * (2 * f) / (2 * f - f)                # image distance for z_o = 2f
forms = {"Levoy (1+|M_T|)N": (1 + abs(m)) * N, "ISETCam N(1-m)": N * (1 - m),
         "thin lens z_i/d": s11 / (f / N)}
ok3a = all(abs(v - 2 * N) / (2 * N) <= 1e-12 for v in forms.values())
print("\nH3 N_w at m = -1, N = 8: " + ", ".join(f"{k} {v:.6f}" for k, v in forms.items())
      + f": {'held' if ok3a else 'failed'}")
r11, rinf = Grid(N, 0.0, False, s=s11).ee50(50.0), Grid(N, 0.0, False, s=f).ee50(50.0)
ok3b = abs(r11 / rinf / 2 - 1) <= 4e-6
print(f"H3 EE50 at 1:1 {r11:.4f} um, at infinity {rinf:.4f} um, ratio {r11 / rinf:.8f}: "
      f"{'held' if ok3b else 'failed'}")
print(f"   Levoy's MP-E 65 example: N = 2.8, |M_T| = 5 -> N' = {(1 + 5) * 2.8:.1f}")

Output (NumPy 2.3.5, SciPy 1.16.3):

C0 L/largest disc 6.71; energy f/1.4 1.000000000000, f/22 1.000000000000; grid points 1321743, 5433: held

z = 1900 mm (-100 mm from focus), optics only
  N     c um      1.22 lam N_w  EE50 um   RMS(100) um  RMS(200) um
  1.4   48.197    0.963         17.1136   17.4883      17.9628
  2     33.738    1.376         12.0339   12.8388      13.7348
  2.8   24.099    1.927         8.6713    10.2214      11.7334
  4     16.869    2.753         6.1902    9.0220       11.3451
  5.6   12.049    3.854         4.6212    9.0867       12.1957
  8     8.435     5.506         3.8203    10.0612      13.9917
  11    6.134     7.570         3.9009    11.5071      16.1900
  16    4.217     11.011        5.0143    13.8036      19.4605
  22    3.067     15.141        6.7090    16.2402      22.8582
  minimum at: EE50 f/8, RMS(100) f/4, RMS(200) f/4

z = 1900 mm (-100 mm from focus), optics + 6 um pixel
  N     c um      1.22 lam N_w  EE50 um   RMS(100) um  RMS(200) um
  1.4   48.197    0.963         17.1154   17.6587      18.1289
  2     33.738    1.376         12.0401   13.0697      13.9512
  2.8   24.099    1.927         8.6999    10.5097      11.9858
  4     16.869    2.753         6.3469    9.3467       11.6057
  5.6   12.049    3.854         5.0325    9.4081       12.4381
  8     8.435     5.506         4.4275    10.3539      14.2022
  11    6.134     7.570         4.5444    11.7534      16.3718
  16    4.217     11.011        5.5105    13.9802      19.5975
  22    3.067     15.141        7.0746    16.3758      22.9629
  minimum at: EE50 f/8, RMS(100) f/4, RMS(200) f/4

z = 2000 mm (in focus), optics only
  N     c um      1.22 lam N_w  EE50 um   RMS(100) um  RMS(200) um
  1.4   0.000     0.963         0.4224    4.0061       5.7087
  2     0.000     1.376         0.6034    4.7892       6.8239
  2.8   0.000     1.927         0.8448    5.6698       8.0728
  4     0.000     2.753         1.2068    6.7795       9.6508
  5.6   0.000     3.854         1.6895    8.0238       11.4252
  8     0.000     5.506         2.4136    9.6347       13.6611
  11    0.000     7.570         3.3187    11.3359      16.0482
  16    0.000     11.011        4.8272    13.7443      19.4124
  22    0.000     15.141        6.6374    16.2150      22.8385
  minimum at: EE50 f/1.4, RMS(100) f/1.4, RMS(200) f/1.4

z = 2000 mm (in focus), optics + 6 um pixel
  N     c um      1.22 lam N_w  EE50 um   RMS(100) um  RMS(200) um
  1.4   0.000     0.963         2.4757    4.6959       6.2115
  2     0.000     1.376         2.5172    5.3801       7.2500
  2.8   0.000     1.927         2.5859    6.1768       8.4390
  4     0.000     2.753         2.7206    7.2107       9.9611
  5.6   0.000     3.854         2.9569    8.3974       11.6891
  8     0.000     5.506         3.3972    9.9184       13.8887
  11    0.000     7.570         4.0552    11.5583      16.2293
  16    0.000     11.011        5.3343    13.9111      19.5452
  22    0.000     15.141        7.0048    16.3477      22.9415
  minimum at: EE50 f/1.4, RMS(100) f/1.4, RMS(200) f/1.4

z = 2400 mm (+400 mm from focus), optics only
  N     c um      1.22 lam N_w  EE50 um   RMS(100) um  RMS(200) um
  1.4   152.625   0.963         54.0338   54.0391      54.2333
  2     106.838   1.376         37.8770   38.0157      38.3564
  2.8   76.313    1.927         27.1274   27.5146      28.1365
  4     53.419    2.753         19.0989   20.0157      21.1870
  5.6   38.156    3.854         13.7946   15.6546      17.6605
  8     26.709    5.506         9.9000    13.4391      16.5998
  11    19.425    7.570         7.6637    13.1921      17.4415
  16    13.355    11.011        6.6837    14.4275      19.9330
  22    9.713     15.141        7.3653    16.4841      23.0459
  minimum at: EE50 f/16, RMS(100) f/11, RMS(200) f/8

z = 2400 mm (+400 mm from focus), optics + 6 um pixel
  N     c um      1.22 lam N_w  EE50 um   RMS(100) um  RMS(200) um
  1.4   152.625   0.963         54.0339   54.0942      54.2885
  2     106.838   1.376         37.8775   38.0941      38.4344
  2.8   76.313    1.927         27.1288   27.6228      28.2427
  4     53.419    2.753         19.1033   20.1641      21.3277
  5.6   38.156    3.854         13.8100   15.8434      17.8289
  8     26.709    5.506         9.9914    13.6583      16.7784
  11    19.425    7.570         7.9194    13.4131      17.6110
  16    13.355    11.011        7.0481    14.6339      20.0832
  22    9.713     15.141        7.7093    16.6399      23.1625
  minimum at: EE50 f/16, RMS(100) f/11, RMS(200) f/8

H1 interior minimum (defocused), H1c minimum at f/1.4 (in focus):
  H1  z 1900 optics EE50      min f/8    held
  H1  z 1900 optics RMS(100)  min f/4    held
  H1  z 1900 optics RMS(200)  min f/4    held
  H1  z 1900 pixel  EE50      min f/8    held
  H1  z 1900 pixel  RMS(100)  min f/4    held
  H1  z 1900 pixel  RMS(200)  min f/4    held
  H1c z 2000 optics EE50      min f/1.4  held
  H1c z 2000 optics RMS(100)  min f/1.4  held
  H1c z 2000 optics RMS(200)  min f/1.4  held
  H1c z 2000 pixel  EE50      min f/1.4  held
  H1c z 2000 pixel  RMS(100)  min f/1.4  held
  H1c z 2000 pixel  RMS(200)  min f/1.4  held
  H1  z 2400 optics EE50      min f/16   held
  H1  z 2400 optics RMS(100)  min f/11   held
  H1  z 2400 optics RMS(200)  min f/8    held
  H1  z 2400 pixel  EE50      min f/16   held
  H1  z 2400 pixel  RMS(100)  min f/11   held
  H1  z 2400 pixel  RMS(200)  min f/8    held
C4 RMS(200) > RMS(100) in 54 of 54 conditions: held

C1 Airy EE50 grid vs analytic: max rel err 7.151e-07 (tol 2e-6): held
C2 EE50      grid vs radial: max rel err 1.978e-06 (tol 4e-06): held
C2 RMS(100)  grid vs radial: max rel err 1.012e-03 (tol 0.003): held
C2 RMS(200)  grid vs radial: max rel err 8.490e-03 (tol 0.02): held
C3 f/1.4 in focus + pixel EE50 vs pixel alone 2.3937 um: rel diff 3.430e-02 (tol 0.05): held

H2 marked   exact sqrt(2)^k  error (stops)
   f/1.4    1.4142           -0.0291
   f/2      2.0000           0.0000
   f/2.8    2.8284           -0.0291
   f/4      4.0000           0.0000
   f/5.6    5.6569           -0.0291
   f/8      8.0000           0.0000
   f/11     11.3137          -0.0811
   f/16     16.0000          0.0000
   f/22     22.6274          -0.0811
H2 max |error| 0.0811 stop < 1/6: held

H3 N_w at m = -1, N = 8: Levoy (1+|M_T|)N 16.000000, ISETCam N(1-m) 16.000000, thin lens z_i/d 16.000000: held
H3 EE50 at 1:1 4.7065 um, at infinity 2.3533 um, ratio 1.99999958: held
   Levoy's MP-E 65 example: N = 2.8, |M_T| = 5 -> N' = 16.8

Every check held. The data check C0 held: the energy of the PSF is 1 to twelve decimals and the grid period is 6.71 times the largest disc. The Airy check C1 held, with the grid’s EE50 within a relative 7.2×10−77.2 \times 10^{-7} of the analytic value at every f-number. The radial cross-check C2 held for EE50 and for both RMS windows; the RMS radii agree less closely, to 8.5×10−38.5 \times 10^{-3} at the 200 µm window, which in our reading is the periodized grid folding the slowly decaying Airy tail back into the window, the same tail that makes the window necessary. The pixel check C3 held, with the in-focus f/1.4 blur 3.4% above the pixel’s own EE50, and the window check C4 held in all 54 conditions.

The trade-off hypothesis H1 held in all twelve cases. At 1.9 m the EE50 radius falls from 17.11 µm at f/1.4 to 3.82 µm at f/8 and rises again to 6.71 µm at f/22; at 2.4 m it falls from 54.03 µm to 6.68 µm at f/16, eight times smaller, before rising at f/22. The minimum is shallow: at 1.9 m, f/11 is only 0.081 µm worse than f/8. At the EE50 minimum the defocus disc and the Airy disc are of the same order, 8.4 µm against an Airy diameter of 11.0 µm at 1.9 m and f/8, as the quadrature estimate assumed. The control H1c held: in focus there is no defocus to trade, and every measure is smallest at f/1.4, where the Airy EE50 radius is only 0.42 µm.

Where the minimum falls depends on the measure. The windowed RMS radius puts it at f/4 for 1.9 m, not f/8, and at f/11 or f/8 for 2.4 m, not f/16; in every defocused case the RMS minimum is at the same or a wider aperture than the EE50 minimum, and the wider window moves it further or leaves it. In our reading, the RMS radius weighs the faint outer rings of the Airy pattern by the square of their distance, so it penalizes diffraction more than the encircled energy does: in focus at f/1.4 the RMS radius in the 100 µm window is 9.5 times the EE50 radius, and doubling the window raises it by a factor of 1.43 at f/1.4 and 1.41 at f/22, close to the 2\sqrt{2} that a second moment growing in proportion to the window would give. A statement such as “this lens is sharpest at f/8” therefore needs both a defocus and a definition of sharpness. The 6 µm pixel changes the numbers little where the optical blur is large and dominates where it is small (2.48 µm against 0.42 µm in focus at f/1.4), but it moved no minimum in this set-up.

H2 held: the marked values f/1.4, f/2.8 and f/5.6 differ from the exact powers of 2\sqrt{2} by 0.029 stop, and f/11 and f/22 by 0.081 stop, below the sixth of a stop the plan allowed; the even powers are exact. The errors are negative because each rounded label is smaller than the exact value it stands for. H3 held: the three forms of the working f-number give f/16 for an f/8 lens at 1:1, and the Airy EE50 radius doubles, from 2.3533 µm at infinity focus to 4.7065 µm, a ratio of 2 to within 5×10−75 \times 10^{-7}, which follows from the scaling of the model. For Levoy’s MP-E 65 example the rule gives 16.8 where the slide writes f/16.

Process note. The plan for this example listed eleven departures from the batch plan’s description before the pilot: (1) the RMS radius is computed inside two stated windows, because the Airy pattern’s second moment diverges; (2) “integrated over pixels” is implemented as the pixel-aperture PSF, a 6 µm photosite convolved with the lens blur through its transfer function, with results printed with and without it, rather than as a sampled pixel image whose encircled energy would depend on sub-pixel position; (3) the convolution is computed exactly in the frequency domain instead of by sampling and convolving kernels, with the radial route as a check; (4) checks C0–C4 were added; (5) the in-focus control H1c was added; (6) diffraction uses the image distance (the working f-number) instead of 1.22λN1.22\lambda N; (7) the stop sequence is fixed as f/1.4–f/22; (8) the two defocused depths were chosen with the quadrature estimate, as stated above; (9) H3 is computed as three forms of the working f-number and a ratio of EE50 radii, and Levoy’s macro example is printed; (10) the lens, wavelength and pixel values (50 mm, 0.55 µm, 6 µm) were chosen so as not to repeat image formation’s 8 mm, f/2.8, 2 m set-up; (11) there is no library cross-check, since SciPy and scikit-image have no PSF or encircled-energy routine. Two planning scripts ran before the plan was written, and so before the pilot: one computed the derivation constants used to choose the depths, and one computed the check errors from which the tolerances were set, without printing any value of the sweep. After the pilot the editor approved two print-format repairs and nothing else: the stop errors of the exact values printed as −0.0000 and now print as 0.0000, and the pixel rows of the H1 summary were padded by one character to align. No value, measure or check changed.

Common Misconceptions

  • “A larger f-number is a larger aperture.” The f-number is a ratio with the diameter in the denominator: f/16 is a smaller opening than f/2, by a factor of 8 in diameter and 64 in area.
  • “The f-number is the size of the hole.” It is the size relative to the focal length, and that is what makes it useful: the same f-number gives the same irradiance on any lens (Levoy, Image Formation, slide 54), while the physical diameter at f/2 is 25 mm on a 50 mm lens and 50 mm on a 100 mm lens.
  • “Zooming out at a fixed f-number gathers more light.” At a fixed f-number the lens shrinks the physical aperture as the focal length falls, so it does not; only a fixed diameter would (Levoy’s note on the same slide).
  • “Marked f-numbers are exact.” They are rounded powers of 2\sqrt{2}; the example shows that f/11 and f/22 are off by 0.08 stop and f/1.4, f/2.8 and f/5.6 by 0.03.
  • “The f-number on the lens applies at every focus distance.” It is defined at infinity focus. At magnification mm the cone to the sensor corresponds to (1+∣m∣)N(1+|m|)N, twice the marked value at 1:1, for both exposure and diffraction.
  • “1.22λN1.22\lambda N is the size of the Airy disc.” It is the radius to the first dark ring; ISETCam’s airyDisk.m returns the radius unless asked for the diameter, and the radius that holds half the light is smaller, about 0.535λN0.535\lambda N.
  • “A smaller aperture always gives a sharper image” (image formation lists this too). Stopping down shrinks defocus but enlarges diffraction; in the example, f/22 is blurrier than f/16 even 400 mm behind the focus plane, and in focus the widest aperture is sharpest.
  • “Every lens has one sharpest aperture.” Even for an ideal lens the best f-number depends on how far the subject is from the focus plane and on the definition of blur: in the example it is f/8 or f/4 at one depth and f/16, f/11 or f/8 at another. For real lenses aberrations, which stopping down reduces, move it again.

Where It Is Used

The aperture is one of the three exposure settings, and exposure covers how it trades against exposure time and gain. Depth of field derives the near and far limits that the f-number scales, and the thin lens model the circle of confusion behind them. Image formation uses the f-number in its irradiance formula and its defocus and diffraction blur, and the point spread function article turns the aperture into the cutoff frequency of the optical transfer function. Optical microscopy describes the same limits through numerical aperture, with the Rayleigh, Abbe and Sparrow criteria. Vision system design lists the aperture among a system’s optical choices, as the setting for light, depth of field and diffraction, and digital camera places the aperture in the chain from lens to stored image. Image sensor measurements under EMVA 1288 fix the illumination geometry at f-number 8. Image deblurring inverts the defocus blur whose shape the aperture sets, and depth from defocus, which depth estimation mentions, uses a wide aperture’s shallow depth of field to measure range.

Related

  • Image Formation

    How light leaving a scene becomes an array of pixel values, through illumination and reflectance, the lens, the sensor and its colour filters, sampling and quantization, and the camera's own processing.

  • Depth of Field

    The range of object distances that a focused lens images with blur no larger than an acceptable circle of confusion, its exact near and far limits under the thin-lens model, the hyperfocal distance, Levoy's approximations and how depth of field scales with f-number, distance and focal length.

  • Point Spread Function

    The image a camera forms of a single point of light, how diffraction, defocus, aberrations and the pixel aperture combine into it, its Fourier transform the optical transfer function and its magnitude the MTF, and how the MTF is measured from a slanted edge.

  • Optical Microscopy

    Light microscopy as an imaging sensor, covering the optical path and Köhler illumination, objectives and numerical aperture, the diffraction-limited point-spread function and the Abbe, Rayleigh and Sparrow resolution criteria, brightfield, darkfield, phase contrast and differential interference contrast, cameras and Nyquist sampling, and the artifacts that image analysis has to handle.

  • Digital Camera

    The camera as an imaging system, from lens, shutter and sensor to the image signal processor that demosaics, white-balances, colour-corrects, tone-maps and compresses its output; RAW against processed images, metadata, machine-vision interfaces, camera classes, and where processing breaks the assumptions of vision methods.

  • Designing a Computer Vision System

    How a working vision system is designed from its requirements, through the choice of sensor, optics, lighting, compute and model, to the data it is trained on, its validation in the field and its maintenance once deployed, with the requirement arithmetic for a measurement station worked through in code.

References

  1. Levoy, M. (2013). Image Formation. Lecture slides, CS 178: Digital Photography, Stanford University, Spring 2013 (cited by slide number).
  2. Levoy, M. (2013). Optics I: Lenses and Apertures. Lecture slides, CS 178: Digital Photography, Stanford University, Spring 2013 (cited by slide number).
  3. Levoy, M. (2013). Optics II: Practical Photographic Lenses. Lecture slides, CS 178: Digital Photography, Stanford University, Spring 2013 (cited by slide number).
  4. Torralba, A., Isola, P. & Freeman, W. T. (2024). Foundations of Computer Vision. MIT Press. Chapter 6, Lenses, §6.3.1 (read in the online edition).
  5. ISETCam (Stanford Center for Image Systems Engineering). opticalimage/optics/opticsGet.m, at commit 3e0253421752eb72f2d1353327dffd0d433abdaf (MIT licence; comments and code read).
  6. ISETCam (Stanford Center for Image Systems Engineering). airyDisk.m, at commit 3e0253421752eb72f2d1353327dffd0d433abdaf (MIT licence; code read).
  7. ISETCam (Stanford Center for Image Systems Engineering). dlCore.m and dlMTF.m, at commit 3e0253421752eb72f2d1353327dffd0d433abdaf (MIT licence; code and comments read).
  8. European Machine Vision Association (2021). EMVA Standard 1288: Standard for Characterization of Image Sensors and Cameras, Release 4.0 Linear.