Mask-Guided Attention Regulation for Anatomically Consistent Counterfactual CXR Synthesis

Zichun Zhang, Weizhi Nie, Honglin Guo, Yuting SuarXiv 2026

TL;DR

Generating counterfactual chest X-rays (e.g., adding or removing a medical condition from an existing scan) using diffusion models often distorts healthy anatomy or fails to accurately localize the disease. This paper introduces a training-free, inference-time attention regulation framework that uses organ masks to constrain self-attention and boost pathology-specific cross-attention. The result is highly controllable, anatomically consistent medical image editing without the need for costly model retraining.

What Problem Does This Paper Address?

Counterfactual medical image generation creates "what-if" scenarios—such as simulating how a patient's chest X-ray (CXR) would look if they developed pleural effusion or cardiomegaly. This is incredibly useful for data augmentation, clinical training, and making AI models more interpretable.

However, state-of-the-art diffusion models struggle with two major issues when editing medical images:

  1. Structural Instability (Structural Drift): Global self-attention mechanisms cause localized changes to leak into non-target regions, inadvertently warping stable structures like healthy lung shapes, ribs, or cardiac contours.
  2. Pathological Expression Instability: Pathological features in X-rays are often subtle and highly localized. Standard text prompts generate weak, noisy cross-attention responses, causing the model to either suppress the lesion entirely or diffuse it uncontrollably.

While existing methods try to fix this by retraining models or adding learnable control branches (like ControlNet), doing so introduces massive computational overhead and fails to scale across different hospitals and evolving imaging devices.

Methods

The authors propose a completely training-free, inference-time attention regulation framework that manipulates the internal attention maps of a pre-trained diffusion model's UNet during the denoising process.

Fig. 1. Overview of our inference-time attention regulation framework for counterfac- tual CXR generation. (a) The input image is encoded by VAE[15], noised, and denoised by a conditional diffusion model to generate a counterfactual image. (b) Anatomy-aware self-attention gating with Manat preserves structural consistency, while (c) pathology- guided cross-attention reweighting with a mask-derived prior Ωlocalizes pathological edits.

The framework consists of three core components:

  • Anatomy-aware Attention Regularization: To prevent structural drift, the framework downsamples an anatomical organ mask ($M_{anat}$) and uses it to gate the model's self-attention maps ($S_t$). This confines spatial interactions strictly to valid anatomical regions of interest (ROIs).
  • Pathology-guided Attention Regulation: To ensure subtle lesions are properly expressed, the framework extracts anatomical cues from the text prompt (e.g., "right lung base") and creates a spatial prior map ($\Omega$). During the early stages of denoising, the cross-attention maps ($A_{t,k}$) for pathology-related tokens are amplified using a soft multiplier map $(1 + \eta\Omega)$.
  • Latent Correction: The authors introduce a differentiable "region concentration score" that measures how well a pathology token's attention map aligns with the target ROI. A lightweight gradient update is then applied directly to the intermediate latent noise vector ($z_t$), steering the denoising trajectory toward precise lesion localization.

Datasets

The framework was evaluated using frontal-view (PA) chest X-ray studies from two prominent open-source datasets:

  • MIMIC-CXR-JPG
  • ChexpertPlus

Images were resized to $512 \times 512$ pixels. Lung masks were automatically generated using HybridGNet, a robust medical image segmentation tool. To ensure clean conditioning signals, the paired radiology reports were pre-processed and compressed into concise prompts using a GPT-based cleaning step.

Key Insights and Ideas

  • Inference-Time Control is Sufficient: You don't need to retrain a massive model or add extra learnable layers to achieve precise medical image editing; regulating the internal attention maps at inference time is highly effective.
  • The Importance of Early Denoising: Both the pathology cross-attention boosting and latent corrections are applied exclusively during the early denoising window ($t < 0.4T$). This reinforces the idea that global layout and pathology localization are locked in during the initial phases of generation, while later phases merely refine fine-grained textures.
  • Disentangling Identity from Disease: By explicitly gating self-attention with anatomical masks and boosting cross-attention with pathology priors, the model successfully decouples the patient's fixed anatomical identity from the transient disease state.

Key Results

The proposed method was compared against several state-of-the-art baselines, including Stable Diffusion (SD) Inpainting, BiomedJourney, ProgEmu, and PIE.

Fig. 2. Qualitative comparison with state-of-the-art counterfactual CXR generation methods. Given the target prompt and the original image, we compare our results with SD-inpainting, PIE, BiomedJourney, and ProgEmu on representative cases.
  • Quantitative Performance: As shown in Table 1, the method achieved the highest pathology classification accuracy (Conf: 0.709) and text-image alignment (CLIP-I: 0.870), while maintaining competitive realism (FID: 29.0) and structural similarity.
  • Ablation Studies: Removing the anatomy-aware self-attention regularization caused the structural similarity (SSIM) to drop significantly (from 0.80 to 0.76), proving its necessity in preventing global structural drift. Conversely, omitting the pathology cross-attention regulation severely degraded pathological accuracy (Conf dropped from 0.71 to 0.66).

Limitations and Future Work

Not explicitly discussed in detail by the authors. However, based on the methodology, potential limitations include a heavy reliance on the accuracy of the external organ segmentation tool (HybridGNet). If the initial mask is flawed, the attention gating will restrict generation incorrectly. Additionally, the deterministic mapping of text cues to spatial priors might struggle with highly complex, multi-localized, or systemic pathologies that span across multiple unmasked organs.

Summary updated

BibTeX
@misc{zhang2026mask,
  author = {Zichun Zhang and Weizhi Nie and Honglin Guo and Yuting Su},
  title = {{Mask-Guided Attention Regulation for Anatomically Consistent Counterfactual CXR Synthesis}},
  year = {2026},
  eprint = {2603.04130},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.04130},
}
Figure