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.

15.6 Learned demosaicking⧉

Fine fabric and thin diagonal structures can defeat local interpolation rules. A learned demosaicker uses a larger training collection to fit how sparse color samples map to full-color detail.

A synthetic training pair is easy to construct by selecting one component per pixel from a full-color image. Producing a representative clean target is harder: a processed photograph may already contain demosaicking, denoising, sharpening and compression artifacts, and its RGB channels need not be camera-linear responses.

Specify the color domain and how the target was prepared before treating remosaicking as a sensor simulation.

15.6.1 The data problem hiding inside a free training set⧉

Uniformly sampled crops may underrepresent difficult patterns. If most loss comes from easy or common regions, training can leave rare artifacts insufficiently addressed. The actual error distribution should be measured.

Gharbi and colleagues' contribution (Gharbi et al. 2016) was to notice this and to mine for the hard cases. Run a classical method over a large corpus, find the patches where it fails, and train mostly on those. The network then spends its capacity on moire, on fine diagonal structure, and on the color boundaries where the difference assumption breaks, which is where the remaining error actually is.

Hard-case mining changes what the network is trained to prioritize. Keep a representative held-out test set, and report performance on both ordinary and difficult scenes; otherwise a gain on mined cases can hide regressions elsewhere.

fig-demosaic-hard-cases
Figure 15.6.1. Interactive. What a hard patch looks like. The panel reconstructs a large set of crops with classical demosaicking and plots the distribution of their PSNR: most crops reconstruct well, a thin tail does not, and the tail is dominated by fine repetitive texture, diagonals and saturated boundaries. The lowest-scoring fifth is marked as the mined hard set, and a click on the histogram opens the crop nearest that score, with two classical reconstructions side by side. No learned method is run or retrained here; the figure shows what hard-example mining selects, which is the training set the chapter's learned methods depend on. Interactive: browse the distribution and click a score to inspect the nearest crop and its two reconstructions.
fig-deep-demosaick-1
Figure 15.6.2. The learned model's result, set against the methods of this chapter. From a single noisy Bayer mosaic (the regime where green-based and edge-directed demosaicking start to crumble because the noise corrupts the very gradients and color differences they rely on) the network produces a clean, full-color reconstruction in one shot. Notice that the win is both sharper edges and the absence of the maze and fringing artifacts we spent the chapter chasing: by solving denoising and demosaicking together, the model never has to guess on top of guesses. Gharbi et al. 2016.
fig-deep-demosaick-2
Figure 15.6.3. The network architecture. The mosaic enters as input and a stack of convolutional layers learns the local operations that classic demosaicking hand-coded (gradient estimation, direction selection, cross-channel color-difference interpolation) but jointly and tuned to data instead of designed term by term. Read it as the heuristic pipeline of this chapter, replaced by a single trained model that discovers which neighborhood structure to exploit. Gharbi et al. 2016.
fig-deep-demosaick-3
Figure 15.6.4. What a network learns when you train it on standard, mostly-easy images: the same family of artifacts the classic methods leave behind. Smooth regions look perfect, but fine periodic color texture still produces maze and false color, because those hard cases are scarce in ordinary training sets and contribute almost nothing to the average loss; the model is never forced to solve them. This is the motivation for the whole next step: the bottleneck is not the architecture, it is what the network is shown. Gharbi et al. 2016.
fig-deep-demosaick-4
Figure 15.6.5. The hard patches, mined automatically into the training set. These are the high-frequency color textures (fine periodic detail, sharp diagonal color edges) where the "color is smooth" assumption fails and classic methods leave maze and fringing. By searching data for the cases that defeat the heuristic and over-representing them, training is steered straight at the chapter's hardest examples; this targeted mining, more than the network design, is what produced the gain. Gharbi et al. 2016.
fig-deep-demosaick-8
Figure 15.6.6. Generalization to real RAW captures. The network, trained on simulated mosaics, holds up on actual sensor data with real noise and real optics, evidence that it learned the underlying image structure (cross-channel correlation, edges, noise statistics) rather than overfitting the synthesis used to make training pairs. Gharbi et al. 2016.
fig-deep-demosaick-10
Figure 15.6.7. Joint denoising and demosaicking versus prior methods. On noisy input the learned model is compared against classic and earlier learned baselines: the gain is largest exactly where this chapter said the hand-built methods struggle (fine color texture and high-contrast edges under noise) because solving the two problems together avoids the artifact-amplifying handoff of demosaick-then-denoise. Gharbi et al. 2016.
Video 15.6.1. Video: Deep Joint Demosaicking and Denoising, Michaël Gharbi, Gaurav Chaurasia, Sylvain Paris, Frédo Durand 2016 (YouTube).

15.6.2 Architectures, briefly⧉

Gharbi et al. used a convolutional architecture and curated difficult examples (Gharbi et al. 2016). Later designs include explicit cross-channel guidance (Liu et al. 2020 (self guidance)), transformer/attention blocks (Xing & Egiazarian 2022 (RSTCANet)) and joint reconstruction tasks (Xing & Egiazarian 2021 (joint demosaic-denoise-SR)). Their differences matter only alongside the training data, loss, noise conditions and computation budget.

Two representation choices are particularly useful in implementing these models.

Pack the mosaic. Rearrange a Bayer tile into four planes at half width and height. This preserves samples and makes the four CFA phases explicit, including the two green positions. A shift by two raw pixels becomes a one-pixel translation in packed space; an odd raw shift changes phase and channel layout. Packing does not create full one-pixel translation invariance. Update the layout under cropping, rotation and flips.

Predict a residual when a baseline gives useful structure. The residual may be a color difference or a correction to a classical reconstruction. This parameterization can ease training; faster convergence or better generalization must be established for the specific model.

There are several distinct ways to carry classical structure into a learned demosaicker. Packing the Bayer phases into channels makes the periodic sampling pattern explicit. Predicting a correction to a baseline reconstruction lets the baseline handle the easy component. Reconstructing green and using it to guide red and blue gives the network an explicit cross-channel dependency, as in self-guided demosaicking Liu et al. 2020 (self guidance). Attention provides another way to exchange evidence across positions or channels Xing & Egiazarian 2022 (RSTCANet). These choices address different aspects of the problem; adding depth alone does not explain whether an improvement comes from better color guidance, more context, or the difficult examples used in training.

SGNet also supplies a density-map guidance signal to account for regions with different spatial-frequency content (Liu et al. 2020 (self guidance)). This makes reconstruction difficulty an input to local processing, in addition to using an estimated green channel as a guide. Hard-case mining changes which examples appear in training; such spatial guidance changes the evidence the trained network receives within an image. They address related difficulties at different points in the system.

15.6.3 Unrolling, and the bridge from the classical formulation⧉

Demosaicking can be posed as an inverse problem like everything else in this book: the mosaic operator $M$ selects one channel per pixel, and

$$ \hat x = \arg\min_x \; \lVert M x - y \rVert^2 + \lambda\, \rho(x), $$

with $\rho$ a prior that knows the channels share their structure. Solving it iteratively gives a sequence of steps, and unrolling those steps into a network with learned parameters gives the same bridge Chapter 13.7, Learned denoisers described: an architecture derived from an algorithm rather than chosen.

Kokkinos and Lefkimmiatis use iterative reconstruction with a learned residual denoising component (Kokkinos & Lefkimmiatis 2018). This is related to Chapter 13.11, Denoising as a universal prior, but finite learned unrolling does not automatically inherit a plug-and-play convergence result or an explicit image penalty.

Algorithm 15.6.1
# unrolled demosaicking: the data step is trivial because M is a selector
x = classical_demosaic(y)                    # a decent initialization matters here
for t in range(T):
    x = x + step[t] * M_transpose(y - M(x))  # data: put the measured values back
    x = denoise_net[t](x)                    # prior: LEARNED, per step
# a unit step resets measured components before denoising; other steps only move toward them

The denoising step can change measured components again. Exact reinsertion is appropriate for noiseless interpolation if desired; with noisy raw input, the estimator should be allowed to change those samples. State which objective and output convention the implementation uses.

15.6.4 What the networks learned⧉

Outputs alone do not reveal a network's internal reconstruction rule. Test candidate explanations through ablations and controlled inputs.

Wider receptive fields can exploit repeated patterns and broader edge context, but learned and classical methods can both produce false structure. Their errors need not differ categorically. Inspect cases where the color samples support several competing patterns.

That last point deserves care. Demosaicking is usually thought of as reconstruction, not synthesis, because two thirds of the data is missing rather than most of it. But a learned demosaicker on a texture at the sampling limit is choosing between explanations the data does not separate, which is synthesis, and it can be confidently wrong on exactly the fine repeating structures that people zoom in to check.

15.6.5 Benchmarks and their age⧉

Kodak (24 images from Kodak's Photo CD sample set, 768×512) and McMaster (18 crops of 500×500 Zhang et al. 2011 (McMaster dataset)) are small, established full-color evaluation sets. McMaster was assembled because the Kodak images have unusually strong correlation between their color channels, which flatters methods built on that assumption; its images have more saturated colors and weaker inter-channel correlation. Synthetic mosaicking of a finished image measures reconstruction of that target, whose acquisition and processing may differ from a camera-linear sensor image. A film scan does not necessarily contain a prior Bayer demosaicking pass. Document provenance rather than assuming every target was previously demosaicked.

Include fine architecture, text, fabric, clipped regions and multiple cameras in evaluation. Real raw data improves realism, but does not provide exact clean RGB ground truth by itself; paired-capture references and challenge datasets still require their preparation and alignment to be documented.

Color PSNR (CPSNR) commonly uses a single MSE over all RGB samples: $\mathrm{MSE}_{RGB}=\lVert\hat x-x\rVert^2/(3HW)$ and $\mathrm{CPSNR}=10\log_{10}(L^2/\mathrm{MSE}_{RGB})$. This differs from averaging three channelwise PSNRs. State the peak $L$, color encoding and crop. Artifact-specific measures and perceptual comparisons can supplement it. S-CIELAB models spatial sensitivity before color-difference evaluation; it is not a universal measure of every false-color artifact. Inspect image crops as well as averages (Chapter 9.3, Image metrics).

A fence crop and a smooth wall illustrate why an image average is insufficient. Most wall pixels can be reconstructed accurately by several methods, while the fence occupies relatively few pixels and can contain conspicuous alternating colors. Their contribution to a whole-image error may be small even when the artifact attracts attention immediately. Examine fine repetitive textures, diagonals, and saturated boundaries at the intended display scale as well as at pixel scale. Artifact-specific measurements can help identify zippering, while a spatial color metric can account for the different visibility of luminance and chromatic variations. Neither replaces inspection of the failure that matters for the application.