Amortized Image Registration and Weakly Supervised Endoscopy

MIT 6.874 · Lecture 22: Image Registration and Automatic Pathology Detection

Biology
Deep Learning
Medical Imaging
How VoxelMorph, SynthMorph, and HyperMorph amortize 3D medical image registration, and how Y-Net and PS-DeVCEM tackle polyp segmentation and weakly supervised capsule endoscopy.
Author

Chao Ma

Published

November 28, 2026

Aligning two 3D brain MRI volumes with classical pairwise optimization (ANTs or NiftyReg on CPU) takes roughly 2,350 to 9,000 seconds per scan pair because the solver optimizes a fresh deformation field from scratch for every pair (Part A, p. 25). Replacing that per-pair solver with a shared convolutional network (VoxelMorph) shifts the optimization cost into training and aligns a new 3D pair in 51 seconds on CPU and 0.5 seconds on GPU.

MIT 6.874 Lecture 22 (Spring 2021; listed as Lecture 22, Imaging and Cancer, in the course schedule, while the linked recording is titled Lecture 21: Deep Learning Image Registration and Analysis on YouTube) pairs two medical-imaging workflows that solve structural bottlenecks without dense per-voxel or per-frame supervision at test time. Adrian V. Dalca (HMS, MIT) covers unsupervised, probabilistic, modality-agnostic, and hyperparameter-amortized 3D registration (l22a.pdf, 65 pp.). Ahmed Mohammed (NTNU, SINTEF Digital) covers dual-encoder polyp segmentation (Y-Net) and weakly supervised multiple-instance learning (PS-DeVCEM) for capsule video endoscopy (l22b.pdf, 41 pp.).

Two-row pipeline diagram on warm cream background. Top row shows Pairwise Optimization taking Scans (m, f) through an Iterative Solver (Optimize phi per pair) and Warp m o phi in roughly 2,350 to 9,000 s on NiftyReg or ANTs CPU. Bottom row shows Amortized VoxelMorph taking Scans (m, f) through CNN g_theta(m, f) with shared weights, integrating velocity v to deformation field phi_z, and completing in 0.5 s on GPU or 51 s on CPU.

Comparison between per-pair iterative optimization (NiftyReg / ANTs CPU) and amortized neural registration (VoxelMorph GPU / CPU) on 3D brain MRI pairs (MIT 6.874 Lecture 22, Part A, p. 25).

Part I: Unsupervised and amortized 3D image registration

Image registration estimates a spatial correspondence field \(\phi\) that warps a moving scan \(m\) onto a fixed scan \(f\) so anatomical coordinates line up for population templates, longitudinal tracking (such as brain aging or lesion progression), pre-/post-surgical alignment, and label propagation (Part A, pp. 4–11).

Classical pairwise optimization solves a separate variational problem for each image pair \((m, f)\) (Part A, p. 12):

\[ \hat{\phi}_{m,f} = \arg\min_{\phi} \|m \circ \phi - f\| + \lambda\,\text{Reg}(\phi), \]

where the first term measures intensity mismatch between the warped moving scan \(m \circ \phi\) and \(f\), and \(\lambda\,\text{Reg}(\phi)\) penalizes non-smooth deformations. Although mathematically well understood, optimizing \(\phi\) independently for every new scan pair is computationally slow.

VoxelMorph and the probabilistic diffeomorphic model

Rather than requiring ground-truth deformation fields \(\phi_{\text{gt}}\) in supervised training (\(\mathcal{L} = \|\phi - \phi_{gt}\|^2\), Part A, p. 16), VoxelMorph parameterizes a shared U-Net-style network \(g_\theta(m, f)\) across the entire training set and evaluates the classical unsupervised registration objective directly through a differentiable spatial transform layer (Part A, pp. 17–21). Writing this objective in clarified, consistently indexed notation:

\[ \mathcal{L}(\theta; \text{data}) = \sum_{(m, f) \in \mathcal{D}} \Big[\,\|m \circ g_\theta(m, f) - f\| + \lambda\,\text{Reg}\big(g_\theta(m, f)\big)\,\Big]. \]

(Slides 19–20 print shorthand \(\sum_{i,j} \|m_i \circ g_\theta(m_i.f_i) - f_{ij}\| + \lambda\,\text{Reg}(g_\theta(m_i.f_i))\) with mixed indices and omitted outer brackets.) During stochastic gradient descent, each training pair nudges the shared weights \(\theta\), amortizing optimization across the population so test-time registration requires a single forward pass.

To encourage smooth, orientation-preserving (diffeomorphic) deformations—which hold theoretically when a sufficiently smooth velocity field is integrated accurately—and estimate uncertainty, Dalca formulates registration as a probabilistic generative model (Part A, p. 23):

\[ m \circ \phi_z + \epsilon = f, \qquad z \sim \mathcal{N}(z; 0, \Lambda^{-1}), \]

where \(z\) is a stationary velocity field whose prior precision matrix \(\Lambda\) encodes spatial smoothness via a graph Laplacian. Integrating \(z\) (shown as via v integration / integration layer on pp. 36–57, implemented in VoxelMorph via scaling and squaring) yields a diffeomorphism \(\phi_z\), and variational inference approximates the posterior probability of registration \(p(z \mid m, f)\).

As a constructed 1D scaling-and-squaring check (not lecture data), suppose a 1D stationary velocity field is \(v(x) = -1.2 x\). Applying the full displacement in one direct Euler step gives \(\phi_{\text{direct}}(x) = x + v(x) = -0.2 x\): while still algebraically invertible (\(y \mapsto -5y\)), its negative derivative \(-0.2 < 0\) reverses spatial orientation, violating the positive-Jacobian condition of orientation-preserving diffeomorphic registration. Splitting the integration into \(T = 2\) scaling-and-squaring stages (\(2^T = 4\) substeps) first forms the small step \(\phi^{(1/4)}(x) = x + \frac{1}{4}v(x) = 0.7 x\) (derivative \(0.7 > 0\)) and squares it twice (\(\phi^{(1/2)} = \phi^{(1/4)} \circ \phi^{(1/4)}\), \(\phi^{(1)} = \phi^{(1/2)} \circ \phi^{(1/2)}\)), producing \(\phi^{(1)}(x) = 0.7^4 x = 0.2401 x\) with positive derivative everywhere (whereas the exact continuous ODE flow for \(v(x) = -1.2 x\) gives \(e^{-1.2} x \approx 0.3012 x\)).

Runtime, limited-data regimes, and auxiliary segmentations

On an atlas-based brain MRI benchmark (7,000 training volumes, 250 validation, 250 test; Part A, pp. 24–27), VoxelMorph matched baseline optimization accuracy across 17 brain structures (Brain-Stem near 0.9 Dice down to choroid-plexus near 0.3) while cutting inference runtime by orders of magnitude:

Method Device Reported Runtime per 3D Pair Source
ANTs CPU ~9,000 s (bar chart; error bar ~7,000–11,000 s) Part A, p. 25
NiftyReg CPU ~2,350 s (bar chart) Part A, p. 25
VoxelMorph CPU 51 s (slide label) Part A, p. 25
VoxelMorph GPU 0.5 s (slide label) Part A, p. 25

Two practical extensions on Part A, pp. 29–31 show how amortized learning behaves when training data are scarce or auxiliary labels exist:

  • Limited training data (p. 29): Across training-set sizes of 10, 25, 50, and 100 volumes, pure amortized test-set Dice rises from roughly 0.71 (10 scans) toward the ANTs (SyN) baseline (dashed line near 0.75, read visually from the plot). Running instance-specific optimization initialized from the trained VoxelMorph network (Test Set (Instance-Specific Opt.)) lifts Dice slightly above ANTs (SyN) (visually near 0.76) even when trained on just 10 scans.
  • Auxiliary segmentation masks at training (pp. 30–31): When anatomical segmentations \((s_m, s_f)\) are available during training, adding a Dice loss between the warped segmentation \(s_m \circ \phi_z\) and \(s_f\) guides the deformation field without requiring segmentations at test time. Median test-time Dice rises from visually ~0.75 (VoxelMorph) to ~0.84 (VoxelMorph w/ seg).

SynthMorph, HyperMorph, and conditional templates

Dalca closes Part A with three extensions that remove dependence on specific imaging contrasts, fixed hyperparameters, and static population atlases:

  1. SynthMorph (pp. 32–41): Building on synthetic contrast generation (Billot et al., MIDL/MICCAI 2020, lab2im, p. 34), SynthMorph (Hoffmann et al., p. 32 / Hoffman et al., pp. 36–38) samples synthetic anatomical label pairs \((s_m, s_f)\) from \(g_s(z)\) and renders arbitrary synthetic image contrasts \((m, f)\) via \(g_I(s_m, s_f, z)\) without real training scans. A modality-agnostic CNN \(h_\theta(m, f)\) predicts a velocity field \(v \to \phi_v\) trained solely with Dice overlap \(\mathcal{L}_{\text{dis}}\) on the synthetic labels plus \(\mathcal{L}_{\text{reg}}\). Evaluated across six contrast/dataset settings on p. 39 (T1-T1^b, T1-T1^{b,x}, T2-T2^b, T1-PD^{b,x}, T1-T2^b, and T1-T2, where b marks skull-stripped and x cross-dataset pairs), intensity-based vm-ncc drops below the 0.55 axis floor on T1-PD^{b,x}, T1-T2^b, and T1-T2 (vm-nmi also drops below 0.55 on T1-PD^{b,x}), whereas sm-shapes and sm-brains stay competitive across all six settings.
  2. HyperMorph (pp. 42–52): Tuning the smoothness weight \(\lambda\) normally requires training a grid of separate models—reported on p. 48 as 765 GPU-hours across ~10 VoxelMorph models. HyperMorph uses a hypernetwork \(h(\lambda)\) that maps \(\lambda\) directly to registration network weights \(\theta_v\), training one model in 147 GPU-hours (a 5.20x speedup, reducing compute by 80.78%) while tracing the entire validation Dice curve vs. \(\lambda\). Crucially, HyperMorph exposes that optimal \(\lambda\) is not universal: read visually from the curves, it shifts across datasets (PPMI, ABIDE, GSP, UK Biobank; p. 50), across tasks (Within-subject peaks near \(\lambda \approx 0.83\) vs. Cross-subject near \(\lambda \approx 0.16\); p. 51), and even across regions in the same brain (CSF peaks near \(\lambda < 0.1\), Hippocampus/Putamen near \(0.6\text{–}0.7\), and Accumbens/Pallidum near \(0.8\text{–}0.9\); p. 52).
  3. Deformable and conditional templates (pp. 53–61): Jointly optimizing template parameters \(\Psi_{\text{atl}}\) alongside the velocity predictor learns a sharp population atlas \(t\) directly from scans \(x_i\) (p. 55). Conditioning a template generator \(g_{t, \theta_t}(a_i)\) on clinical attributes \(a_i\) (p. 57) produces continuous age-varying brain atlases from 15 to 90 years (p. 58) and neonatal dHCP atlases from 29 to 44 weeks (p. 61).

Part II: Automatic pathology detection in endoscopy

Ahmed Mohammed shifts from 3D volumetric registration to gastrointestinal imaging for colorectal cancer (CRC) and ulcerative colitis (UC) screening (Part B, pp. 2–8). In Capsule Video Endoscopy (CVE), a 31 x 11 mm swallowable capsule captures roughly 50,000 frames per exam and requires about 2 hours of manual physician review (Part B, p. 4). Models face severe appearance variability (sessile vs. pedunculated polyps, neoplastic vs. hyperplastic morphology, specular reflections, debris) alongside scarce pixel- and frame-level annotations (Part B, pp. 5–8).

Y-Net: Dual encoders for polyp segmentation

To address domain shift when adapting ImageNet-pretrained backbones to colonoscopy video frames without overfitting on small medical datasets, Y-Net (Mohammed et al., 2018, Part B, pp. 10–15) feeds the same input frame into two parallel encoders feeding a single decoder: one initialized with pretrained VGG19 weights (Encoder one) and one initialized with random weights trained from scratch (Encoder two).

Training uses an adaptive RMSprop-style update (printed verbatim on Part B, p. 16 with \(+\epsilon\) inside the square root) and a hybrid weighted log-likelihood plus soft Dice loss:

\[ \theta_{t+1} = \theta_t - \frac{c \cdot \eta}{\sqrt{E[g^2] + \epsilon}} \cdot g_t, \]

where \(c\) is a learning-rate scaling factor, \(\eta\) is the base learning rate, \(g_t\) is the gradient at step \(t\), \(E[g^2]\) is the running squared-gradient average, and square root, addition, and division apply elementwise, paired with:

\[ \mathcal{L}(p, g) = -\frac{1}{N}\sum_{i=1}^{N} \left(\frac{\lambda}{2} \cdot g_i \cdot \log p_i\right) + \left(1 - \frac{2\sum_{i=1}^{N} (g_i \cdot p_i) + \epsilon}{\sum_{i=1}^{N} p_i + \sum_{i=1}^{N} g_i + \epsilon}\right). \]

Notice that Slide 16 writes only the foreground log term (\(g_i \log p_i\)) rather than symmetric binary cross-entropy; pairing it with the soft Dice denominator \(\sum p_i + \sum g_i + \epsilon\) is essential so predicting \(p_i \equiv 1\) on background pixels is penalized by the Dice term. As a constructed 4-pixel loss check (not lecture data) with ground truth \(g = (1, 1, 0, 0)\), predicted probabilities \(p = (0.8, 0.5, 0.2, 0.1)\), \(\lambda = 1.0\), and \(\epsilon = 10^{-6}\):

  • Foreground log term: \(-\frac{1}{4}\left[0.5\ln(0.8) + 0.5\ln(0.5)\right] \approx 0.1145\).
  • Soft Dice overlap: \(\frac{2(0.8 + 0.5) + 10^{-6}}{1.6 + 2.0 + 10^{-6}} = \frac{2.6}{3.6} \approx 0.7222\), giving Dice loss \(1 - 0.7222 = 0.2778\) and total \(\mathcal{L} \approx 0.3923\).

Evaluated on the ASU-Mayo Clinic polyp database (20 training and 18 test colonoscopy video segments with pixel-level masks: 4,278 / 18,495 polyp frames in training and 4,300 / 17,574 frames in test; Part B, p. 17), methods are scored with \(F_1 = \frac{2PR}{P+R}\) and \(F_2 = \frac{5PR}{4P+R}\), where \(F_2\) weights recall four times as heavily as precision to penalize missed polyps (Part B, p. 18):

Paired horizontal bar chart on warm cream background comparing Recall (%) and F1-Score (%) on the ASU-Mayo Clinic polyp benchmark. Y-Net (Dual Encoders) reaches 84.4% Recall and 85.9% F1-Score; U-Net (VGG19 Only) reaches 68.2% Recall and 79.8% F1-Score; Fusion (3D CNN) reaches 71.0% Recall and 78.6% F1-Score; U-Net (Scratch) reaches 39.2% Recall and 54.7% F1-Score.

Recall and F1-score comparison across single-encoder U-Nets, 3D Fusion, and dual-encoder Y-Net on the ASU-Mayo Clinic polyp benchmark (MIT 6.874 Lecture 22, Part B, pp. 19–20).

Combining the ablation and benchmark tables (Part B, pp. 19–20):

Method TP FP FN Prec (%) Rec (%) F1 (%) F2 (%)
U-Net (scratch, ablation) — — — 90.8 39.2 54.7 44.2
U-Net (VGG19 single encoder) — — — 96.2 68.2 79.8 72.4
PLS 1,594 10,103 2,719 13.6 36.9 19.9 27.5
CVC-CLINIC 1,578 3,456 2,735 31.3 36.6 33.8 35.4
OUS 2,222 229 2,091 90.6 51.5 65.7 56.4
ASU 2,636 184 1,677 93.5 61.1 73.9 65.7
CUMED 3,081 769 1,232 80.0 71.4 75.5 73.0
Fusion (3D CNN) 3,062 414 1,251 88.1 71.0 78.6 73.9
Y-Net (Ours, dual encoders) 3,582 513 662 87.4 84.4 85.9 85.0

While a single pretrained VGG19 encoder achieved higher precision (96.2% vs. 87.4%), adding the randomly initialized encoder increased recall by +16.2 percentage points (68.2% to 84.4%), lifting F1 to 85.9% and F2 to 85.0%. Checking the Slide 20 confusion counts directly reveals an unresolved evaluation-denominator discrepancy in the published table: the six baselines sum TP + FN = 4,313 and Y-Net sums 3,582 + 662 = 4,244, compared with 4,300 positive test frames stated on Slide 17, alongside 0.1 pp rounding differences (3,582 / (3,582 + 513) = 87.47% vs. printed 87.4%; OUS and PLS likewise differ by 0.1 pp). All slide-reported counts and percentages are retained verbatim here, leaving the denominator discrepancy unresolved.

PS-DeVCEM: Weakly supervised video Multiple Instance Learning

Because manually labeling ~50,000 frames per clinical capsule exam does not scale, PS-DeVCEM (Mohammed et al., 2020, Part B, PDF pp. 23–37) frames capsule endoscopy as Multiple Instance Learning (MIL). (Note on l22b.pdf page numbers: the deck omits printed slide number 23, so from PDF p. 23 onward, printed slide footers sit +1 ahead of the PDF #page= index; all links below follow PDF page numbers.) While the clinical motivation stems from full ~50,000-frame exams (p. 4), the evaluated 227 training / 228 test dataset (PDF p. 32) consists of shorter labeled video segments (the published PS-DeVCEM paper uses 30-frame sequences, uniformly sampling longer clips). Each labeled video segment \(V = \{f_1, \dots, f_N\}\) is treated as a bag with a known segment-level label \(G\) and unknown frame-level labels \(\mathbf{y} = \{y_1, \dots, y_N\}\) (Part B, PDF p. 25): a positive bag contains at least one pathology frame (\(Y = \max_n \{y_n\}\) for a single target class; Part B, PDF p. 26), whereas a negative bag contains none.

The capsule dataset spans 227 training video segments and 228 testing video segments across 14 pathology/normal labels (Part B, PDF p. 32): summing the per-class counts gives 376 training entries and 413 testing entries (exceeding 227 and 228) because individual segments can exhibit multiple pathologies simultaneously (Erosions, Debris, Polyp, Ulceration, Normal, and nine additional classes).

Naïve Single-Instance Learning (SIL) copies the bag label onto every frame, mislabeling healthy frames inside positive bags and collapsing to 0.066 F1 (0.046 recall; Part B, PDF pp. 24, 35). PS-DeVCEM (EndoscopicMIL) solves this in three stages (Part B, PDF pp. 27–35):

  1. Temporal sequence modeling (PDF pp. 28–29): Shared ResNet-50 weights (ImageNet-initialized in the published paper) map frames to features \(x_1, \dots, x_N\), which pass through forward and backward Residual LSTM blocks (combining a Conv1D shortcut with stacked LSTM layers) to produce hidden states \(\mathbf{h}_1, \dots, \mathbf{h}_N\) (row vectors \(\mathbf{h}_n \in \mathbb{R}^{1 \times D}\)).
  2. Temporal attention pooling (PDF p. 30): Instead of uniform averaging, an ungated tanh attention network (\(\mathbf{V} \in \mathbb{R}^{L \times D}\), \(\mathbf{w} \in \mathbb{R}^{L \times 1}\)) assigns frame weights \(\alpha_n\) and forms the bag embedding \(Z\): \[ Z = \sum_{n=1}^{N} \alpha_n \mathbf{h}_n, \qquad \alpha_n = \frac{\exp\{\mathbf{w}^\top \tanh(\mathbf{V}\mathbf{h}_n^\top)\}}{\sum_{i=1}^{N} \exp\{\mathbf{w}^\top \tanh(\mathbf{V}\mathbf{h}_i^\top)\}}. \]
  3. Attention-guided dual sub-bag self-supervision (PDF p. 31): Frames whose attention exceeds the uniform baseline \(1/N\) form a positive-evidence sub-bag \(Z_{\text{bag}}^+ = \sum_{\alpha_b > 1/N} \mathbf{h}_b^+\), while frames with \(\alpha_b \le 1/N\) form a negative-evidence sub-bag \(Z_{\text{bag}}^- = \sum_{\alpha_b \le 1/N} \mathbf{h}_b^-\), jointly supervised by a bag-level and dual-sub-bag cross-entropy loss (note that the slide graphic on PDF p. 31 / printed footer 32 mixes \(m\) and \(n\) indices, omits the negative sign on its first term, and omits outer parentheses on the second term).

As a constructed 4-frame attention-MIL check (not lecture data), suppose \(N = 4\) frames produce raw unnormalized attention scores \(s = (0.1, 2.2, 1.5, -0.5)\). Softmax normalization gives \(\alpha = (0.0726, 0.5930, 0.2945, 0.0399)\), summing to \(1.0000\). Against the uniform cutoff \(1/N = 0.25\), only frames 2 (\(\alpha_2 = 0.5930\)) and 3 (\(\alpha_3 = 0.2945\)) enter \(Z_{\text{bag}}^+\), while frames 1 and 4 enter \(Z_{\text{bag}}^-\).

Paired horizontal bar chart on warm cream background showing Mean F1-Score and Mean Precision averaged across 14 capsule endoscopy classes. EndoscopicMIL (Proposed) reaches 0.551 F1 and 0.616 Precision; EndoscopicMIL (No Self-Sup) reaches 0.540 F1 and 0.606 Precision; STPN reaches 0.536 F1 and 0.592 Precision; AttenLSTM reaches 0.487 F1 and 0.529 Precision; AttenConv reaches 0.246 F1 and 0.229 Precision; SIL reaches 0.066 F1 and 0.235 Precision.

Ablation and benchmark progression across weakly supervised MIL models averaged over 14 capsule endoscopy classes (MIT 6.874 Lecture 22, Part B, PDF pp. 34–35).

The ablation and MIL comparison tables (Part B, PDF pp. 34–35) isolate why each component matters:

Method Precision Recall F1-Score Specificity
SIL (instance label copy) 0.235 0.046 0.066 0.997
MissSVM 0.130 0.162 0.123 0.912
AttenConv (frame feature input & attention) 0.229 0.290 0.246 0.872
AttenConvLSTM (frame input, LSTM hidden attention) 0.450 0.461 0.443 0.939
AttenLSTM (LSTM hidden input & attention) 0.529 0.478 0.487 0.954
GuidedLSTM (LSTM hidden + self-supervision) 0.487 0.482 0.458 0.946
Attention-based deep MIL 0.616 0.471 0.513 0.955
STPN (temporal baseline) 0.592 0.517 0.536 0.916
W-TALC 0.274 0.891 0.416 0.666
EndoscopicMIL (w/o self-supervision) 0.606 0.540 0.540 0.951
EndoscopicMIL (proposed: Residual LSTM + self-sup.) 0.616 0.546 0.551 0.951

Computing attention over raw frame features (AttenConv, 0.246 F1) almost doubles when attending over LSTM hidden states (AttenConvLSTM, 0.443 F1; AttenLSTM, 0.487 F1), because pathologies span contiguous bursts of video frames rather than isolated snapshots. Adding Residual LSTM blocks and the attention-guided dual sub-bag self-supervision lifts average F1 from 0.540 (without self-supervision) to 0.551 at 0.951 specificity.

Pretext self-supervision for endoscopy (PDF pp. 38–39)

In the closing section of Part B, Mohammed discusses pretext self-supervision separately from PS-DeVCEM—first citing image-rotation prediction (Gidaris et al., 2018, Part B, PDF p. 38), and then showing a multi-orientation/multi-view (MOMV) Context Free Encoder that splits each 201x201x3 RGB endoscopic patch into a \(3\times 3\) grid of nine \(67\times 67\) sub-patches (67X67x1 through 67X67x9) for a 100-class pretext task before 3-class downstream classification (Part B, PDF p. 39).

Lecture and sources