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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# <div align="center">MedSynV2: Flexible Control of 3D CT Generation via Text and Semantically-Defined Segmentation Prompts</div>
|
| 2 |
+
|
| 3 |
+
<p align="center">
|
| 4 |
+
<b>Weicheng Dai</b><sup>1</sup>,
|
| 5 |
+
Chenyu Wang<sup>1</sup>,
|
| 6 |
+
Shantanu Ghosh<sup>1</sup>,
|
| 7 |
+
Kayhan Batmanghelich<sup>1</sup><sup>*</sup>
|
| 8 |
+
<br/>
|
| 9 |
+
<sup>1</sup>Department of Electrical and Computer Engineering, Boston University
|
| 10 |
+
<br/>
|
| 11 |
+
<sup>*</sup>Corresponding author
|
| 12 |
+
</p>
|
| 13 |
+
|
| 14 |
+
<p align="center">
|
| 15 |
+
<i>ECCV 2026</i>
|
| 16 |
+
</p>
|
| 17 |
+
<p align="center">
|
| 18 |
+
<a href="assets/ECCV_2026_medsynv2.pdf">📄 Read the manuscript (ECCV 2026)</a>
|
| 19 |
+
</p>
|
| 20 |
+
|
| 21 |
+
<p align="center">
|
| 22 |
+
<!-- <a href=""><img src="https://img.shields.io/badge/Paper-ECCV%202026-blue"/></a> -->
|
| 23 |
+
</p>
|
| 24 |
+
|
| 25 |
---
|
| 26 |
+
|
| 27 |
+
## 🧠 Overview
|
| 28 |
+
|
| 29 |
+
**MedSynV2** is a **flexible multimodal framework for controllable 3D medical image generation**, designed to overcome the limitations of existing text-only or segmentation-only conditioning methods.
|
| 30 |
+
|
| 31 |
+
Our model supports **optional and partial conditioning** from:
|
| 32 |
+
- 📝 **Radiology reports** (semantic, flexible)
|
| 33 |
+
- 🧩 **Segmentation prompts** (precise, spatial)
|
| 34 |
+
|
| 35 |
+
Crucially, MedSynV2 **does not require full-organ annotations**.
|
| 36 |
+
Users may provide segmentation for a *specific anatomy or abnormality*, whose semantic meaning is specified through an accompanying text description.
|
| 37 |
+
|
| 38 |
+
This design enables **scalable, fine-grained control** over volumetric generation while maintaining high image fidelity.
|
| 39 |
+
For the full technical details, method description, and experimental results, please see [our manuscript](assets/ECCV_2026_medsynv2.pdf).
|
| 40 |
+
|
| 41 |
---
|
| 42 |
+
|
| 43 |
+
## ✨ Key Features
|
| 44 |
+
|
| 45 |
+
- 🔀 **Multimodal conditioning**: text-only, segmentation-only, or both
|
| 46 |
+
- 🧩 **Partial segmentation support** (no full-organ masks required)
|
| 47 |
+
- 🧠 **Strong semantic grounding** via text-described segmentation prompts
|
| 48 |
+
- ⚡ **Memory-efficient diffusion transformer** for high-resolution 3D volumes
|
| 49 |
+
- 🔍 **Gated attention** for long radiology reports
|
| 50 |
+
- 🧬 Generates **anatomically consistent, high-resolution CT volumes**
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## 🧩 Method Overview
|
| 55 |
+
|
| 56 |
+
<p align="center">
|
| 57 |
+
<img src="assets/medsynv2_overview.png" width="90%"/>
|
| 58 |
+
</p>
|
| 59 |
+
|
| 60 |
+
<p align="center">
|
| 61 |
+
<a href="assets/medsynv2_overview.pdf">📄 View full-resolution PDF</a>
|
| 62 |
+
</p>
|
| 63 |
+
|
| 64 |
+
MedSynV2 extends diffusion transformers to jointly process:
|
| 65 |
+
- Image tokens
|
| 66 |
+
- Segmentation tokens
|
| 67 |
+
- Text tokens from radiology reports
|
| 68 |
+
|
| 69 |
+
A gated attention mechanism enables effective conditioning on **long, unstructured clinical text**, while preserving spatial controllability through segmentation prompts.
|
| 70 |
+
|
| 71 |
+
---
|
| 72 |
+
|
| 73 |
+
## 📊 Results Summary
|
| 74 |
+
|
| 75 |
+
We evaluate MedSynV2 on **large-scale 3D CT datasets**, using:
|
| 76 |
+
|
| 77 |
+
- **Perceptual metrics** (FID, SSIM, PSNR)
|
| 78 |
+
- **Semantic consistency metrics**
|
| 79 |
+
- **Radiologist evaluation**
|
| 80 |
+
|
| 81 |
+
### Key findings:
|
| 82 |
+
- 🚀 **~24% relative improvement in mean FID**
|
| 83 |
+
- 🧠 Strong semantic alignment between generated and real CT volumes
|
| 84 |
+
- 🧬 High-resolution, anatomically coherent synthesis
|
| 85 |
+
- 📈 Improved **data efficiency** when used for data augmentation
|
| 86 |
+
- 🌱 Generalization to concepts beyond training distribution
|
| 87 |
+
|
| 88 |
+
<p align="center">
|
| 89 |
+
<img src="assets/results_modifyingMask.png" width="90%"/>
|
| 90 |
+
</p>
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
## 📦 Code Status
|
| 95 |
+
|
| 96 |
+
The full release will include:
|
| 97 |
+
- Model architecture and diffusion transformer implementation
|
| 98 |
+
- Multimodal conditioning pipelines
|
| 99 |
+
- Inference scripts
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
### 0. Create conda environment
|
| 103 |
+
```
|
| 104 |
+
conda env create -f environment.yml
|
| 105 |
+
```
|
| 106 |
+
If flash-attention raises issue, please follow the original [github](https://github.com/dao-ailab/flash-attention) and compile `flash-attn==2.7.4.post1`.
|
| 107 |
+
|
| 108 |
+
### 1. Download pretrained models
|
| 109 |
+
|
| 110 |
+
| pretrained model components | Checkpoints |
|
| 111 |
+
|----------------------------------|------------------------------------------------------------------------------------------------------------------------------|
|
| 112 |
+
| Text model (same as [MedSyn](https://github.com/batmanlab/MedSyn/tree/main)) | [pretrained_lm](https://www.dropbox.com/scl/fi/d6tg6si72nnjfa87vawsl/pretrained_lm.gz?rlkey=fcnyrmy1i3xi9frzjchc68kh3&st=gq6xofnh&dl=0) |
|
| 113 |
+
| MedSynV2 Generator | [final_ckpt](https://huggingface.co/batmanLab/MedSynV2/tree/main/final_ckpt) |
|
| 114 |
+
| OpenSora checkpoint | [vae.ckpt](https://huggingface.co/batmanLab/MedSynV2/blob/main/vae.ckpt) |
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
### 2.1 If you prefer report, extract text features
|
| 118 |
+
Here's an example.
|
| 119 |
+
```
|
| 120 |
+
cd src
|
| 121 |
+
python extract_text_feature.py --prompt 'There is no airspace opacity, effusion or pneumothorax. There is no evidence of suspicious pulmonary nodule or mass.' \
|
| 122 |
+
--text_model_path './model/pretrained_lm' \
|
| 123 |
+
--save_path './result/text_feature/normal.npy'
|
| 124 |
+
```
|
| 125 |
+
### 2.2 Latent feature generation
|
| 126 |
+
```
|
| 127 |
+
cd src
|
| 128 |
+
python medsynv2_DiT_reportonly.py --text_feature_folder './text_feature' \
|
| 129 |
+
--pretrain_model_path ./model/medsynv2_dit_x0.pth \
|
| 130 |
+
--save_path './tmp/medsynv2_dit_x0_results_reportonly'
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
### 2.3 OpenSora decoding
|
| 134 |
+
```
|
| 135 |
+
cd opensora/osp
|
| 136 |
+
python examples/recon_ct.py --pretrained_model_path './model/vae.ckpt' \
|
| 137 |
+
--folder './tmp/medsynv2_dit_x0_results_reportonly' \
|
| 138 |
+
--save_folder './tmp/medsynv2_dit_x0_results_reportonly_SR'
|
| 139 |
+
```
|
| 140 |
+
if you need to convert it to nifti
|
| 141 |
+
```
|
| 142 |
+
python examples/convert.py --folder './tmp/medsynv2_dit_x0_results_reportonly_SR' \
|
| 143 |
+
--save_folder './tmp/medsynv2_dit_x0_results_reportonly_SR_nii'
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
### 3.1 If you need masks encoded, encode the mask first
|
| 147 |
+
We encode the masks with batch_index from 0 to 5, as a 48GB GPU will only handle this size.
|
| 148 |
+
After running, concatenate them along the depth axis (trivial).\
|
| 149 |
+
Make sure your masks are binary masks. \
|
| 150 |
+
Note we extract contours of lobes with `encode_masks_lobe.py`
|
| 151 |
+
```
|
| 152 |
+
cd opensora/osp
|
| 153 |
+
python examples/encode_masks.py --batch_index 0 \ # you should use 0~5 here
|
| 154 |
+
--pretrained_model_path './model/vae.ckpt' \
|
| 155 |
+
--folder 'YOUR NIFTI MASKS' \
|
| 156 |
+
--save_folder 'YOUR MASKS_LATENTS FOLDER'
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
### 3.2 (Optional) If you need reports as well, follow 2.1 above
|
| 160 |
+
Otherwise create some dummy npy files in the `text_feature` folder, just as file name indicator.
|
| 161 |
+
|
| 162 |
+
### 3.3 Latent feature generation with mask features (and reports)
|
| 163 |
+
Make sure you check [line 559](https://github.com/batmanlab/MedSynV2/blob/26f2dde890eb2dfa079c1944f9e26c7fd32c954c/src/medsynv2_DiT_masks.py#L559) and put corresponding masks into each folders.
|
| 164 |
+
The pre-conditions (indicating which masks) are already extracted and [uploaded](https://github.com/batmanlab/MedSynV2/tree/main/extra_prompts_gen).
|
| 165 |
+
```
|
| 166 |
+
cd src
|
| 167 |
+
python medsynv2_DiT_reportonly.py --text_feature_folder './text_feature' \
|
| 168 |
+
--mask_folder 'YOUR MASKS_LATENTS FOLDER' \
|
| 169 |
+
--pretrain_model_path ./model/medsynv2_dit_x0.pth \
|
| 170 |
+
--save_path './tmp/medsynv2_dit_x0_results_report_mask' \
|
| 171 |
+
--include_report
|
| 172 |
+
|
| 173 |
+
```
|
| 174 |
+
| anatomy / abnormality | corresponding suffix index |
|
| 175 |
+
|----------------------------------|------------------------------------------------------------------------------------------------------------------------------|
|
| 176 |
+
| lobes | 1 |
|
| 177 |
+
| airways | 2 |
|
| 178 |
+
| vessel | 3 |
|
| 179 |
+
| heart | 4 |
|
| 180 |
+
| consolidation | 5 |
|
| 181 |
+
| ground glass opacity | 6 |
|
| 182 |
+
| pericardial effusion | 7 |
|
| 183 |
+
| pleural effusion | 8 |
|
| 184 |
+
| nodule | 9 |
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
### 3.4 OpenSora Decoding
|
| 188 |
+
The same as 2.3
|
| 189 |
+
|
| 190 |
+
### If you find any issue implementing the inference, please let us know
|
| 191 |
+
|
| 192 |
+
## License and copyright
|
| 193 |
+
The source code is Licensed under [Apache License 2.0](https://github.com/batmanlab/MedSynV2/blob/main/LICENSE.txt).
|
| 194 |
+
Model weights is Licensed
|
| 195 |
+
under [Custom Academic License for Model Weights](https://github.com/batmanlab/MedSynV2/blob/main/LICENSE_WEIGHTS.txt).
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
---
|
| 199 |
+
## 📚 Citation
|
| 200 |
+
|
| 201 |
+
If you find this work useful, please cite:
|
| 202 |
+
|
| 203 |
+
```bibtex
|
| 204 |
+
@InProceedings{dai2026medsynv2,
|
| 205 |
+
author="Dai, Weicheng
|
| 206 |
+
and Wang, Chenyu
|
| 207 |
+
and Ghosh, Shantanu
|
| 208 |
+
and Batmanghelich, Kayhan",
|
| 209 |
+
editor="Favaro, Paolo
|
| 210 |
+
and Kukelova, Zuzana
|
| 211 |
+
and Maki, Atsuto
|
| 212 |
+
and Rohrbach, Anna
|
| 213 |
+
and Schindler, Konrad
|
| 214 |
+
and Tombari, Federico",
|
| 215 |
+
title="MedSynV2: Flexible Control of 3D CT Generation via Text and Semantically-Defined Segmentation Prompts",
|
| 216 |
+
booktitle="Computer Vision -- ECCV 2026",
|
| 217 |
+
year="2026",
|
| 218 |
+
publisher="Springer Nature Switzerland",
|
| 219 |
+
address="Cham",
|
| 220 |
+
pages="396--413",
|
| 221 |
+
isbn="978-3-032-37517-9"
|
| 222 |
+
}
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
## Credits
|
| 226 |
+
The code is heavily based on [MedSyn](https://github.com/batmanlab/MedSyn/tree/main) and [OpenSoraPlan](https://github.com/PKU-YuanGroup/Open-Sora-Plan).
|