Skip to main content

Auto-differentiable digitally reconstructed radiographs in PyTorch

Project description

DiffDRR

Auto-differentiable DRR synthesis and optimization in PyTorch

Build Status Paper shield License: MIT Downloads Docs Code style: black

DiffDRR is a PyTorch-based digitally reconstructed radiograph (DRR) generator that provides

  1. Auto-differentiable DRR syntheisis
  2. GPU-accelerated rendering
  3. A pure Python implementation

Most importantly, DiffDRR implements DRR synthesis as a PyTorch module, making it interoperable in deep learning pipelines.

Installation Guide

To install DiffDRR from PyPI:

pip install diffdrr

To build DiffDRR from source:

git clone https://github.com/eigenvivek/DiffDRR
conda env create -f environment.yaml
conda activate DiffDRR

Usage

The following minimal example specifies the geometry of the projectional radiograph imaging system and traces rays through a CT volume:

import matplotlib.pyplot as plt
import torch

from diffdrr.drr import DRR
from diffdrr.data import load_example_ct
from diffdrr.visualization import plot_drr

# Read in the volume
volume, spacing = load_example_ct()

# Get parameters for the detector
bx, by, bz = torch.tensor(volume.shape) * torch.tensor(spacing) / 2
detector_kwargs = {
    "sdr"   : 300.0,
    "theta" : torch.pi,
    "phi"   : 0,
    "gamma" : torch.pi / 2,
    "bx"    : bx,
    "by"    : by,
    "bz"    : bz,
}

# Make the DRR
drr = DRR(volume, spacing, height=200, delx=4.0).to("cpu")
img = drr(**detector_kwargs)
ax = plot_drr(img)
plt.show()

On a single NVIDIA RTX 2080 Ti GPU, producing such an image takes

</code></pre>
<pre><code>1.38 s ± 89.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

The full example is available at tutorials/introduction.ipynb.

Application: 6-DoF Slice-to-Volume Registration

We demonstrate the utility of our auto-differentiable DRR generator by solving a 6-DoF registration problem with gradient-based optimization. Here, we generate two DRRs:

  1. A fixed DRR from a set of ground truth parameters
  2. A moving DRR from randomly initialized parameters

To solve the registration problem, we use gradient descent to minimize an image loss similarity metric between the two DRRs. This produces optimization runs like this:

The full example is available at experiments/registration.

How does DiffDRR work?

DiffDRR reformulates Siddon’s method[^1], the canonical algorithm for calculating the radiologic path of an X-ray through a volume, as a series of vectorized tensor operations. This version of the algorithm is easily implemented in tensor algebra libraries like PyTorch to achieve a fast auto-differentiable DRR generator.

Citing DiffDRR

If you find DiffDRR useful in your work, please cite our paper (or the freely accessible arXiv version):

@inproceedings{gopalakrishnanDiffDRR2022,
    author    = {Gopalakrishnan, Vivek and Golland, Polina},
    title     = {Fast Auto-Differentiable Digitally Reconstructed Radiographs for Solving Inverse Problems in Intraoperative Imaging},
    year      = {2022},
    booktitle = {Clinical Image-based Procedures: 11th International Workshop, CLIP 2022, Held in Conjunction with MICCAI 2022, Singapore, Proceedings},
    series    = {Lecture Notes in Computer Science},
    publisher = {Springer},
    doi       = {https://doi.org/10.1007/978-3-031-23179-7_1},
}

[^1]: Siddon RL. Fast calculation of the exact radiological path for a three-dimensional ct array. Medical Physics, 2(12):252–5, 1985.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffdrr-0.3.0.tar.gz (34.6 MB view details)

Uploaded Source

Built Distribution

diffdrr-0.3.0-py3-none-any.whl (34.6 MB view details)

Uploaded Python 3

File details

Details for the file diffdrr-0.3.0.tar.gz.

File metadata

  • Download URL: diffdrr-0.3.0.tar.gz
  • Upload date:
  • Size: 34.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for diffdrr-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a0530d61ab8a8a5bf89db0079284064af7894b35781e6fb9346d79a02c36d9ea
MD5 1e68106fc38f92f690ab77d7816741b4
BLAKE2b-256 004fbe2296eb7d887b424a2b480f3e51696d1322f76a72274647103006c7837d

See more details on using hashes here.

File details

Details for the file diffdrr-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: diffdrr-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 34.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for diffdrr-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18754014cf57f56cb4ff49db4460367939e132402a32a31402b05fb90aa4a8ef
MD5 f187b3737e00a36795d045814932d9d9
BLAKE2b-256 16db6b62cb0c844082d1c9bfc39de6c07079b7cb79e1a291a97f05723b59130d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page