1
1
DiffDRR
2
2
================
3
3
4
- <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
5
-
6
4
> Auto-differentiable DRR synthesis and optimization in PyTorch
7
5
8
6
[ ![ CI] ( https://github.com/eigenvivek/DiffDRR/actions/workflows/test.yaml/badge.svg )] ( https://github.com/eigenvivek/DiffDRR/actions/workflows/test.yaml )
9
- [ ![ Paper
10
- shield] ( https://img.shields.io/badge/arXiv-2208.12737-red.svg )] ( https://arxiv.org/abs/2208.12737 )
11
- [ ![ License:
12
- MIT] ( https://img.shields.io/badge/License-MIT-blue.svg )] ( LICENSE )
13
- [ ![ Downloads] ( https://static.pepy.tech/personalized-badge/diffdrr?period=month&units=international_system&left_color=grey&right_color=blue&left_text=downloads.month )] ( https://pepy.tech/project/diffdrr )
7
+ [ ![ Paper shield] ( https://img.shields.io/badge/arXiv-2208.12737-red.svg )] ( https://arxiv.org/abs/2208.12737 )
8
+ [ ![ License: MIT] ( https://img.shields.io/badge/License-Apache2.0-blue.svg )] ( LICENSE )
9
+ [ ![ Downloads] ( https://static.pepy.tech/personalized-badge/diffdrr?period=total&units=none&left_color=grey&right_color=blue&left_text=downloads )] ( https://pepy.tech/project/diffdrr )
14
10
[ ![ Docs] ( https://img.shields.io/badge/docs-passing-brightgreen.svg )] ( https://vivekg.dev/DiffDRR/ )
15
- [ ![ Code style:
16
- black] ( https://img.shields.io/badge/Code%20style-black-black.svg )] ( https://github.com/psf/black )
11
+ [ ![ Code style: black] ( https://img.shields.io/badge/Code%20style-black-black.svg )] ( https://github.com/psf/black )
17
12
18
- ` DiffDRR ` is a PyTorch-based digitally reconstructed radiograph (DRR)
19
- generator that provides
13
+ ` DiffDRR ` is a PyTorch-based digitally reconstructed radiograph (DRR) generator that provides
20
14
21
- 1 . Auto-differentiable DRR syntheisis
22
- 2 . GPU-accelerated rendering
23
- 3 . A pure Python implementation
15
+ 1 . Auto-differentiable DRR syntheisis
16
+ 2 . GPU-accelerated rendering
17
+ 3 . A pure Python implementation
24
18
25
- Most importantly, ` DiffDRR ` implements DRR synthesis as a PyTorch
26
- module, making it interoperable in deep learning pipelines.
19
+ Most importantly, ` DiffDRR ` implements DRR synthesis as a PyTorch module, making it interoperable in deep learning pipelines.
27
20
28
21
- [ Installation Guide] ( #installation-guide )
29
22
- [ Usage] ( #usage )
30
- - [ Example: Rigid 2D-to-3D
31
- registration] ( #application-6-dof-slice-to-volume-registration )
23
+ - [ Example: Rigid 2D-to-3D registration] ( #application-6-dof-slice-to-volume-registration )
32
24
- [ How does ` DiffDRR ` work?] ( #how-does-diffdrr-work )
33
25
- [ Citing ` DiffDRR ` ] ( #citing-diffdrr )
34
26
35
27
## Installation Guide
36
28
37
29
To install ` DiffDRR ` from PyPI:
38
-
39
- ``` zsh
30
+ ``` zsh
40
31
pip install diffdrr
41
32
```
42
33
43
34
## Usage
44
35
45
- The following minimal example specifies the geometry of the projectional
46
- radiograph imaging system and traces rays through a CT volume:
36
+ The following minimal example specifies the geometry of the projectional radiograph imaging system and traces rays through a CT volume:
47
37
48
38
``` python
49
39
import matplotlib.pyplot as plt
@@ -57,43 +47,34 @@ from diffdrr.visualization import plot_drr
57
47
volume, spacing = load_example_ct()
58
48
59
49
# Initialize the DRR module for generating synthetic X-rays
50
+ device = " cuda" if torch.cuda.is_available() else " cpu"
60
51
drr = DRR(
61
- volume, # The CT volume as a numpy array
62
- spacing, # Voxel dimensions of the CT
63
- sdr = 300.0 , # Source-to-detector radius (half of the source-to-detector distance)
64
- height = 200 , # Height of the DRR (if width is not seperately provided, the generated image is square)
65
- delx = 4.0 , # Pixel spacing (in mm)
66
- batch_size = 1 , # How many batches of parameters will be passed = number of DRRs generated each forward pass
67
- ).to(" cuda" if torch.cuda.is_available() else " cpu" )
68
-
69
- # Rotations and translations determine the viewing angle
70
- # They must have the same batch_size as was passed to the DRR constructor
71
- # Rotations are (yaw pitch roll)
72
- # Translations are (bx by bz)
73
- rotations = torch.tensor([[torch.pi, 0.0 , torch.pi / 2 ]])
74
- translations = torch.tensor(volume.shape) * torch.tensor(spacing) / 2
75
- translations = translations.unsqueeze(0 )
76
-
77
- # Generate the DRR
78
- drr.move_carm(rotations, translations)
79
- with torch.no_grad():
80
- img = drr() # Only keep the graph if optimizing DRRs
81
- ax = plot_drr(img)
52
+ volume, # The CT volume as a numpy array
53
+ spacing, # Voxel dimensions of the CT
54
+ sdr = 300.0 , # Source-to-detector radius (half of the source-to-detector distance)
55
+ height = 200 , # Height of the DRR (if width is not seperately provided, the generated image is square)
56
+ delx = 4.0 , # Pixel spacing (in mm)
57
+ ).to(device)
58
+
59
+ # Set the camera pose with rotations (yaw, pitch, roll) and translations (x, y, z)
60
+ rotations = torch.tensor([[torch.pi, 0.0 , torch.pi / 2 ]], device = device)
61
+ bx, by, bz = torch.tensor(volume.shape) * torch.tensor(spacing) / 2
62
+ translations = torch.tensor([[bx, by, bz]], device = device)
63
+
64
+ # Make the DRR
65
+ img = drr(rotations, translations)
66
+ plot_drr(img, ticks = False )
82
67
plt.show()
83
68
```
84
69
85
- ![ ] ( index_files/figure-commonmark/cell-2-output-1.png )
70
+ ![ ] ( notebooks/ index_files/figure-commonmark/cell-2-output-1.png)
86
71
87
72
On a single NVIDIA RTX 2080 Ti GPU, producing such an image takes
88
73
89
- ``` python
90
- % timeit drr()
91
- ```
92
-
93
- 34.9 ms ± 110 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
74
+ 34.9 ms ± 32.2 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
94
75
95
76
The full example is available at
96
- [ ` tutorials/ introduction.ipynb` ] ( tutorials/introduction.ipynb ) .
77
+ [ ` introduction.ipynb ` ] ( https://vivekg.dev/DiffDRR/ tutorials/introduction.html ) .
97
78
98
79
## Application: 6-DoF Slice-to-Volume Registration
99
80
@@ -111,7 +92,7 @@ optimization runs like this:
111
92
![ ] ( https://cdn.githubraw.com/eigenvivek/DiffDRR/7a6a44aeab58d19cc7a4afabfc5aabab3a494974/experiments/registration/results/momentum_dampen/gifs/converged/649.gif )
112
93
113
94
The full example is available at
114
- [ ` tutorials/ optimizers.ipynb` ] ( tutorials/optimizers.ipynb ) .
95
+ [ ` optimizers.ipynb ` ] ( https://vivekg.dev/DiffDRR/ tutorials/optimizers.html ) .
115
96
116
97
## How does ` DiffDRR ` work?
117
98
0 commit comments