Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🧠 Text-Conditioned Latent Diffusion for Contrast-Enhanced CT Synthesis
|
| 2 |
+
|
| 3 |
+
**Model Name**: `TUMSyn/ct-noncontrast-to-contrast`
|
| 4 |
+
**Model Type**: Fine-tuned `Stable Diffusion v1.5` for medical image-to-image translation
|
| 5 |
+
**Paper**: _Text-Conditioned Latent Diffusion Model for Synthesis of Contrast-Enhanced CT from Non-Contrast CT_
|
| 6 |
+
**Conference**: AAPM 2025 (Oral)
|
| 7 |
+
**Authors**: Mingjie Li, Yizheng Chen, Lei Xing, Michael Gensheimer
|
| 8 |
+
**Affiliation**: Stanford Radiation Oncology Department
|
| 9 |
+
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
## 🧬 Model Description
|
| 13 |
+
|
| 14 |
+
This model is a fine-tuned version of **Stable Diffusion v1.5**, specialized for converting **non-contrast CT images** into **contrast-enhanced CT images**, guided by **textual phase prompts** (e.g., *venous phase*, *arterial phase*). It utilizes the `InstructPix2Pix` framework to enable flexible prompt-conditioned generation, enabling control over contrast timing without requiring explicit paired data.
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## 💡 Key Features
|
| 19 |
+
|
| 20 |
+
- 🧾 **Text-guided control** over contrast phase (arterial vs. venous)
|
| 21 |
+
- 🖼️ Processes **2D CT slices** in image format (converted from DICOM)
|
| 22 |
+
- 🏥 Focused on **clinical realism and anatomical fidelity**
|
| 23 |
+
- 🧠 Reconstructs full 3D volume with NIfTI output support
|
| 24 |
+
- ✅ Evaluated and presented as **Oral at AAPM 2025**
|
| 25 |
+
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
## 🛠️ Usage
|
| 29 |
+
|
| 30 |
+
### 🔧 Requirements
|
| 31 |
+
```bash
|
| 32 |
+
pip install diffusers==0.25.0 nibabel pydicom tqdm pillow
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### 📦 Load the Model
|
| 36 |
+
```python
|
| 37 |
+
from diffusers import StableDiffusionInstructPix2PixPipeline
|
| 38 |
+
import torch
|
| 39 |
+
|
| 40 |
+
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
|
| 41 |
+
"TUMSyn/ct-noncontrast-to-contrast", torch_dtype=torch.float16
|
| 42 |
+
).to("cuda")
|
| 43 |
+
generator = torch.Generator("cuda").manual_seed(0)
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
### 📝 Example Prompts
|
| 47 |
+
|
| 48 |
+
- **Arterial Phase**
|
| 49 |
+
```
|
| 50 |
+
Convert this non-contrast CT slice to mimic an arterial-phase contrast-enhanced CT.
|
| 51 |
+
Brighten and enhance the aorta, major arteries, and adjacent organ boundaries.
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
- **Venous Phase**
|
| 55 |
+
```
|
| 56 |
+
Convert this non-contrast CT slice to mimic a venous-phase contrast-enhanced CT.
|
| 57 |
+
Brighten and enhance the portal and hepatic veins and emphasize organ boundaries.
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### 🧪 Full Pipeline Example
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
import os
|
| 64 |
+
import numpy as np
|
| 65 |
+
import nibabel as nib
|
| 66 |
+
from PIL import Image
|
| 67 |
+
from glob import glob
|
| 68 |
+
from tqdm import tqdm
|
| 69 |
+
from pydicom import dcmread
|
| 70 |
+
from diffusers import StableDiffusionInstructPix2PixPipeline
|
| 71 |
+
|
| 72 |
+
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
|
| 73 |
+
"TUMSyn/ct-noncontrast-to-contrast", torch_dtype=torch.float16
|
| 74 |
+
).to("cuda")
|
| 75 |
+
generator = torch.Generator("cuda").manual_seed(0)
|
| 76 |
+
|
| 77 |
+
prompt = "Convert this non-contrast CT slice to mimic a venous-phase contrast-enhanced CT. Brighten and enhance the portal and hepatic veins, and emphasize organ boundaries."
|
| 78 |
+
|
| 79 |
+
def load_dicom_folder(dicom_folder):
|
| 80 |
+
dicom_folder = os.path.join(dicom_folder, 'DICOM')
|
| 81 |
+
files = sorted(glob(os.path.join(dicom_folder, "*")))
|
| 82 |
+
slices = [dcmread(f).pixel_array.astype(np.float32) for f in files]
|
| 83 |
+
volume = np.stack(slices, axis=0)
|
| 84 |
+
volume += dcmread(files[0]).RescaleIntercept
|
| 85 |
+
volume = np.clip(volume, -1000, 1000)
|
| 86 |
+
return (volume + 1000) / 2000.0
|
| 87 |
+
|
| 88 |
+
def process(volume):
|
| 89 |
+
results = []
|
| 90 |
+
for i in tqdm(range(volume.shape[0])):
|
| 91 |
+
img = Image.fromarray((volume[i] * 255).astype(np.uint8)).convert("RGB")
|
| 92 |
+
out = pipe(prompt, image=img, num_inference_steps=20,
|
| 93 |
+
image_guidance_scale=1.5, guidance_scale=10,
|
| 94 |
+
generator=generator).images[0]
|
| 95 |
+
gray = np.array(out.convert("L")).astype(np.float32) / 255.0
|
| 96 |
+
gray = gray * 2000 - 1000
|
| 97 |
+
results.append(gray)
|
| 98 |
+
return np.stack(results, axis=0)
|
| 99 |
+
|
| 100 |
+
def save_nifti(volume, path):
|
| 101 |
+
nib.save(nib.Nifti1Image(volume, np.eye(4)), path)
|
| 102 |
+
|
| 103 |
+
input_path = "/path/to/dicom_folder"
|
| 104 |
+
output_path = "/path/to/output.nii.gz"
|
| 105 |
+
|
| 106 |
+
vol = load_dicom_folder(input_path)
|
| 107 |
+
out_vol = process(vol)
|
| 108 |
+
save_nifti(out_vol, output_path)
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
## 🧠 Intended Use
|
| 114 |
+
|
| 115 |
+
- Medical research and simulation
|
| 116 |
+
- Data augmentation for contrast-enhanced imaging
|
| 117 |
+
- Exploratory analysis in non-contrast → contrast CT enhancement
|
| 118 |
+
|
| 119 |
+
> ⚠️ **Disclaimer**: This model is for research purposes only. It is not intended for clinical decision-making or diagnostic use.
|
| 120 |
+
|
| 121 |
+
---
|
| 122 |
+
|
| 123 |
+
## 📝 Citation
|
| 124 |
+
|
| 125 |
+
```
|
| 126 |
+
@inproceedings{li2025text,
|
| 127 |
+
title={Text-Conditioned Latent Diffusion Model for Synthesis of Contrast-Enhanced CT from Non-Contrast CT},
|
| 128 |
+
author={Li, Mingjie and Chen, Yizheng and Xing, Lei and Gensheimer, Michael},
|
| 129 |
+
booktitle={AAPM Annual Meeting (Oral)},
|
| 130 |
+
year={2025}
|
| 131 |
+
}
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
---
|
| 135 |
+
|
| 136 |
+
## 🧾 License
|
| 137 |
+
|
| 138 |
+
This model is released for **non-commercial research purposes only**. Please contact the authors if you wish to use it in clinical or commercial settings.
|