voxelmorph 0.2__tar.gz → 0.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- voxelmorph-0.3.1/PKG-INFO +246 -0
- {voxelmorph-0.2 → voxelmorph-0.3.1}/README.md +74 -19
- voxelmorph-0.3.1/pyproject.toml +43 -0
- {voxelmorph-0.2 → voxelmorph-0.3.1}/setup.py +3 -10
- voxelmorph-0.3.1/tests/test_functional.py +1402 -0
- voxelmorph-0.3.1/tests/test_imports.py +1 -0
- voxelmorph-0.3.1/tests/test_models.py +245 -0
- voxelmorph-0.3.1/tests/test_modules.py +444 -0
- voxelmorph-0.3.1/tests/test_neurite_integration.py +180 -0
- voxelmorph-0.3.1/voxelmorph/__init__.py +53 -0
- voxelmorph-0.3.1/voxelmorph/functional.py +1296 -0
- voxelmorph-0.3.1/voxelmorph/nn/__init__.py +29 -0
- voxelmorph-0.3.1/voxelmorph/nn/functional.py +826 -0
- voxelmorph-0.3.1/voxelmorph/nn/losses.py +80 -0
- voxelmorph-0.3.1/voxelmorph/nn/models.py +280 -0
- voxelmorph-0.3.1/voxelmorph/nn/modules.py +287 -0
- voxelmorph-0.3.1/voxelmorph/py/__init__.py +15 -0
- {voxelmorph-0.2/voxelmorph → voxelmorph-0.3.1/voxelmorph/py}/generators.py +54 -39
- {voxelmorph-0.2 → voxelmorph-0.3.1}/voxelmorph/py/utils.py +48 -21
- voxelmorph-0.3.1/voxelmorph.egg-info/PKG-INFO +246 -0
- voxelmorph-0.3.1/voxelmorph.egg-info/SOURCES.txt +24 -0
- {voxelmorph-0.2 → voxelmorph-0.3.1}/voxelmorph.egg-info/requires.txt +3 -2
- voxelmorph-0.2/PKG-INFO +0 -17
- voxelmorph-0.2/voxelmorph/__init__.py +0 -59
- voxelmorph-0.2/voxelmorph/py/__init__.py +0 -1
- voxelmorph-0.2/voxelmorph/tf/__init__.py +0 -4
- voxelmorph-0.2/voxelmorph/tf/layers.py +0 -539
- voxelmorph-0.2/voxelmorph/tf/losses.py +0 -359
- voxelmorph-0.2/voxelmorph/tf/networks.py +0 -1242
- voxelmorph-0.2/voxelmorph/tf/utils/__init__.py +0 -1
- voxelmorph-0.2/voxelmorph/tf/utils/utils.py +0 -800
- voxelmorph-0.2/voxelmorph/torch/__init__.py +0 -4
- voxelmorph-0.2/voxelmorph/torch/layers.py +0 -97
- voxelmorph-0.2/voxelmorph/torch/losses.py +0 -117
- voxelmorph-0.2/voxelmorph/torch/modelio.py +0 -77
- voxelmorph-0.2/voxelmorph/torch/networks.py +0 -305
- voxelmorph-0.2/voxelmorph/torch/utils.py +0 -1
- voxelmorph-0.2/voxelmorph.egg-info/PKG-INFO +0 -17
- voxelmorph-0.2/voxelmorph.egg-info/SOURCES.txt +0 -24
- {voxelmorph-0.2 → voxelmorph-0.3.1}/LICENSE.md +0 -0
- {voxelmorph-0.2 → voxelmorph-0.3.1}/setup.cfg +0 -0
- {voxelmorph-0.2 → voxelmorph-0.3.1}/voxelmorph.egg-info/dependency_links.txt +0 -0
- {voxelmorph-0.2 → voxelmorph-0.3.1}/voxelmorph.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: voxelmorph
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: Unsupervised Learning for Image Registration.
|
|
5
|
+
Home-page: https://github.com/voxelmorph/voxelmorph
|
|
6
|
+
Author: Adrian V. Dalca, Malte Hoffmann, Andrew Hoopes
|
|
7
|
+
License: MIT
|
|
8
|
+
Project-URL: GitHub, https://github.com/voxelmorph/voxelmorph
|
|
9
|
+
Project-URL: PyPI, https://pypi.org/project/voxelmorph/
|
|
10
|
+
Keywords: python,pytorch,medical-imaging,registration,medical-image-computing
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE.md
|
|
18
|
+
Requires-Dist: torch
|
|
19
|
+
Requires-Dist: scikit-image
|
|
20
|
+
Requires-Dist: packaging
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Requires-Dist: scipy
|
|
23
|
+
Requires-Dist: nibabel
|
|
24
|
+
Requires-Dist: h5py
|
|
25
|
+
Requires-Dist: neurite>=0.2
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
Dynamic: requires-python
|
|
29
|
+
|
|
30
|
+
# VoxelMorph: learning-based image registration
|
|
31
|
+
|
|
32
|
+
**VoxelMorph** is a general purpose library for learning-based tools for alignment/registration, and more generally modelling with deformations.
|
|
33
|
+
|
|
34
|
+
> ⚠️ **Warning**: VoxelMorph pytorch is under active development. Interfaces may change.
|
|
35
|
+
|
|
36
|
+
> **For users who want to use the stable TensorFlow version**, pull or clone the [`dev-tensorflow`](https://github.com/voxelmorph/voxelmorph/tree/dev-tensorflow) branch.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
Install the published package from PyPI:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
pip install voxelmorph
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
To work from a source checkout, clone this repository and install the requirements listed in `setup.py`.
|
|
47
|
+
|
|
48
|
+
### Pre-commit hooks
|
|
49
|
+
|
|
50
|
+
This repo uses `pre-commit` to run `pycodestyle` before commits.
|
|
51
|
+
|
|
52
|
+
Install once after cloning:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install pre-commit
|
|
56
|
+
pre-commit install
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
You can also run the check manually:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pre-commit run pycodestyle --all-files
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
# Tutorial
|
|
66
|
+
|
|
67
|
+
We have several VoxelMorph tutorials:
|
|
68
|
+
- the main [VoxelMorph tutorial](http://tutorial.voxelmorph.net/) explains VoxelMorph and learning-based registration
|
|
69
|
+
- a [deformable SynthMorph demo](https://colab.research.google.com/drive/1zaDnAJGUokS0knqWttuTgrRJMb6zxukI?usp=sharing) showing how to train a registration model without data
|
|
70
|
+
- an [affine SynthMorph demo](https://colab.research.google.com/drive/1QClknfaZIYklBjmBy-nUn83h85bpo8r0?usp=sharing) on learning anatomy-aware and acquisition-agnostic affine registration
|
|
71
|
+
- a [CT-to-MRI SynthMorph demo](https://colab.research.google.com/drive/1aWbFiyQw5mtJbTglpniAOMimGo_l8BYP?usp=drive_link) clipping the Hounsfield scale for multi-modal registration
|
|
72
|
+
- a [SynthMorph shapes demo](https://colab.research.google.com/drive/14s2h0j_Aoncp587vmpjsQBe6PQTxyVP5) that walks through the steps of running a trained 3D shapes model
|
|
73
|
+
- a [tutorial on training VoxelMorph](https://colab.research.google.com/drive/1ZefmWXBupRNsnIbBbGquhVDsk-7R7L1S?usp=sharing) on [OASIS data](https://github.com/adalca/medical-datasets/blob/master/neurite-oasis.md), which we processed and released for free for HyperMorph
|
|
74
|
+
- an [additional small tutorial](https://colab.research.google.com/drive/1V0CutSIfmtgDJg1XIkEnGteJuw0u7qT-#scrollTo=h1KXYz-Nauwn) on warping annotations together with images
|
|
75
|
+
- another tutorial on [template (atlas) construction](https://colab.research.google.com/drive/1SkQbrWTQHpQFrG4J2WoBgGZC9yAzUas2?usp=sharing) with VoxelMorph
|
|
76
|
+
- visualize [warp](https://colab.research.google.com/drive/1F8f1imh5WfyBv-crllfeJBFY16-KHl9c?usp=sharing) as warped grid
|
|
77
|
+
- [inverting warps](https://colab.research.google.com/drive/1juAJRYhPPDNbO9yRtlc0VGhbIFSuhpJ2?usp=sharing) that are not diffeomorphisms
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# Instructions
|
|
81
|
+
|
|
82
|
+
To use the VoxelMorph library from source, clone this repository and install the requirements listed in `setup.py`.
|
|
83
|
+
|
|
84
|
+
> **Note**: For source development, install from GitHub instead:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
pip install git+https://github.com/voxelmorph/voxelmorph.git
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Pre-trained models
|
|
91
|
+
|
|
92
|
+
See list of pre-trained models available [here](data/readme.md#models).
|
|
93
|
+
|
|
94
|
+
## Training
|
|
95
|
+
|
|
96
|
+
If you would like to train your own model, you will likely need to customize some of the data-loading code in `voxelmorph/generators.py` for your own datasets and data formats. However, it is possible to run many of the example scripts out-of-the-box, assuming that you provide a list of filenames in the training dataset. Training data can be in the NIfTI, MGZ, or npz (numpy) format, and it's assumed that each npz file in your data list has a `vol` parameter, which points to the image data to be registered, and an optional `seg` variable, which points to a corresponding discrete segmentation (for semi-supervised learning). It's also assumed that the shape of all training image data is consistent, but this, of course, can be handled in a customized generator if desired.
|
|
97
|
+
|
|
98
|
+
For a given image list file `/images/list.txt` and output directory `/models/output`, the following script will train an image-to-image registration network (described in MICCAI 2018 by default) with an unsupervised loss. Model weights will be saved to a path specified by the `--model-dir` flag.
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
./scripts/tf/train.py --img-list /images/list.txt --model-dir /models/output --gpu 0
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The `--img-prefix` and `--img-suffix` flags can be used to provide a consistent prefix or suffix to each path specified in the image list. Image-to-atlas registration can be enabled by providing an atlas file, e.g. `--atlas atlas.npz`. If you'd like to train using the original dense CVPR network (no diffeomorphism), use the `--int-steps 0` flag to specify no flow integration steps. Use the `--help` flag to inspect all of the command line options that can be used to fine-tune network architecture and training.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
## Registration
|
|
108
|
+
|
|
109
|
+
If you simply want to register two images, you can use the `register.py` script with the desired model file. For example, if we have a model `model.h5` trained to register a subject (moving) to an atlas (fixed), we could run:
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
./scripts/tf/register.py --moving moving.nii.gz --fixed atlas.nii.gz --moved warped.nii.gz --model model.h5 --gpu 0
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This will save the moved image to `warped.nii.gz`. To also save the predicted deformation field, use the `--save-warp` flag. Both npz or nifty files can be used as input/output in this script.
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Testing (measuring Dice scores)
|
|
119
|
+
|
|
120
|
+
To test the quality of a model by computing dice overlap between an atlas segmentation and warped test scan segmentations, run:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
./scripts/tf/test.py --model model.h5 --atlas atlas.npz --scans scan01.npz scan02.npz scan03.npz --labels labels.npz
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Just like for the training data, the atlas and test npz files include `vol` and `seg` parameters and the `labels.npz` file contains a list of corresponding anatomical labels to include in the computed dice score.
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
## Parameter choices
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
### CVPR version
|
|
133
|
+
|
|
134
|
+
For the CC loss function, we found a reg parameter of 1 to work best. For the MSE loss function, we found 0.01 to work best.
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
### MICCAI version
|
|
138
|
+
|
|
139
|
+
For our data, we found `image_sigma=0.01` and `prior_lambda=25` to work best.
|
|
140
|
+
|
|
141
|
+
In the original MICCAI code, the parameters were applied after the scaling of the velocity field. With the newest code, this has been "fixed", with different default parameters reflecting the change. We recommend running the updated code. However, if you'd like to run the very original MICCAI2018 mode, please use `xy` indexing and `use_miccai_int` network option, with MICCAI2018 parameters.
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
## Spatial transforms and integration
|
|
145
|
+
|
|
146
|
+
- The spatial transform code, found at `voxelmorph.layers.SpatialTransformer`, accepts N-dimensional affine and dense transforms, including linear and nearest neighbor interpolation options. Note that original development of VoxelMorph used `xy` indexing, whereas we are now emphasizing `ij` indexing.
|
|
147
|
+
|
|
148
|
+
- For the MICCAI2018 version, we integrate the velocity field using `voxelmorph.layers.VecInt`. By default we integrate using scaling and squaring, which we found efficient.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# VoxelMorph papers
|
|
152
|
+
|
|
153
|
+
If you use VoxelMorph or some part of the code, please cite (see [bibtex](citations.bib)):
|
|
154
|
+
|
|
155
|
+
* HyperMorph, avoiding the need to tune registration hyperparameters:
|
|
156
|
+
|
|
157
|
+
**Learning the Effect of Registration Hyperparameters with HyperMorph**
|
|
158
|
+
Andrew Hoopes, [Malte Hoffmann](https://malte.cz), Bruce Fischl, [John Guttag](https://people.csail.mit.edu/guttag/), [Adrian V. Dalca](http://adalca.mit.edu)
|
|
159
|
+
MELBA: Machine Learning for Biomedical Imaging. 2022. [eprint arXiv:2203.16680](https://arxiv.org/abs/2203.16680)
|
|
160
|
+
|
|
161
|
+
**HyperMorph: Amortized Hyperparameter Learning for Image Registration.**
|
|
162
|
+
Andrew Hoopes, [Malte Hoffmann](https://malte.cz), Bruce Fischl, [John Guttag](https://people.csail.mit.edu/guttag/), [Adrian V. Dalca](http://adalca.mit.edu)
|
|
163
|
+
IPMI: Information Processing in Medical Imaging. 2021. [eprint arXiv:2101.01035](https://arxiv.org/abs/2101.01035)
|
|
164
|
+
|
|
165
|
+
* [SynthMorph](https://synthmorph.voxelmorph.net), avoiding the need to have data at training (!):
|
|
166
|
+
|
|
167
|
+
**Anatomy-aware and acquisition-agnostic joint registration with SynthMorph.**
|
|
168
|
+
[Malte Hoffmann](https://malte.cz), Andrew Hoopes, Douglas N. Greve, Bruce Fischl, [Adrian V. Dalca](http://adalca.mit.edu)
|
|
169
|
+
Imaging Neuroscience. 2024. [eprint arXiv:2301.11329](https://arxiv.org/abs/2301.11329)
|
|
170
|
+
|
|
171
|
+
**Anatomy-specific acquisition-agnostic affine registration learned from fictitious images.**
|
|
172
|
+
[Malte Hoffmann](https://malte.cz), Andrew Hoopes, Bruce Fischl, [Adrian V. Dalca](http://adalca.mit.edu)
|
|
173
|
+
SPIE Medical Imaging: Image Processing. 2023.
|
|
174
|
+
|
|
175
|
+
**SynthMorph: learning contrast-invariant registration without acquired images.**
|
|
176
|
+
[Malte Hoffmann](https://malte.cz), Benjamin Billot, [Juan Eugenio Iglesias](https://scholar.harvard.edu/iglesias), Bruce Fischl, [Adrian V. Dalca](http://adalca.mit.edu)
|
|
177
|
+
IEEE TMI: Transactions on Medical Imaging. 2022. [eprint arXiv:2004.10282](https://arxiv.org/abs/2004.10282)
|
|
178
|
+
|
|
179
|
+
* For the atlas formation model:
|
|
180
|
+
|
|
181
|
+
**Learning Conditional Deformable Templates with Convolutional Networks**
|
|
182
|
+
[Adrian V. Dalca](http://adalca.mit.edu), [Marianne Rakic](https://mariannerakic.github.io/), [John Guttag](https://people.csail.mit.edu/guttag/), [Mert R. Sabuncu](http://sabuncu.engineering.cornell.edu/)
|
|
183
|
+
NeurIPS 2019. [eprint arXiv:1908.02738](https://arxiv.org/abs/1908.02738)
|
|
184
|
+
|
|
185
|
+
* For the diffeomorphic or probabilistic model:
|
|
186
|
+
|
|
187
|
+
**Unsupervised Learning of Probabilistic Diffeomorphic Registration for Images and Surfaces**
|
|
188
|
+
[Adrian V. Dalca](http://adalca.mit.edu), [Guha Balakrishnan](http://people.csail.mit.edu/balakg/), [John Guttag](https://people.csail.mit.edu/guttag/), [Mert R. Sabuncu](http://sabuncu.engineering.cornell.edu/)
|
|
189
|
+
MedIA: Medial Image Analysis. 2019. [eprint arXiv:1903.03545](https://arxiv.org/abs/1903.03545)
|
|
190
|
+
|
|
191
|
+
**Unsupervised Learning for Fast Probabilistic Diffeomorphic Registration**
|
|
192
|
+
[Adrian V. Dalca](http://adalca.mit.edu), [Guha Balakrishnan](http://people.csail.mit.edu/balakg/), [John Guttag](https://people.csail.mit.edu/guttag/), [Mert R. Sabuncu](http://sabuncu.engineering.cornell.edu/)
|
|
193
|
+
MICCAI 2018. [eprint arXiv:1805.04605](https://arxiv.org/abs/1805.04605)
|
|
194
|
+
|
|
195
|
+
* For the original CNN model, MSE, CC, or segmentation-based losses:
|
|
196
|
+
|
|
197
|
+
**VoxelMorph: A Learning Framework for Deformable Medical Image Registration**
|
|
198
|
+
[Guha Balakrishnan](http://people.csail.mit.edu/balakg/), [Amy Zhao](http://people.csail.mit.edu/xamyzhao/), [Mert R. Sabuncu](http://sabuncu.engineering.cornell.edu/), [John Guttag](https://people.csail.mit.edu/guttag/), [Adrian V. Dalca](http://adalca.mit.edu)
|
|
199
|
+
IEEE TMI: Transactions on Medical Imaging. 2019.
|
|
200
|
+
[eprint arXiv:1809.05231](https://arxiv.org/abs/1809.05231)
|
|
201
|
+
|
|
202
|
+
**An Unsupervised Learning Model for Deformable Medical Image Registration**
|
|
203
|
+
[Guha Balakrishnan](http://people.csail.mit.edu/balakg/), [Amy Zhao](http://people.csail.mit.edu/xamyzhao/), [Mert R. Sabuncu](http://sabuncu.engineering.cornell.edu/), [John Guttag](https://people.csail.mit.edu/guttag/), [Adrian V. Dalca](http://adalca.mit.edu)
|
|
204
|
+
CVPR 2018. [eprint arXiv:1802.02604](https://arxiv.org/abs/1802.02604)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
# Notes
|
|
208
|
+
- **keywords**: machine learning, convolutional neural networks, alignment, mapping, registration
|
|
209
|
+
- **data in papers**:
|
|
210
|
+
In our initial papers, we used publicly available data, but unfortunately we cannot redistribute it (due to the constraints of those datasets). We do a certain amount of pre-processing for the brain images we work with, to eliminate sources of variation and be able to compare algorithms on a level playing field. In particular, we perform FreeSurfer `recon-all` steps up to skull stripping and affine normalization to Talairach space, and crop the images via `((48, 48), (31, 33), (3, 29))`.
|
|
211
|
+
|
|
212
|
+
We encourage users to download and process their own data. See [a list of medical imaging datasets here](https://github.com/adalca/medical-datasets). Note that you likely do not need to perform all of the preprocessing steps, and indeed VoxelMorph has been used in other work with other data.
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
# Creation of deformable templates
|
|
216
|
+
|
|
217
|
+
To experiment with this method, please use `train_template.py` for unconditional templates and `train_cond_template.py` for conditional templates, which use the same conventions as VoxelMorph (please note that these files are less polished than the rest of the VoxelMorph library).
|
|
218
|
+
|
|
219
|
+
We've also provided an unconditional atlas in `data/generated_uncond_atlas.npz.npy`.
|
|
220
|
+
|
|
221
|
+
Models in h5 format weights are provided for [unconditional atlas here](http://people.csail.mit.edu/adalca/voxelmorph/atlas_creation_uncond_NCC_1500.h5), and [conditional atlas here](http://people.csail.mit.edu/adalca/voxelmorph/atlas_creation_cond_NCC_1022.h5).
|
|
222
|
+
|
|
223
|
+
**Explore the atlases [interactively here](http://voxelmorph.mit.edu/atlas_creation/)** with tipiX!
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
# SynthMorph
|
|
227
|
+
|
|
228
|
+
SynthMorph is a strategy for learning registration without acquired imaging data, producing powerful networks agnostic to contrast induced by MRI ([eprint arXiv:2004.10282](https://arxiv.org/abs/2004.10282)). For a video and a demo showcasing the steps of generating random label maps from noise distributions and using these to train a network, visit [synthmorph.voxelmorph.net](https://synthmorph.voxelmorph.net).
|
|
229
|
+
|
|
230
|
+
We provide model files for a ["shapes" variant](https://surfer.nmr.mgh.harvard.edu/ftp/data/voxelmorph/synthmorph/shapes-dice-vel-3-res-8-16-32-256f.h5) of SynthMorph, that we train using images synthesized from random shapes only, and a ["brains" variant](https://surfer.nmr.mgh.harvard.edu/ftp/data/voxelmorph/synthmorph/brains-dice-vel-0.5-res-16-256f.h5), that we train using images synthesized from brain label maps. We train the brains variant by optimizing a loss term that measures volume overlap of a [selection of brain labels](https://surfer.nmr.mgh.harvard.edu/ftp/data/voxelmorph/synthmorph/fs-labels.npy). For registration with either model, please use the `register.py` script with the respective model weights.
|
|
231
|
+
|
|
232
|
+
Accurate registration requires the input images to be min-max normalized, such that voxel intensities range from 0 to 1, and to be resampled in the affine space of a [reference image](https://surfer.nmr.mgh.harvard.edu/ftp/data/voxelmorph/synthmorph/ref.nii.gz). The affine registration can be performed with a variety of packages, and we choose FreeSurfer. First, we skull-strip the images with [SAMSEG](https://surfer.nmr.mgh.harvard.edu/fswiki/Samseg), keeping brain labels only. Second, we run [mri_robust_register](https://surfer.nmr.mgh.harvard.edu/fswiki/mri_robust_register):
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
mri_robust_register --mov in.nii.gz --dst out.nii.gz --lta transform.lta --satit --iscale
|
|
236
|
+
mri_robust_register --mov in.nii.gz --dst out.nii.gz --lta transform.lta --satit --iscale --ixform transform.lta --affine
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
where we replace `--satit --iscale` with `--cost NMI` for registration across MRI contrasts.
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
# Data
|
|
243
|
+
While we cannot release most of the data used in the VoxelMorph papers as they prohibit redistribution, we thorough processed and [re-released OASIS1](https://github.com/adalca/medical-datasets/blob/master/neurite-oasis.md) while developing [HyperMorph](http://hypermorph.voxelmorph.net/). We now include a quick [VoxelMorph tutorial](https://colab.research.google.com/drive/1ZefmWXBupRNsnIbBbGquhVDsk-7R7L1S?usp=sharing) to train VoxelMorph on neurite-oasis data.
|
|
244
|
+
|
|
245
|
+
# Contact
|
|
246
|
+
For any code-related problems or questions please [open an issue](https://github.com/voxelmorph/voxelmorph/issues/new?labels=voxelmorph) or [start a discussion](https://github.com/voxelmorph/voxelmorph/discussions) of general registration/VoxelMorph topics.
|
|
@@ -1,18 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# VoxelMorph: learning-based image registration
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**VoxelMorph** is a general purpose library for learning-based tools for alignment/registration, and more generally modelling with deformations.
|
|
4
|
+
|
|
5
|
+
> ⚠️ **Warning**: VoxelMorph pytorch is under active development. Interfaces may change.
|
|
6
|
+
|
|
7
|
+
> **For users who want to use the stable TensorFlow version**, pull or clone the [`dev-tensorflow`](https://github.com/voxelmorph/voxelmorph/tree/dev-tensorflow) branch.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Install the published package from PyPI:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
pip install voxelmorph
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
To work from a source checkout, clone this repository and install the requirements listed in `setup.py`.
|
|
18
|
+
|
|
19
|
+
### Pre-commit hooks
|
|
20
|
+
|
|
21
|
+
This repo uses `pre-commit` to run `pycodestyle` before commits.
|
|
22
|
+
|
|
23
|
+
Install once after cloning:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install pre-commit
|
|
27
|
+
pre-commit install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
You can also run the check manually:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pre-commit run pycodestyle --all-files
|
|
34
|
+
```
|
|
4
35
|
|
|
5
36
|
# Tutorial
|
|
6
37
|
|
|
7
|
-
|
|
38
|
+
We have several VoxelMorph tutorials:
|
|
39
|
+
- the main [VoxelMorph tutorial](http://tutorial.voxelmorph.net/) explains VoxelMorph and learning-based registration
|
|
40
|
+
- a [deformable SynthMorph demo](https://colab.research.google.com/drive/1zaDnAJGUokS0knqWttuTgrRJMb6zxukI?usp=sharing) showing how to train a registration model without data
|
|
41
|
+
- an [affine SynthMorph demo](https://colab.research.google.com/drive/1QClknfaZIYklBjmBy-nUn83h85bpo8r0?usp=sharing) on learning anatomy-aware and acquisition-agnostic affine registration
|
|
42
|
+
- a [CT-to-MRI SynthMorph demo](https://colab.research.google.com/drive/1aWbFiyQw5mtJbTglpniAOMimGo_l8BYP?usp=drive_link) clipping the Hounsfield scale for multi-modal registration
|
|
43
|
+
- a [SynthMorph shapes demo](https://colab.research.google.com/drive/14s2h0j_Aoncp587vmpjsQBe6PQTxyVP5) that walks through the steps of running a trained 3D shapes model
|
|
44
|
+
- a [tutorial on training VoxelMorph](https://colab.research.google.com/drive/1ZefmWXBupRNsnIbBbGquhVDsk-7R7L1S?usp=sharing) on [OASIS data](https://github.com/adalca/medical-datasets/blob/master/neurite-oasis.md), which we processed and released for free for HyperMorph
|
|
45
|
+
- an [additional small tutorial](https://colab.research.google.com/drive/1V0CutSIfmtgDJg1XIkEnGteJuw0u7qT-#scrollTo=h1KXYz-Nauwn) on warping annotations together with images
|
|
46
|
+
- another tutorial on [template (atlas) construction](https://colab.research.google.com/drive/1SkQbrWTQHpQFrG4J2WoBgGZC9yAzUas2?usp=sharing) with VoxelMorph
|
|
47
|
+
- visualize [warp](https://colab.research.google.com/drive/1F8f1imh5WfyBv-crllfeJBFY16-KHl9c?usp=sharing) as warped grid
|
|
48
|
+
- [inverting warps](https://colab.research.google.com/drive/1juAJRYhPPDNbO9yRtlc0VGhbIFSuhpJ2?usp=sharing) that are not diffeomorphisms
|
|
8
49
|
|
|
9
50
|
|
|
10
51
|
# Instructions
|
|
11
52
|
|
|
12
|
-
To use the VoxelMorph library,
|
|
53
|
+
To use the VoxelMorph library from source, clone this repository and install the requirements listed in `setup.py`.
|
|
54
|
+
|
|
55
|
+
> **Note**: For source development, install from GitHub instead:
|
|
13
56
|
|
|
14
57
|
```
|
|
15
|
-
pip install voxelmorph
|
|
58
|
+
pip install git+https://github.com/voxelmorph/voxelmorph.git
|
|
16
59
|
```
|
|
17
60
|
|
|
18
61
|
## Pre-trained models
|
|
@@ -69,28 +112,39 @@ For our data, we found `image_sigma=0.01` and `prior_lambda=25` to work best.
|
|
|
69
112
|
In the original MICCAI code, the parameters were applied after the scaling of the velocity field. With the newest code, this has been "fixed", with different default parameters reflecting the change. We recommend running the updated code. However, if you'd like to run the very original MICCAI2018 mode, please use `xy` indexing and `use_miccai_int` network option, with MICCAI2018 parameters.
|
|
70
113
|
|
|
71
114
|
|
|
72
|
-
## Spatial
|
|
115
|
+
## Spatial transforms and integration
|
|
73
116
|
|
|
74
117
|
- The spatial transform code, found at `voxelmorph.layers.SpatialTransformer`, accepts N-dimensional affine and dense transforms, including linear and nearest neighbor interpolation options. Note that original development of VoxelMorph used `xy` indexing, whereas we are now emphasizing `ij` indexing.
|
|
75
118
|
|
|
76
119
|
- For the MICCAI2018 version, we integrate the velocity field using `voxelmorph.layers.VecInt`. By default we integrate using scaling and squaring, which we found efficient.
|
|
77
120
|
|
|
78
121
|
|
|
79
|
-
# VoxelMorph
|
|
122
|
+
# VoxelMorph papers
|
|
80
123
|
|
|
81
|
-
If you use
|
|
124
|
+
If you use VoxelMorph or some part of the code, please cite (see [bibtex](citations.bib)):
|
|
82
125
|
|
|
83
126
|
* HyperMorph, avoiding the need to tune registration hyperparameters:
|
|
84
127
|
|
|
85
|
-
**
|
|
86
|
-
Andrew Hoopes, [Malte Hoffmann](https://
|
|
87
|
-
|
|
128
|
+
**Learning the Effect of Registration Hyperparameters with HyperMorph**
|
|
129
|
+
Andrew Hoopes, [Malte Hoffmann](https://malte.cz), Bruce Fischl, [John Guttag](https://people.csail.mit.edu/guttag/), [Adrian V. Dalca](http://adalca.mit.edu)
|
|
130
|
+
MELBA: Machine Learning for Biomedical Imaging. 2022. [eprint arXiv:2203.16680](https://arxiv.org/abs/2203.16680)
|
|
88
131
|
|
|
132
|
+
**HyperMorph: Amortized Hyperparameter Learning for Image Registration.**
|
|
133
|
+
Andrew Hoopes, [Malte Hoffmann](https://malte.cz), Bruce Fischl, [John Guttag](https://people.csail.mit.edu/guttag/), [Adrian V. Dalca](http://adalca.mit.edu)
|
|
134
|
+
IPMI: Information Processing in Medical Imaging. 2021. [eprint arXiv:2101.01035](https://arxiv.org/abs/2101.01035)
|
|
89
135
|
|
|
90
136
|
* [SynthMorph](https://synthmorph.voxelmorph.net), avoiding the need to have data at training (!):
|
|
91
137
|
|
|
138
|
+
**Anatomy-aware and acquisition-agnostic joint registration with SynthMorph.**
|
|
139
|
+
[Malte Hoffmann](https://malte.cz), Andrew Hoopes, Douglas N. Greve, Bruce Fischl, [Adrian V. Dalca](http://adalca.mit.edu)
|
|
140
|
+
Imaging Neuroscience. 2024. [eprint arXiv:2301.11329](https://arxiv.org/abs/2301.11329)
|
|
141
|
+
|
|
142
|
+
**Anatomy-specific acquisition-agnostic affine registration learned from fictitious images.**
|
|
143
|
+
[Malte Hoffmann](https://malte.cz), Andrew Hoopes, Bruce Fischl, [Adrian V. Dalca](http://adalca.mit.edu)
|
|
144
|
+
SPIE Medical Imaging: Image Processing. 2023.
|
|
145
|
+
|
|
92
146
|
**SynthMorph: learning contrast-invariant registration without acquired images.**
|
|
93
|
-
[Malte Hoffmann](https://
|
|
147
|
+
[Malte Hoffmann](https://malte.cz), Benjamin Billot, [Juan Eugenio Iglesias](https://scholar.harvard.edu/iglesias), Bruce Fischl, [Adrian V. Dalca](http://adalca.mit.edu)
|
|
94
148
|
IEEE TMI: Transactions on Medical Imaging. 2022. [eprint arXiv:2004.10282](https://arxiv.org/abs/2004.10282)
|
|
95
149
|
|
|
96
150
|
* For the atlas formation model:
|
|
@@ -121,19 +175,17 @@ IEEE TMI: Transactions on Medical Imaging. 2019.
|
|
|
121
175
|
CVPR 2018. [eprint arXiv:1802.02604](https://arxiv.org/abs/1802.02604)
|
|
122
176
|
|
|
123
177
|
|
|
124
|
-
# Notes
|
|
178
|
+
# Notes
|
|
125
179
|
- **keywords**: machine learning, convolutional neural networks, alignment, mapping, registration
|
|
126
|
-
- The `master` branch is still in testing as we roll out a major refactoring of the library.
|
|
127
|
-
- If you'd like to run code from VoxelMorph publications, please use the `legacy` branch.
|
|
128
180
|
- **data in papers**:
|
|
129
181
|
In our initial papers, we used publicly available data, but unfortunately we cannot redistribute it (due to the constraints of those datasets). We do a certain amount of pre-processing for the brain images we work with, to eliminate sources of variation and be able to compare algorithms on a level playing field. In particular, we perform FreeSurfer `recon-all` steps up to skull stripping and affine normalization to Talairach space, and crop the images via `((48, 48), (31, 33), (3, 29))`.
|
|
130
182
|
|
|
131
183
|
We encourage users to download and process their own data. See [a list of medical imaging datasets here](https://github.com/adalca/medical-datasets). Note that you likely do not need to perform all of the preprocessing steps, and indeed VoxelMorph has been used in other work with other data.
|
|
132
184
|
|
|
133
185
|
|
|
134
|
-
# Creation of
|
|
186
|
+
# Creation of deformable templates
|
|
135
187
|
|
|
136
|
-
To experiment with this method, please use `train_template.py` for unconditional templates and `train_cond_template.py` for conditional templates, which use the same conventions as
|
|
188
|
+
To experiment with this method, please use `train_template.py` for unconditional templates and `train_cond_template.py` for conditional templates, which use the same conventions as VoxelMorph (please note that these files are less polished than the rest of the VoxelMorph library).
|
|
137
189
|
|
|
138
190
|
We've also provided an unconditional atlas in `data/generated_uncond_atlas.npz.npy`.
|
|
139
191
|
|
|
@@ -158,5 +210,8 @@ mri_robust_register --mov in.nii.gz --dst out.nii.gz --lta transform.lta --satit
|
|
|
158
210
|
where we replace `--satit --iscale` with `--cost NMI` for registration across MRI contrasts.
|
|
159
211
|
|
|
160
212
|
|
|
161
|
-
#
|
|
162
|
-
|
|
213
|
+
# Data
|
|
214
|
+
While we cannot release most of the data used in the VoxelMorph papers as they prohibit redistribution, we thorough processed and [re-released OASIS1](https://github.com/adalca/medical-datasets/blob/master/neurite-oasis.md) while developing [HyperMorph](http://hypermorph.voxelmorph.net/). We now include a quick [VoxelMorph tutorial](https://colab.research.google.com/drive/1ZefmWXBupRNsnIbBbGquhVDsk-7R7L1S?usp=sharing) to train VoxelMorph on neurite-oasis data.
|
|
215
|
+
|
|
216
|
+
# Contact
|
|
217
|
+
For any code-related problems or questions please [open an issue](https://github.com/voxelmorph/voxelmorph/issues/new?labels=voxelmorph) or [start a discussion](https://github.com/voxelmorph/voxelmorph/discussions) of general registration/VoxelMorph topics.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "voxelmorph"
|
|
7
|
+
version = "0.3.1"
|
|
8
|
+
description = "Unsupervised Learning for Image Registration."
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Intended Audience :: Science/Research",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Operating System :: OS Independent"
|
|
17
|
+
]
|
|
18
|
+
authors = [
|
|
19
|
+
{ name = "Adrian V. Dalca" },
|
|
20
|
+
{ name = "Malte Hoffmann" },
|
|
21
|
+
{ name = "Andrew Hoopes" }
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"torch",
|
|
25
|
+
"scikit-image",
|
|
26
|
+
"packaging",
|
|
27
|
+
"numpy",
|
|
28
|
+
"scipy",
|
|
29
|
+
"nibabel",
|
|
30
|
+
"h5py",
|
|
31
|
+
"neurite>=0.2",
|
|
32
|
+
]
|
|
33
|
+
keywords = [
|
|
34
|
+
"python",
|
|
35
|
+
"pytorch",
|
|
36
|
+
"medical-imaging",
|
|
37
|
+
"registration",
|
|
38
|
+
"medical-image-computing",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.urls]
|
|
42
|
+
GitHub = "https://github.com/voxelmorph/voxelmorph"
|
|
43
|
+
PyPI = "https://pypi.org/project/voxelmorph/"
|
|
@@ -3,22 +3,15 @@
|
|
|
3
3
|
import re
|
|
4
4
|
import pathlib
|
|
5
5
|
import setuptools
|
|
6
|
-
import packaging.version
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# base source directory
|
|
10
|
-
base_dir = pathlib.Path(__file__).parent.resolve()
|
|
11
6
|
|
|
12
7
|
# extract the current version
|
|
13
|
-
init_file =
|
|
8
|
+
init_file = pathlib.Path(__file__).parent.resolve().joinpath('voxelmorph/__init__.py')
|
|
14
9
|
init_text = open(init_file, 'rt').read()
|
|
15
10
|
pattern = r"^__version__ = ['\"]([^'\"]*)['\"]"
|
|
16
11
|
match = re.search(pattern, init_text, re.M)
|
|
17
12
|
if not match:
|
|
18
|
-
raise RuntimeError(f'Unable to find __version__ in {init_file}
|
|
13
|
+
raise RuntimeError(f'Unable to find __version__ in {init_file}')
|
|
19
14
|
version = match.group(1)
|
|
20
|
-
if isinstance(packaging.version.parse(version), packaging.version.LegacyVersion):
|
|
21
|
-
raise RuntimeError(f'Invalid version string {version}.')
|
|
22
15
|
|
|
23
16
|
# run setup
|
|
24
17
|
setuptools.setup(
|
|
@@ -29,7 +22,7 @@ setuptools.setup(
|
|
|
29
22
|
url='https://github.com/voxelmorph/voxelmorph',
|
|
30
23
|
keywords=['deformation', 'registration', 'imaging', 'cnn', 'mri'],
|
|
31
24
|
packages=setuptools.find_packages(),
|
|
32
|
-
python_requires='>=3.
|
|
25
|
+
python_requires='>=3.8',
|
|
33
26
|
classifiers=[
|
|
34
27
|
'Intended Audience :: Science/Research',
|
|
35
28
|
'Programming Language :: Python :: 3',
|