X-Diffusion: Generating Detailed 3D MRI Volumes From a Single Image Using Cross-Sectional Diffusion Models
X-Diffusion is a state-of-the-art deep learning model for generating detailed 3D MRI volumes from single 2D images using cross-sectional diffusion models. This project implements the methods described in our paper, providing a robust framework for medical image synthesis.
- Generate complete 3D MRI volumes from single 2D slices
- Optimized inference with mixed precision support
- Support for BRATS and UK Biobank datasets
- Modular architecture for easy customization
- Comprehensive evaluation metrics (PSNR, SSIM)
- Pre-trained models available
- Docker support for easy deployment
- Documentation
- Python 3.8 or higher
- CUDA 11.0+ (for GPU support)
- 32GB RAM recommended
- 30GB VRAM for training (GPU)
- Clone the repository:
git clone https://github.com/EmmanuelleB985/X-Diffusion.git
cd X-Diffusion- Create a virtual environment:
conda create -n XDiffusion python=3.9
conda activate XDiffusion- Install dependencies:
pip install -r requirements.txt- Install development dependencies (optional):
pip install -r requirements-dev.txt- Install pre-commit hooks (for contributors):
pre-commit install- Download pre-trained models:
# Zero-123 checkpoint
wget https://cv.cs.columbia.edu/zero123/assets/300000.ckpt -P Zero123/
# X-Diffusion checkpoint
tar -xzvf ckpt.tar.gzpython scripts/main.py \
-t \
--base configs/sd-brats-finetune-c_concat-256.yaml \
--gpus 0 \
--scale_lr False \
--num_nodes 1 \
--seed 42 \
--check_val_every_n_epoch 10 \
--finetune_from Zero123/300000.ckpt# Single image inference
python scripts/inference.py \
--model_path checkpoints/best_model.ckpt \
--input_image path/to/image.png \
--output_dir results/
# Batch inference
python scripts/inference.py \
--model_path checkpoints/best_model.ckpt \
--input_dir data/test_images/ \
--output_dir results/ \
--batch_size 4Run all checks:
# Format code
black scripts/ tests/
# Sort imports
isort scripts/ tests/
# Run linting
flake8 scripts/ tests/
# Type checking
mypy scripts/
# Run pylint
pylint scripts/
# Check docstring coverage
interrogate scripts/ -v --fail-under=90Or use pre-commit to run all checks automatically:
pre-commit run --all-filesRun the test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=scripts --cov-report=html
# Run specific test categories
pytest -m unit # Unit tests only
pytest -m integration # Integration tests only
pytest -m "not slow" # Skip slow testsBuild the documentation:
cd docs
make html
# Open docs/_build/html/index.html in your browserDownload the BRATS2023 dataset:
- Create an account on Synapse
- Download the dataset
- Extract to
data/BRATS2023/
Access UK Biobank data:
- Register on the UK Biobank platform
- Follow instructions from UKBiobankDXAMRIPreprocessing
X-Diffusion uses a cross-sectional diffusion approach based on:
- Backbone: Modified Stable Diffusion architecture
- Conditioning: Cross-sectional image embeddings
- Denoising: Progressive refinement through diffusion steps
- 3D Reconstruction: Volumetric assembly from 2D slices
Our model achieves state-of-the-art performance on:
| Dataset | PSNR ↑ | SSIM ↑ | FID ↓ |
|---|---|---|---|
| BRATS | 28.3 | 0.912 | 12.4 |
| UK Biobank | 29.1 | 0.925 | 10.8 |
If you use this code in your research, please cite our paper:
@misc{bourigault2025xdiffusion,
title={X-Diffusion: Generating Detailed 3D MRI Volumes From a Single Image Using Cross-Sectional Diffusion Models},
author={Emmanuelle Bourigault and Abdullah Hamdi and Amir Jamaludin},
year={2025},
eprint={2404.19604},
archivePrefix={arXiv},
primaryClass={eess.IV}
}This project builds upon:
We thank the authors for making their code publicly available.
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions!
- Fork the repository
- Create your feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m 'Add my feature') - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request