All projects Case study · Computer vision · Medical imaging

Teaching a diffusion model to draw the X-rays we don't have.

The first known class-conditional latent diffusion pipeline for hand osteoarthritis radiographs. It lifted 5-class severity AUC from 0.878 to 0.908 and recovered the near-invisible KL4 class by +0.072 AUC — all on a single cloud GPU.

13,176DIP-joint X-rays from 3,505 patients
2.9%of the data was severe disease
0.878 → 0.9085-class macro AUC
+0.072AUC gain on KL4, the rarest grade
The pipeline
Input13,176 X-rays
CompressVAE → 22×22×8
GenerateKL-conditioned UNet
Synthesise1,500 X-rays
RetrainResNet-18
Result5-class AUC ↑
The problem

Hand osteoarthritis severity is graded 0 to 4 on the Kellgren–Lawrence scale. In this 13,176-image dataset of DIP-joint radiographs, grades 3 and 4 — the severe cases — make up 2.9% of the data. There are 118 real KL4 images against 5,947 KL0 images. That is a fifty-fold imbalance on exactly the grades that change a treatment decision.

A classifier trained on that skew learns to be confidently wrong about severe disease. You cannot simply collect more severe scans, and naive oversampling just memorises the same handful of images. So the question became: can you synthesise clinically faithful severe-grade X-rays that measurably improve the classifier, without leaking a single patient between train and test?

The imbalance
Bar chart of Kellgren–Lawrence grade distribution in the training set, showing 5,947 KL0 images falling to 118 KL4 images
KL grade distribution in the training set. 5,947 images at KL0 (healthy), falling to 144 at KL3 and 118 at KL4. The two grades that matter most clinically are the two the model sees least.
What I did
  1. Curated and de-leaked the data. 13,176 DIP-joint X-rays from 3,505 patients at Boston University and Tufts Medical Center, split 70/15/15 at the patient level and stratified by maximum KL grade, with zero leakage verified programmatically. A real bug surfaced here: matching images on the internal scoring ID gave a 0% match rate. Switching to the OAI participant ID took it to 100%.
  2. Compressed with a VAE. Each 180×180 grayscale radiograph becomes a 22×22×8 latent — a 16:1 compression — so diffusion runs cheaply and spends its capacity on anatomy rather than pixels.
  3. Trained a class-conditional latent diffusion model. A DDPM UNet denoises in latent space with the KL grade injected by scale-and-shift at every block, plus classifier-free guidance. It generates 300 images per grade, 1,500 in total.
  4. Sourced the severe grades from real anatomy. KL0–2 are generated from pure noise. KL3–4 are seeded from a real KL0–2 image re-noised at 60% strength, which preserves authentic bone structure — and produced the lowest FID of any grade for KL3 at 139.6.
  5. Built a CycleGAN baseline to beat. Unpaired healthy ↔ diseased translation, the obvious alternative approach.
  6. Retrained and evaluated honestly. ResNet-18 retrained on real plus synthetic at 10–200% ratios, three seeds each — 51 classifier runs — scored by per-grade AUC on a held-out patient set never used in training or generation.
Architecture
Diagram of the pipeline: VAE encoder compresses the X-ray to a latent, a KL-conditioned UNet denoises it, and the VAE decoder reconstructs a generated X-ray
VAE encoder → KL-conditioned UNet denoiser → VAE decoder. The grade is not a suggestion to the model; it is injected at every block, which is precisely what the CycleGAN baseline had no way to do.
Does it look right?
Top row of real hand X-rays compared with a bottom row of diffusion-generated X-rays
Real (top) versus generated (bottom). The generated series shows visible OA progression — smooth bone margins at KL0 through osteophytes and joint-space narrowing at KL3 to sclerosis and deformity at KL4.
FID score per KL grade, ranging from about 139 to 153, lowest at KL3
FID per grade, 139–153. KL3 scores best, which is the real-image-sourced generation strategy paying off. These FIDs read high against knee-OA literature partly because the reference sets for the rare grades are about 118 images — small references inflate FID by design.
Results
Classification results before and after diffusion augmentation
MetricResult
Overall 5-class macro AUC0.878 → 0.908
KL4 (severe) AUC0.856 → 0.928
KL3 AUC gain+0.041
Seed-to-seed variance0.0148 → 0.0010
Seeds improved3 of 3
CycleGAN baselineno reliable gain
Per-class AUC at baseline versus 50% and 200% synthetic augmentation, with the largest gains at KL3 and KL4
Per-class AUC: baseline vs +50% vs +200% synthetic. Improvement is inversely proportional to how much real data the class had. KL4, with 118 real images, gains roughly fourteen times what KL0 gains with 5,947.
Line chart showing macro AUC rising steadily from the baseline through 200% synthetic ratio
AUC against synthetic ratio. The commonly cited 50% cap on synthetic-to-real data turned out to be conservative here — performance kept climbing all the way to 200%.
What didn't work

The CycleGAN baseline delivered no reliable improvement, and it is worth being precise about why: this was a structural limitation, not a tuning failure. CycleGAN maps between two domains. It has no grade-conditioning input, so it can express "healthy ↔ diseased" and nothing finer. That makes the five-class task unreachable by design, no matter how long you train it. Bone structure also degraded visibly with severity in its outputs.

The honest limitations of the diffusion approach: FID sits at 140–152, which leaves real room for higher fidelity. 180×180 is below clinical resolution. And this is a single-site cohort — multi-site validation and a radiologist reader study are the next steps before anyone should believe it clinically.

Key finding

Synthetic data concentrates its value exactly where real data is scarcest — and the architectural lever is class-conditioning, not model size. That single capability is what makes the five-class task possible at all.

PyTorchLatent Diffusion CycleGANVAE ResNet-18Classifier-free guidance
The poster
Conference poster summarising the project: introduction, methods, results and generated samples
The full conference poster. Open the vector original for a readable version.
Read further