Imaging & devices · Research feature

AI Alignment in Medical Imaging: Unveiling Hidden Biases Through Counterfactual Analysis

Researchers developed a method to assess and reduce demographic bias in medical imaging AI by analyzing how predictions change under hypothetical demographic shifts.

Adapted from research by Haroui Ma, Francesco Quinzan, Theresa Willem and colleagues.

arXiv preprint revision · 2026-07-29 · Attribution & reuse
In this article
Editorial illustration of scanner.

Editor’s introduction

The study evaluates AI models for medical imaging by measuring how predictions shift when sensitive attributes like race are hypothetically altered. It uses counterfactual invariance to determine if model outputs remain consistent across different demographic conditions, leveraging a statistical framework that combines latent diffusion models with hypothesis testing. The approach was tested on synthetic and real-world datasets including cheXpert and MIMIC-CXR, showing reduced model sensitivity to race through metrics like AUC-ROC and Effectiveness Accuracy. The method does not require access to actual counterfactual data, making it practical for real-world deployment. However, the evaluation is limited to specific demographic attributes and does not assess broader societal or clinical impacts of bias reduction.

Author summary

Machine learning (ML) systems are increasingly used in medical imaging for diagnostic purposes. However, these systems can learn biases from training data, leading to disparities in clinical outcomes, particularly across demographic groups. Our work addresses this critical issue by introducing a novel statistical framework that tests whether an ML model’s predictions change when sensitive attributes—such as self-reported race or gender—are altered. We achieve this by using latent conditional diffusion models to create realistic image variations. These tools allow us to measure a model’s dependency on sensitive attributes and assess its fairness. We validate our method on synthetic and real-world medical imaging datasets, demonstrating its effectiveness and alignment with counterfactual fairness principles. This approach represents an important step towards building trustworthy and unbiased AI systems in healthcare.

Introduction

A major problem in using machine learning (ML) systems for healthcare is that these systems exhibit biases leading to disparities in performance for different groups of patients. For instance, patients from certain demographic groups may face a higher likelihood of misdiagnosis, such as false positives or false negatives. One possible reason for this problem is that AI models inadvertently learn and amplify existing confounding effects from the training data.

With recent evidence that ML models can identify demographic factors such as age, sex, and racial identity from medical images —a skill beyond human capabilities—tracking confounding effects contained in medical imaging ML models is non-trivial. Although the exact mechanisms of demographic group membership prediction remain unclear, the observable capability suggests that AI models can learn to correctly correlate certain features from medical image data to real-world demographic attributes, relying on proxies or imaging-related surrogate covariates that correlate with specific attributes. These learned correlations, which may represent unfair treatment and discrimination in the real world, can distort a model’s performance and induce harmful biases. When applied in clinical practice, models entailing such undetected biases may result in underdiagnosis and, thus, undertreatment.

Fairness in medical machine learning

In recent years, fairness has emerged as an area of focus within the machine learning community. One of the earliest fairness metrics in machine learning is fairness through unawareness, which ignores protected attributes like self-reported race and gender. However, this can be ineffective since protected attributes are often encoded in other features. Demographic Parity (DP) refers to the statistical parity of outputs between demographic groups but has been criticized for practically not ensuring fairness, making it unsuitable for medical classification cases. Equality of opportunity (EO) aims for individual fairness but relies on similarities between cases, which are difficult to define in practice. Counterfactual fairness (CF) offers an alternative by ensuring decisions are the same in both real and counterfactual worlds where demographics differ.

Several works have broadly discussed the application of AI fairness on medical datasets. offers a review on fairness in medical imaging but does not propose a novel evaluation method, focusing only on association-based metrics like DP/EO. A cited study investigates the role of demographic encodings and shares a similar fairness goal, but relies on EO, which this work critiques. A cited study uses explainability tools to analyze predictions of protected attributes but lacks a quantitative bias measure. A cited study explores encoding and performance disparities but introduces no new methodology, unlike the statistical testing framework proposed in this work. To summarize, existing methods either rely on non-causal metrics or lack a quantified test framework.

Counterfactual invariance

Counterfactual invariance broadly refers to the desirable property that a model’s predictions remain unchanged when irrelevant aspects of the input are hypothetically altered. Various notions of counterfactual invariance have been proposed in recent years. Almost sure counterfactual invariance means that a variable remains unchanged almost surely, with respect to changes to another variable. study functional counterfactual invariance. According to this definition, a function is considered counterfactually invariant if its output behaves in the same way as in almost sure counterfactual invariance. Distributional counterfactual invariance, on the other hand, requires that the probability distribution of outcomes remains the same under different interventions, rather than the outcomes themselves. Finally, studies a generalization of distributional counterfactual invariance, by considering conditional distributions instead.

A key approach to achieving a predictive model that is counterfactually invariant is learning counterfactual invariant representations. A cited study introduces a neural representation that satisfies certain conditional independence conditions. However, their method uses the Hilbert-Schmidt norm of the kernel covariance as penalty during training. This method is a training-time regularizer rather than a post hoc procedure for quantifying invariance in a fixed pretrained model. Hence, it does not apply to the present problem setting. Furthermore, this approach may suffer from high variance, and it may be inapplicable to high-dimensional settings. As for the paper by, its method targets counterfactual invariance during the training phase. In contrast, the proposed method quantifies counterfactual invariance in a pretrained model.

Related but methodologically distinct invariance-auditing work is also relevant. PreCOF uses predictive counterfactual explanations to detect explicit and implicit bias, but is primarily designed for tabular black-box models and does not provide a statistical test of invariance. Vision-based auditing approaches using generated counterfactual images include generative counterfactual face attribute augmentation, attribute-perturbed encoder-decoder network, and Deep-SCM-based approach like. However, these approaches remain distinct from the present setting: uses ad hoc slope-based sensitivity analysis and lacks a formal testing pipeline; assumes a specified causal graph and structural equations, targets bias scoring and mitigation rather than hypothesis testing. By contrast, the proposed framework is tailored to pretrained medical imaging models and combines high-quality latent-diffusion counterfactuals with standard statistical tests to assess invariance under interventions on sensitive attributes.

Diffusion-based generative models

Diffusion-based generative models have achieved notable success in recent years across a variety of applications. While a comprehensive review is beyond the scope of this work, this paper briefly highlights a few key works relevant to our setting. For a more detailed overview, the authors refer the interested reader to, e.g.,. A cited study introduced diffusion models with a convolutional architecture. A cited study extended this to discrete diffusion models, achieving competitive results. improved the reverse diffusion process by estimating noise, while introduced better noise scheduling for faster sampling. replaced the Markov process with a non-Markovian one, leading to faster sampling. In conditional generation, introduces classifier guidance, while proposes diffusion models that are conditioned on self-supervised representations. focus on generating images from low-density regions and using VAEs for controllable image generation, respectively. A cited study introduces Cascaded Diffusion Models for high-resolution image generation.

Overview

Our approach evaluates whether a medical AI model relies on sensitive attributes, such as the self-reported race or sex, when making predictions. The central idea is to ask a simple question: Would the model’s prediction change if the same patient had a different demographic attribute, while everything else remained identical? Since such data cannot be observed in reality, we use a generative framework to simulate it. First, each medical image is mapped into a latent representation. Within this representation, we separate (disentangle) the information related to the sensitive attribute from the information that encodes clinical content such as anatomy or disease markers. This separation allows us to adjust the sensitive attribute while keeping all other medical factors unchanged. The generative model then reconstructs a new version of the image from the modified representation. If predictions differ, this indicates that the model is not invariant to the attribute, signaling potential bias. This overview captures the intuition behind our method, while the following sections provide the formal causal definition, model architecture, and statistical testing procedure.

Overview

We introduce the Disentangled Conditional Latent Diffusion Model (DCLDM), a conditional latent diffusion framework designed to learn latent representations that separate (disentangle) sensitive attributes from other image factors. Intuitively, a DCLDM represents each image in a latent space where the attribute of interest can be modified independently of all other visual characteristics. Similar to latent diffusion models, DCLDMs are generative models that perform diffusion processes in a lower-dimensional latent space, enabling efficient and scalable generation of high-quality images.

The proposed algorithm

The proof of this theorem leverages the causal graph structure and the concept of a valid adjustment set to establish conditional independence, which, combined with the law of total expectation and properties of conditional variance, demonstrates the equivalence stated in the theorem (see App. A for a detailed proof).

Baselines

Both DP and EO have been criticized, for either not ensuring fairness, or relying on “similarity” attributes that are difficult to define in practice. We remark that DP and EO are purely based on statistical associations, and they do not rely on counterfactuals, as opposed to the notion of counterfactual invariance. In a clinical context, the prevalence of a disease may differ between demographic groups due to socio-economic factors. An accurate, well-calibrated model reflecting these real-world differences could be flagged as “biased” by DP or EO. Furthermore, these metrics can fail to identify subtle, hidden biases that are not reflected in simple statistics.

Generative performance of DCLDM

The analysis on real-world imaging datasets relies on images generated with our DCLDM (see Fig 5). Therefore, we conduct an additional set of experiments to validate its generative performance. We focus on two key aspects: (1) The reconstructed image preserves the essential anatomical and pathological features of the original image; (2) the detected racial attribute of the reconstructed image is consistent with the counterfactual label.

Experimental setup

We take two steps to build the DCLDM: Step 1: We train a standard CLDM, which consists of an encoder, a decoder and an inner latent diffusion model, on the two image datasets. Step 2: We train the disentangling transformation that creates the counterfactual latent representation (see App. D.1 and App. D.2 for implementation details).

Evaluation metric

We evaluate our model and baselines using two complementary metrics. First, Effectiveness Accuracy measures how well the model achieves the desired counterfactual attribute. Specifically, it is defined as the proportion of generated images whose predicted racial label matches the conditioning label provided during generation. For this evaluation, we employ a high-performance ResNet-101 (see App. D.3) classifier pre-trained to detect racial attributes from images. Second, the Fréchet Inception Distance (FID) assesses the overall quality of the generated images by comparing the statistical properties of their features to those of real images, with lower FID scores indicating higher realism. Fig 5 illustrates representative samples generated by our DCLDM alongside their original counterparts.

Validating the absence of artifacts in image generation

A central requirement for validating our generative framework is to ensure that the synthesis process does not introduce spurious artifacts or detectable digital fingerprints. If such irregularities were present, they could bias downstream diagnostic models toward exploiting unintended visual cues rather than clinically meaningful content. To address this concern, we design experiments that explicitly evaluate whether generated images are visually indistinguishable from authentic ones, thereby testing the fidelity of the generative process.

Evaluation metric

We assess the presence of artifacts using an adversarial evaluation strategy. For the ResNet-101 models trained as above, we measure performance using the AUC-ROC metric. Chance-level AUC-ROC scores indicate that the classifier cannot distinguish between the two sets of images, providing strong evidence that the generative process does not introduce detectable artifacts.

Effectiveness of signal removal for the sensitive attribute

In addition to verifying that our method does not introduce artifacts, we conduct a further experiment to evaluate an equally important property: the removal of signals associated with self-reported race during the generative process. The motivation behind this experiment is to determine whether our counterfactual generator can effectively eliminate identifiable demographic information from images, thereby reducing the ability of downstream models to distinguish between self-identified racial groups after conversion.

Evaluation metrics

To quantify the extent of signal removal, we use the area under the ROC curve (AUC) as the primary evaluation metric of the ResNet-101 model trained as described above. A high baseline AUC indicates that real images from different self-identified racial groups are easily separable by the classifier. After applying the counterfactual conversion, a substantial reduction in AUC would suggest that demographic cues linked to self-reported race have been effectively reduced, since the classifier is no longer able to distinguish between groups.

Discussion

The proposed counterfactual invariance test via latent representations has significant implications for fairness in medical AI. The method explores the deep causal mechanism of the diagnostic models, revealing dependencies, which are overlooked by traditional association-based metrics. Through quantifying the biases linked to the sensitive attribute, our method identifies the diagnostic models’ undesirable dependencies across demographic groups, reducing the risk of misdiagnosis. Overall, this work advances responsible AI in healthcare, encouraging further improvement of AI fairness.

However, challenges are also present. For instance, the hard-to-control variance and complexity of diffusion models make the generative model hard to train. In addition to model complexity, computational efficiency is another practical consideration. Although our experiments were conducted on accessible hardware—a single CPU (Intel Core i7, 16 GB RAM) and one NVIDIA A100 GPU (48 GB)—future work could explore more lightweight architectures or apply model-distillation techniques to further reduce computational demands and enhance accessibility across institutions.

In the experiment, we rely on this proxy measure ECA to assess alignment of the test framework, which, while informative, is inherently limited in its ability to fully capture true causal effects. We acknowledge that this introduces a degree of uncertainty in our evaluation. However, this approach reflects a broader constraint in the field, where ethical, logistical, and practical considerations prevent direct observation of counterfactuals.

The validity of the CIT-LR relies on the DCLDM’s ability to satisfy the causal disentanglement assumption. Failure modes might occur if 1) the sensitive information is not fully disentangled, or 2) the decoder introduces anatomical artifacts which get perceived as disease markers by the diagnostic model. In such cases, the test might reject a fair model or accept an unfair model. For this reason, diagnostics on the DCLDM (e.g., real-vs-synthetic AUC near 0.5, stable FID across groups, and qualitative inspection by domain experts) should be conducted to ensure the correct functioning of the method.

Future work should aim to refine these representations and address unobserved confounding and expand the methodology to cover a broader range of problems. Although our study focused on self-reported race, it is interesting to extend this framework to other factors such as hospital location or imaging site. Because imaging devices and acquisition protocols vary across institutions, exploring these sources of variation represents an important next step. Doing so could enable fairness evaluation across diverse clinical environments and lead to models that generalize more effectively across healthcare systems. More broadly, the framework is modality-agnostic: any setting where a conditional generator can approximate counterfactual image generation admits the use of our CIT-LR. Extending beyond chest X-rays to CT/MRI/ultrasound or dermoscopy would primarily require a modality-specific CLDM, e.g., a 3D CLDM for brain imaging. This highlights the broader applicability of our approach and opens a clear pathway for future work across diverse medical imaging settings.