MedSegFactory: Text-Guided Generation of Medical Image-Mask Pairs

Jiawei Mao, Yuhan Wang, Yucheng Tang, Daguang Xu, Kang Wang, Yang Yang, Zongwei Zhou, Yuyin Zhou

TL;DR

This paper introduces MedSegFactory, a novel framework that generates paired medical images and their corresponding segmentation masks using only text prompts. This approach addresses the critical bottleneck of data scarcity and annotation costs in medical imaging by enabling on-demand, high-quality synthetic data generation.

What Problem Does This Paper Address?

Medical imaging plays a crucial role in diagnosis, treatment planning, and monitoring. However, the widespread adoption of AI-powered medical image analysis tools is hampered by the high cost and effort required to create large, annotated datasets. Acquiring and annotating medical data is expensive, time-consuming, and often restricted by strict privacy regulations and ethical considerations, limiting data sharing between institutions. While synthetic data generation offers a promising solution, existing methods have limitations:

  • Unconditional generation: Lacks control over the generated content.
  • Unconditional paired generation: Generates image-mask pairs but without fine-grained control.
  • Conditional generation (image): Generates images based on masks but doesn't produce the masks themselves.
  • Conditional generation (image guided by masks): Requires detailed, pre-existing segmentation masks, which are precisely what's expensive and difficult to obtain.

This paper tackles the challenge of generating both high-quality medical images and their corresponding segmentation masks in a controlled and scalable manner, directly from user-defined text descriptions.

Methods

MedSegFactory is built upon a dual-stream diffusion model, inspired by Stable Diffusion. It consists of two parallel streams: one for synthesizing medical images and the other for generating segmentation masks.

The core innovation is the Joint Cross-Attention (JCA) mechanism. This mechanism allows the intermediate representations from both the image and mask generation streams to dynamically condition each other during the denoising process. This bidirectional interaction ensures that the generated image and mask are precisely aligned and semantically consistent. Instead of relying on pre-defined masks, JCA enables a collaborative refinement where the evolving image representation guides mask generation, and vice-versa.

The process involves:

  1. Encoding paired medical images and masks into latent representations.
  2. Adding noise to these latent representations.
  3. Denoising these noisy representations using a Diffusion UNet, enhanced by JCA.
  4. Decoding the denoised latent representations back into a synthetic medical image and its corresponding segmentation mask.

The model is trained to minimize the difference between the predicted noise and the actual noise in both streams, guided by text prompts.

Datasets

The paper utilizes several publicly available medical segmentation datasets for training and evaluation, covering various modalities and tasks:

  • AMOS (Abdominal Multi-Organ Segmentation)
  • ACDC (Automated Cardiac Diagnosis Challenge)
  • BUSI (Breast Ultrasound Images Dataset)
  • KiTS19 (Kidney Tumor Segmentation Challenge)
  • LiTS17 (Liver Tumor Segmentation Challenge)
  • CVC-ClinicDB and Kvasir-SEG (Colonoscopy datasets)

These datasets encompass 2D slices and 3D volumes from CT scans, MRI, and ultrasound.

Key Insights and Ideas

  • Text-guided generation for paired data: The most significant insight is the shift from mask-guided or unconditional generation to text-guided generation of paired image-mask data. This unlocks a new paradigm for synthetic medical data creation.
  • JCA for semantic alignment: The Joint Cross-Attention mechanism is crucial. It moves beyond simple cross-conditioning by enabling mutual refinement between image and mask streams, leading to superior alignment and consistency, which is vital for medical applications.
  • Addressing data scarcity directly: By generating unlimited, high-quality synthetic data, MedSegFactory directly tackles the pervasive issue of data scarcity and annotation costs in medical AI research.
  • Versatility across modalities and tasks: The framework is designed to be versatile, capable of generating data for diverse medical imaging tasks and modalities, as demonstrated by its performance across multiple datasets.

Key Results

  • High-quality image generation: MedSegFactory produces anatomically accurate, high-quality medical images with fewer artifacts and better structural integrity compared to baseline methods like SDM, ControlNet, and DiffBoost.
  • Superior alignment: Qualitative comparisons (Figure 5) show that MedSegFactory achieves significantly better alignment between generated images and their corresponding segmentation masks, a common failure point in other methods.
  • Improved segmentation performance: When the synthetic data generated by MedSegFactory is used to augment training datasets for downstream segmentation tasks (using nnUNet), it leads to significant performance improvements. For example, on ACDC, BUSI, and CVC-ClinicDB datasets, MedSegFactory-augmented training achieved higher DSC and IoU scores compared to baselines and even the nnUNet trained solely on real data.
  • Quantitative metrics: MedSegFactory achieved competitive or state-of-the-art performance in terms of Inception Score (IS) and Fréchet Inception Distance (FID) for image generation and Dice coefficients (DSC) and Intersection over Union (IoU) for segmentation tasks.

Limitations and Future Work

  • Blurred boundaries in target-free generation: When generating images without explicit segmentation targets (i.e., relying solely on text prompts without a mask stream), the model can sometimes produce blurred or imprecise anatomical boundaries. The authors suggest refining prompt design and attention-masking strategies to mitigate this.
  • 2D architecture: The current framework is designed for 2D medical images. Extending it to handle 3D volumetric data, which is critical for CT/MRI imaging, is identified as a key direction for future work.

Summary updated

BibTeX
@inproceedings{mao2025medsegfactory,
  author = {Jiawei Mao and Yuhan Wang and Yucheng Tang and Daguang Xu and Kang Wang and Yang Yang and Zongwei Zhou and Yuyin Zhou},
  title = {{MedSegFactory: Text-Guided Generation of Medical Image-Mask Pairs}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2025},
}
Figure