Development and validation of an AI algorithm to generate realistic and meaningful counterfactuals for retinal imaging based on diffusion models

Indu Ilanchezian, Valentyn Boreiko, Ziwei Huang, Murat Seçkin Ayhan, Matthias Hein, Lisa M. Koch, Philipp BerensPLOS Digital Health 2025

TL;DR

This paper introduces a novel AI approach using diffusion models guided by robust classifiers to generate realistic and clinically meaningful "what-if" scenarios (counterfactuals) for retinal images. These generated images can help clinicians understand disease progression and aid in patient education by visualizing how an image might look with or without specific conditions like diabetic retinopathy.

What Problem Does This Paper Address?

In medical imaging, especially in fields like ophthalmology, understanding disease progression and the impact of treatments often relies on counterfactual reasoning – imagining "what if" scenarios. For instance, a clinician might wonder how a patient's retinal scan would look if they had developed diabetic retinopathy. While AI models can classify diseases, they struggle to generate realistic visual explanations for these counterfactual questions. Existing methods often produce images that are either not realistic, introduce artifacts, or fail to capture the subtle nuances of disease. This gap limits the potential of AI to aid in medical training, patient education, and clinical decision-making.

Methods

The core of this work lies in combining two powerful AI techniques:

  • Diffusion Models: These are state-of-the-art generative models known for producing high-quality, diverse images. The authors trained an unconditional diffusion model on retinal images to learn the underlying data distribution.
  • Classifier Guidance: To make the generated images "meaningful" and directed towards a specific outcome (e.g., showing signs of disease), the diffusion model's generation process is guided by the gradients of a trained classifier.
  • Adversarially Robust Classifiers: Crucially, the authors found that using adversarially robust classifiers (classifiers trained to withstand small, malicious perturbations) significantly improved the realism and clinical relevance of the generated counterfactuals. They also employed a "cone projection" technique to combine the gradients from both plain and robust classifiers, balancing performance and robustness.
  • Regularization: A regularization parameter was tuned to control the degree of change, ensuring generated images remained close to the original while still reflecting the target condition.

Datasets

The study utilized two primary types of retinal imaging datasets:

  • Color Fundus Photography (CFP): Large-scale datasets from EyePacs Inc. (for Diabetic Retinopathy screening) and augmented with data from Benitez and FGADR datasets. These were used for training both plain and robust classifiers, as well as the diffusion model.
  • Optical Coherence Tomography (OCT) B-scans: A publicly available dataset containing scans categorized as normal, choroidal neovascularization (CNV), drusen, and diabetic macular edema (DME). This dataset was used for training classifiers and the diffusion model for OCT counterfactual generation.

Key Insights and Ideas

  • Robust Classifiers are Key for Realistic Counterfactuals: The most significant finding is that adversarially robust classifiers, not just standard ones, are essential for generating clinically meaningful and realistic counterfactual medical images. Their gradients provide better guidance for diffusion models.
  • Diffusion Models Excel at Medical Image Generation: Diffusion models, when guided appropriately, can generate high-resolution medical images with impressive realism, surpassing previous methods like GANs in this domain.
  • Counterfactuals as Explanations: The generated counterfactuals serve as powerful visual explanations, illustrating why a classifier makes a certain prediction and highlighting the features indicative of disease.
  • Bi-directional Counterfactuals: The method can generate counterfactuals in both directions – transforming a healthy image to show disease and a diseased image to appear healthy, offering a comprehensive view of disease progression.
  • OCT Counterfactuals are Harder but Still Valuable: While fundus image counterfactuals were nearly indistinguishable from real images to experts, OCT counterfactuals were more detectable, likely due to the nature of OCT data and disease presentation. However, they still captured key clinical features.

Key Results

  • Realism: Generated color fundus images were found to be indistinguishable from real images by domain experts in a user study. OCT images were realistic but identifiable by experts with higher than chance probability.
  • Meaningfulness: Counterfactual images were classified with accuracy comparable to real images, indicating that the introduced changes were clinically meaningful.
  • Expert Evaluation: In an odd-one-out task, experts struggled to distinguish diffusion counterfactuals from real fundus images (close to chance level performance), while sparse counterfactuals were easily identified.
  • Classification Performance: The diffusion model with cone-projected gradients achieved high balanced accuracy for both binary and multi-class fundus classification tasks.
  • Regularization Impact: Tuning the regularization strength allowed control over the extent of changes, balancing lesion generation/removal with preserving image structure.

Limitations and Future Work

  • OCT Realism: While realistic, OCT counterfactuals were more detectable than fundus images, possibly due to the nature of OCT data, disease representation, and the model's tendency to create regular structures.
  • Extreme Disease Stages: The model struggled to generate realistic counterfactuals for the most advanced stages of DR (severe and proliferative) due to their underrepresentation in the training data.
  • Classifier Limitations: The quality of counterfactuals is dependent on the classifier's ability to learn relevant features. If a classifier relies on shortcuts or misses subtle cues, the counterfactuals may not be optimal.
  • Future Directions: The authors suggest extending this work to multi-task DNNs for generating counterfactuals for multiple attributes simultaneously (e.g., age and disease progression), exploring language-guided image generation, and applying the method to longitudinal data or data with interventions (like drug treatments). They also propose investigating techniques to remove biases and systematic errors from classifiers and exploring methods for continuous model updating in real-world scenarios.

Summary updated

BibTeX
@inproceedings{ilanchezian2025development,
  author = {Indu Ilanchezian and Valentyn Boreiko and Ziwei Huang and Murat Seçkin Ayhan and Matthias Hein and Lisa M. Koch and Philipp Berens},
  title = {{Development and validation of an AI algorithm to generate realistic and meaningful counterfactuals for retinal imaging based on diffusion models}},
  booktitle = {PLOS Digital Health},
  year = {2025},
  url = {https://openreview.net/forum?id=LgMStJUxk4},
}
Figure