BookNotesSlidesP-sets Syllabusdraft · v0.2.49.1
◀▲⌂▶
💬Comments welcome. To leave a note, select any text and click the note / highlight button that pops up — or open the panel with the tab at the top-right (‹). Notes are visible only inside our private review group.

17.2 Camera response and radiance calibration⧉

Merging multiple exposures requires the conversion of pixel values into the same meaningful units proportional to scene radiance. Calibration establishes that relationship. When working with raw files, where the pixel values are linearly related to radiance, only pairwise ratios are needed. In the general case, the non-linear response curve from radiance to pixels must be calibrated. The unknown scene can help calibrate the camera because each scene point appears at several exposures. We assume the images in a bracket are pixel-aligned and the scene does not contain movement. The model $I_i=f(k_iL)$ assumes a fixed pointwise response shared across frames, where $k_i$ characterizes the exposure for frame $i$. In the general case $f$ must be calibrated. We assume $I_i$ values have been black-level corrected (recall that some cameras add a constant offset to measure the negative component of readout noise, Chapter 2.8, Noise, signal-to-noise ratio and dynamic range). Throughout, $I_{p,i}$ is the value of pixel $p$ in frame $i$, $L_p$ the radiance at that pixel, and $w(I)$ a reliability weight that is zero for clipped values and small near the noise floor.

17.2.1 The linear case: recovering the exposure ratios⧉

In the linear case, $f$ is simply a global multiplication factor and the problem boils down to recovering the $k_i$ exposure factors up to a multiplicative factor. But even for linear RAW files, linearity breaks down for dark values, and especially for bright ones. We call a pixel reliable if it is not too dark and not too saturated (between $\epsilon_0$ and $1-\epsilon_1$ in normalized pixel values). For exposure ratio estimation, the values of the thresholds are not critical and anything significantly above the read-noise level will do.

For linear, black-level-corrected reliable observations, $I_{p,i}=k_iL_p$ in the noiseless unsaturated model. At a pixel that is reliable in two images, the radiance cancels:

$$ \frac{I_{p,i}}{I_{p,j}} = \frac{k_i\,L_p}{k_j\,L_p} = \frac{k_i}{k_j}, $$

which is the same number at every good pixel, if linearity holds. Estimate it robustly with the median over the pixels where both frames are reliable,

$$ \frac{k_i}{k_j} = \operatorname*{median}_{p:\,w(I_{p,i})>0,\ w(I_{p,j})>0}\!\left(\frac{I_{p,i}}{I_{p,j}}\right). $$

Pairwise ratios recover relative exposure factors, but small denominators and noisy correspondences can bias them. Use many reliable pixels and validate residuals; jointly fitting exposure scales can avoid drift from chaining. Metadata supplies a useful initial estimate and can be accurate enough for some cameras. The image only determines relative radiance without an absolute calibration.

To avoid statistics over ratios, which is always dangerous when denominators can be close to zero, you can use a linear regression where you fit the scalar $\frac{k_i}{k_j}$ according to the model

$$ I_{p,i} = \frac{k_i}{k_j} I_{p,j} $$

which naturally weights the more reliable evidence from larger pixel values higher. But in practice, the median works fine, especially if you exclude ratios with low denominators.

If pixels exhibit inconsistent values between normalized frames, check black level, response, timing, illumination and registration before merging.

Validate exposure factors

Metadata records nominal capture settings. Check them against unsaturated, registered image regions when radiometric accuracy matters (Burggraaff et al. 2019). Pixel-based calibration also has failure modes: motion, flickering light, noise and local processing can make a single global ratio inappropriate.

17.2.2 The non-linear case: recovering the curve⧉

In the non-linear case, we need to recover the response curve. Real cameras (and film, and JPEG) apply a non-linear response $f$, such as a gamma, a tone curve, or a film characteristic, including the beauty curve that gives a camera its look (Why scene-linear looks dull, in Part 8, Basic image processing and ISP). Then $I_i = f(k_i L)$, and you must recover $f$ (equivalently its log-inverse $g = \ln f^{-1}$) before you can merge. The trick of Debevec and Malik (1997) is that a pixel imaged at several exposures gives several $(I_{p,i}, t_i)$ pairs that all constrain the same radiance $L_p$, and that over-determination pins down the curve. Here aperture and calibrated gain are fixed, so $k_i$ is the shutter time $t_i$ times a common scale, which is absorbed into $L_p$. Working in the log domain, each observation says

$$ g(I_{p,i}) = \ln L_p + \ln t_i. $$

The unknowns are the curve $g(\cdot)$, one value per possible pixel level, say 256 of them, and one $\ln L_p$ per pixel. Stack one such equation per pixel per exposure and you have a linear least-squares system in $g$ and the $\ln L_p$'s, solved jointly, exactly the kind of inverse problem of Chapter 6.7, Image formation as a linear system. Two riders make it well-behaved: a smoothness penalty on $g''$ (a real response curve is smooth, not jagged), and the same reliability weight $w(I)$ we will use in the merge, down-weighting samples near the clip and near the noise floor. The recovered curve is fixed only up to one additive constant, again the global scale (Figure 17.2.2).

With sample pixel $p$ and frame $i$, one explicit fit is

$$\min_{g,\ell}\sum_{p,i}w(I_{p,i})^2[g(I_{p,i})-\ell_p-\ln t_i]^2+\lambda\sum_{I} w(I)^2[\Delta^2g(I)]^2,\qquad g(I_{\rm mid})=0.$$

Here $\ell_p=\ln L_p$, the second sum runs over the possible pixel values $I$, $\Delta^2$ is a discrete second difference, and $I_{\rm mid}$ is a mid-range value whose $g$ is fixed. Fixing one curve value removes the additive-scale ambiguity. The written weights multiply residuals before squaring; using weights outside the square is a different convention. Smoothness alone does not enforce a monotone response. Check the recovered curve and held-out exposure residuals.

The system is small. Each $\ell_p$ appears only in its own sample's rows, so it can be eliminated exactly, leaving a symmetric 255 by 255 system for $g$ per channel that solves in milliseconds (Figure 17.2.1). Run it on camera JPEGs and try three things. Set the weight to flat, and the clipped samples at 0 and 255 bend the ends of the curve. Lower $\lambda$ and the curve follows the noise; raise it and it can no longer turn at the toe. Merge with an assumed gamma of 2.2 instead of the recovered curve, and the frames of a bracket disagree about a pixel's radiance by about a stop, against a few tenths of a stop with the curve.

fig-debevec-malik-demo
Figure 17.2.1. Debevec and Malik, and Mitsunaga and Nayar, calibration on camera JPEGs (interactive). Top: a bracket of three JPEGs with shutter time and ISO from EXIF, and the sample pixels, drawn at random or one per band of intensity from flat neighborhoods. Left: the recovered log-inverse response $g(I)$ for R, G and B, solved per channel by least squares with the smoothness weight $\lambda$ and the weighting $w(I)$ chosen below the figure; each sample's observations sit at $\ln L_p + \ln t_i$, and the dashed curve is a gamma of 2.2 anchored at the same code value. Right: the bracket merged with the recovered curve, or with the gamma for comparison, into a radiance map shown as false-color log luminance or tone-mapped with global Reinhard; drag the probes A and B to read a radiance ratio. The readout gives the fit residual and how far the frames still disagree after the merge. The method control switches to Mitsunaga and Nayar's self-calibration Mitsunaga & Nayar 1999: a polynomial of degree $D$ (set by hand, or chosen on held-out pixels) fitted together with the exposure ratios, which can be started off EXIF; the panel at top right then plots the ratios and the error at each iteration, and the curve is drawn as $\ln f^{-1}(I/255) - \ln f^{-1}(128/255)$ so it shares the axes of $g$: the unknown scale of $f^{-1}$, which $f^{-1}(1) = 1$ fixes, is the same unknown as the constant in $g$, which $g(128) = 0$ fixes. Either method's curve can be overlaid on the other's. Where the camera changed ISO within a bracket, $t_i$ is shutter time times ISO/100. You can load your own bracket; exposure times are read from EXIF and can be edited. Photographs by Frédo Durand, the camera's own JPEGs (Sony α1 II and α7R V).

Mitsunaga and Nayar (1999) assume even less. They model the response as a low-order polynomial and recover it, together with the unknown exposure ratios, by radiometric self-calibration, so you need not even trust the EXIF exposure ratios. The spirit is identical: pixels seen at multiple exposures over-determine the curve, so fit a smooth response to them. (Mann & Picard 1995's "comparametric," or Wyckoff, work is the earlier multiple-exposure precursor to both.)

The figure runs their method as a second option on the same samples. Their model is the inverse response itself rather than its logarithm $g$: a polynomial of degree $D$, $f^{-1}(I) = \sum_{n=0}^{D} c_n I^n$, on pixel values normalized to $[0,1]$, with $f^{-1}(1) = 1$. Two steps alternate: with the exposure ratios $k_i/k_{i+1}$ of consecutive frames fixed, every pixel seen in both gives a linear equation $f^{-1}(I_{p,i}) = (k_i/k_{i+1})\, f^{-1}(I_{p,i+1})$ in the $c_n$, solved by least squares; with the curve fixed, each ratio is re-estimated as the average of $f^{-1}(I_{p,i})/f^{-1}(I_{p,i+1})$. Start the ratios a stop off EXIF, alternately up and down, and the iteration brings them back to within a few tenths of a stop. Start them all off the same way and it cannot. If $f^{-1}$ and the ratios $k_i/k_{i+1}$ explain the images, so do $(f^{-1})^{\gamma}$ and $(k_i/k_{i+1})^{\gamma}$ for any exponent $\gamma$, so the pictures fix the ratios only relative to one another, as Grossberg and Nayar showed Grossberg & Nayar 2003, and the polynomial model pins $\gamma$ only weakly. Run exactly as published on these JPEGs, the iteration drifts along that family, so the figure holds the bracket's total span in stops at its starting value, which removes that one direction and nothing else.

Joint fitting uses many observations while imposing a smooth response. It still requires sufficient exposure overlap and a suitable observation model. Debevec–Malik's conventional intensity weights are reliability heuristics, not automatically the inverse variances of log-transformed noise.

The log-domain estimate in Debevec–Malik is a weighted average of log exposures. Exponentiating it gives a geometric mean of radiance estimates, which differs from a linear-light arithmetic mean. Both can be useful under their respective error models; neither justifies averaging gamma-encoded values as radiance.

fig-response-curve-debevec
Figure 17.2.2. The recovered camera response (Debevec–Malik). Left: the camera's non-linear response curve $I = f(kL)$ (pixel value against log exposure), an S-shaped film/JPEG curve. Right: its log-inverse $g(I) = \ln(kL)$, recovered by least squares from pixels seen at many exposures and straightened into log-radiance. Faint clusters of sample points (one cluster per pixel, spread across exposures and shifted by $\ln t_i$) are shown pinning the curve down, up to one global vertical offset; a smoothness penalty keeps $g$ from wiggling between samples.

17.2.3 The pipeline end to end⧉

With calibration and combination both in hand, run the whole pipeline end to end, once, on one bracket: alignment, response recovery, merge, and (a preview of) tone mapping in a single interactive (Figure 17.2.3).

fig-hdr-pipeline
Figure 17.2.3. The HDR pipeline, end to end (interactive). A hand-held bracket is taken through every classical stage on one screen: (1) the differently-exposed frames, each shifted a little by hand tremor; (2) Ward's median-threshold-bitmap alignment, which thresholds each frame at its median into an exposure-invariant 1-bit image and slides it coarse-to-fine to recover the integer shift; (3) Debevec–Malik response recovery, with the full scatter of (value, log-exposure) samples from every frame falling onto the single recovered curve $g$; (4) the merge into a radiance map, shown in false color on a log scale; and (5) tone mapping to the display, switchable between linear (clip), Reinhard global Reinhard et al. 2002, bilateral-grid Chen et al. 2007, and fast local Laplacian Aubry et al. 2014 so the global-vs-local difference is visible in the windows and shadows. Built-in scenes are real radiance maps (Debevec's memorial and vine sunset) from which a realistic bracket is synthesized; you can also upload your own exposures. The tone-mapping stage is a preview; its operators are developed in Part 18, Tone mapping and display and Chapter 10.1, Bilateral filtering.

17.2.4 From exposure to photometry⧉

A shutter time, aperture and ISO setting can describe many scenes, including a lens cap left on. They establish a luminance only when connected to a known meter reading or an absolute camera calibration. The relative response calibration above also leaves an unknown scale.

For a specified reflected-light meter, at its recommended uncompensated exposure, the metering relation is

$$\frac{N^2}{t}=\frac{L_v S}{K},\qquad L_v=\frac{KN^2}{tS}.$$

Here $L_v$ is the luminance represented by the meter reading, $S$ the arithmetic exposure index and $K$ its calibration constant in the stated unit convention. The expression describes the metered patch or weighting, not every pixel. If compensation $c_e$ adds stops at fixed ISO by increasing $t/N^2$, recovering the original meter-equivalent luminance requires multiplying the right-hand estimate by $2^{c_e}$. Manual settings unrelated to the meter support no such inference.

For an illustrative calibrated reading with $K=12.5$, f/2.8, 1/100 s, ISO 400 and zero compensation, $L_v=24.5$ cd/m². That is a meter-equivalent luminance under those assumptions. It is not an absolute estimate for an arbitrary photograph with those EXIF settings.

For a distant uniform patch, an idealized on-axis lens model relates that luminance to image-plane illuminance:

$$E_v\approx\frac{\pi\tau}{4N^2}L_v,\qquad H_v=E_vt.$$

With transmission $\tau=0.9$, the example gives $H_v\approx0.0221$ lux·s. Off-axis pupil geometry, vignetting, flare and close-focus effects require more than this on-axis approximation. Calibrate black level, gain, linearity and spatial response for the actual camera and lens when absolute values matter Burggraaff et al. 2019.

A luminous exposure is weighted by human spectral sensitivity. It does not determine photon count without the spectrum. Given image-plane spectral radiant exposure $H_{e,\lambda}$, the expected detected electrons in a uniform photosite of area $A_p$ are

$$\mu_e=A_p\int H_{e,\lambda}(\lambda)\frac{\lambda}{hc}\eta(\lambda)\,d\lambda.$$

The factor $\lambda/(hc)$ converts energy to photons; quantum efficiency $\eta$ converts photons to expected electrons. Use wavelength units consistent with the spectral density. Replacing the spectrum by one average wavelength and one luminous efficacy is an additional approximation, not a consequence of the exposure settings.

To see the scale, complete the example under stated assumptions. Suppose the metered patch reflects broadband daylight whose luminous efficacy is about 300 lm/W over the visible band; this is an assumption about the spectrum, which the exposure settings do not supply. The radiant exposure is then $H_e \approx 0.0221/300 \approx 7.4\times10^{-5}$ J/m². Approximating every photon by its energy at 555 nm, $hc/\lambda \approx 3.6\times10^{-19}$ J, gives about $2\times10^{14}$ photons per square meter. A 4 µm photosite, $1.6\times10^{-11}$ m², receives about 3,300 photons, and with a flat quantum efficiency of 0.5 about 1,600 electrons, so shot noise alone limits its signal-to-noise ratio to about 40. A 1 µm phone photosite under the same exposure collects one sixteenth as much: about 100 electrons and a signal-to-noise ratio near 10, before read noise, and before the color filter passes only part of the spectrum to each photosite. That is the noise budget of Chapter 2.8, Noise, signal-to-noise ratio and dynamic range, and the reason merging frames matters on a phone.

Likewise, a nominal ISO label need not be the saturation-based ISO speed. A relation defining saturation-based speed cannot be applied to every manufacturer's recommended exposure index to infer sensor clipping or a fixed middle-gray headroom. Measure the relevant raw saturation and noise behavior.

Across ordinary photographs the same chain spans a very wide range (Figure 17.2.4). Six auto-exposed frames, from a near-dark cave to full sun, look about equally bright, yet their meter-equivalent luminances span more than four decades, about fifteen stops. The light level is invisible in the picture and shows only in the numbers: at the figure's reference lens and pixel, the near-dark end delivers a few thousand photons per pixel per second and is limited by noise, while the sunlit end delivers hundreds of millions. The exposure controls exist to slide that photon budget onto the sensor's usable range.

fig-light-level-ladder
Figure 17.2.4. One photograph from each rung of the light-level range. Six of the author's own frames, ordered darkest to brightest scene: a near-dark cave, a city at night, a dim interior, a lit interior, an overcast day, and full sunlight. Each is labeled with an estimated light level, as incident illuminance in lux (assuming an 18% reflectance) and as an EV at ISO 100, running from about 3 lux in the cave to 110,000 lux in full sun; beneath it sit the meter-equivalent scene luminance (cd/m$^2$, computed as $L = KN^2/(tS)$ from the EXIF settings, assuming the camera's metered exposure with no compensation) and the photon rate that implies at a fixed reference (an f/2 lens, a 4 µm pixel, before quantum-efficiency losses). The frames look about equally bright because each was auto-exposed to mid-tones, which is exactly the point: the underlying light level, and the photon budget behind it, spans more than four decades (~15 stops), invisible in the picture and legible only in the numbers. The numbers are estimates under those assumptions, not measurements. (Author's photographs.)