Generative Medical Image Anonymization Based on Latent Code Projection and Optimization

Huiyu Li, Nicholas Ayache, Hervé DelingettearXiv 2025

TL;DR

This paper introduces a two-stage generative framework for medical image anonymization that precisely projects chest X-rays into a StyleGAN2 latent space using a novel co-training scheme. By optimizing the resulting latent codes with dedicated identity-removal and utility-preserving loss functions, the method successfully strips away patient-identifying features while retaining critical diagnostic information for downstream AI models.

What Problem Does This Paper Address?

Sharing medical imaging datasets is crucial for advancing healthcare AI, but it poses severe patient privacy risks. Medical images contain unique structural and biometric features that can be exploited by re-identification attacks.

Traditional anonymization methods often fail to balance the trade-off between privacy and utility. For instance, some methods synthesize entirely new datasets but drastically reduce the dataset size or lack clinical interpretability. Other approaches leverage Generative Adversarial Networks (GANs) via "GAN inversion" to find the latent representation of an image, but standard inversion techniques struggle to perfectly reconstruct medical images, often erasing subtle, crucial diagnostic details. This paper tackles the challenge of removing patient identity from X-rays while perfectly preserving clinical utility.

Methods

The authors propose a two-stage solution: Latent Code Projection followed by Latent Code Optimization.

Fig. 1. Overview of the proposed method, consisting of two key stages: (1) AE-GAN network for latent code projection, and (2) Latent code optimization using identity removal loss and utility-preserving losss.
  1. Latent Code Projection (AE-GAN): Instead of using the classic "$\mathcal{E}$-training" approach (where an encoder is trained against a fixed, pre-trained generator), the authors introduce a co-training scheme. A custom encoder ($\mathcal{E}$) and a StyleGAN2 generator ($\mathcal{G}$) are jointly optimized using a composite loss function combining pixel-wise similarity, perceptual similarity, and adversarial loss. This symmetry allows for highly accurate image reconstruction.
  2. Latent Code Optimization: Once the real image is projected into the latent space ($W$), this code is used to initialize an anonymized latent code ($W_A$). $W_A$ is then optimized using two deep loss functions:
  3. Identity Loss ($\mathcal{L}_{id}$): Utilizes a pre-trained identity encoder ($\mathcal{E}_{id}$) to force the anonymized image's identity features away from the real image (aiming for a feature vector angle $\theta \ge 90^\circ$).
  4. Utility Loss ($\mathcal{L}_{ut}$): Utilizes a pre-trained utility encoder ($\mathcal{E}_{ut}$) to ensure that diagnostic features (like those indicating lung pathologies) remain identical ($\theta = 0^\circ$).

Datasets

The method was evaluated on the MIMIC-CXR-JPG dataset, a large publicly available collection of chest X-rays.

  • To ensure robust identity tracking, the authors filtered the dataset to include only patients with 20 or more images.
  • This resulted in a dataset split of 50,875 training images, 522 validation images, and 1,641 test images.
  • The downstream utility task was lung pathology classification, while the identity task focused on predicting patient IDs.

Key Insights and Ideas

  • Co-training Prevents Information Loss: Jointly training the encoder and generator, rather than freezing the generator, prevents the loss of fine structural details. This is a critical adjustment for medical imaging, where a few pixels can differentiate a healthy lung from a pathological one.
  • Decoupling Inner vs. Outer Risk: The optimization successfully breaks outer linkability (preventing an attacker from matching an anonymized image back to its real-world source) while maintaining inner linkability (ensuring that different anonymized images from the same patient still cluster together). This allows longitudinal patient studies to continue safely without exposing real patient identities.
  • Immunity to Membership Inference: The anonymization process proved highly effective against Membership Inference Attacks (MIA), dropping the attacker's ability to identify if an image was part of the training set down to an accuracy of zero.

Key Results

  • Superior Reconstruction: The proposed co-training scheme significantly outperformed standard $\mathcal{E}$-training, boosting Peak Signal-to-Noise Ratio (PSNR) from 19.477 to 24.319 and Structural Similarity Index (SSIM) from 0.936 to 0.968.
  • High Utility Retention: Classifiers trained on the fully anonymized dataset ($\mathcal{L}_{ut} + \mathcal{L}_{id}$) achieved an AUROC of 0.737 and an F1-score of 0.531, which closely rivals models trained on completely unaltered real data (AUROC 0.774, F1 0.511).
Table 2. Results of utility preservation. ’Acc’: accuracy, ’AP’: average precision, ’AUROC’: area under the ROC curve, ’F1’: F1 score.
  • Robust Privacy Protection: When evaluating outer risk, the True Accept Rate (TAR) dropped to exactly 0.000, meaning it is mathematically impossible for the identity classifier to link the anonymized image back to the patient's real image. Furthermore, the "local cloaking" metric (the median number of images blending with the anonymized image) jumped from 41 to over 1,500, drastically reducing singling-out risks.
Fig. 3. Anonymization results. Real images XR randomly se- lected from the training, validation, and test sets are displayed in the first column. The corresponding reconstructed images ˆXR are displayed in the second column. The anonymized im- ages XA are displayed in the last three columns.

Limitations and Future Work

While the results are promising, the paper leaves a few areas open for future exploration:

  • Single Modality Testing: The framework was exclusively validated on 2D chest X-rays. Its efficacy on 3D volumes (like CT or MRI scans) or other complex imaging modalities remains unproven.
  • Dependency on Pre-trained Encoders: The optimization phase relies entirely on the performance of the pre-trained identity and utility encoders. If the utility encoder wasn't trained to recognize a specific rare pathology, that clinical feature might inadvertently be scrubbed during the anonymization process.

Summary updated

BibTeX
@misc{li2025generative,
  author = {Huiyu Li and Nicholas Ayache and Hervé Delingette},
  title = {{Generative Medical Image Anonymization Based on Latent Code Projection and Optimization}},
  year = {2025},
  eprint = {2501.09114},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2501.09114},
}

Loading related content...

Figure