- Notifications
You must be signed in to change notification settings - Fork627
Unsupervised Learning for Image Registration
License
voxelmorph/voxelmorph
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
VoxelMorph is a general purpose library for learning-based tools for alignment/registration, and more generally modelling with deformations.
⚠️ Warning: VoxelMorph pytorch is under active development. Interfaces may change.
For users who want to use the stable TensorFlow version, use either
pip install voxelmorph, or pull/clone from thedev-tensorflowbranch.
To use the VoxelMorph library, either clone this repository and install the requirements listed insetup.py or install directly with pip.
pip install voxelmorphWe have several VoxelMorph tutorials:
- the mainVoxelMorph tutorial explains VoxelMorph and learning-based registration
- adeformable SynthMorph demo showing how to train a registration model without data
- anaffine SynthMorph demo on learning anatomy-aware and acquisition-agnostic affine registration
- aCT-to-MRI SynthMorph demo clipping the Hounsfield scale for multi-modal registration
- aSynthMorph shapes demo that walks through the steps of running a trained 3D shapes model
- atutorial on training VoxelMorph onOASIS data, which we processed and released for free for HyperMorph
- anadditional small tutorial on warping annotations together with images
- another tutorial ontemplate (atlas) construction with VoxelMorph
- visualizewarp as warped grid
- inverting warps that are not diffeomorphisms
To use the VoxelMorph library, clone this repository and install the requirements listed insetup.py.
Note: The
pip install voxelmorphcommand is not yet supported. Please install directly from GitHub:
pip install git+https://github.com/voxelmorph/voxelmorph.gitSee list of pre-trained models availablehere.
If you would like to train your own model, you will likely need to customize some of the data-loading code invoxelmorph/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 avol parameter, which points to the image data to be registered, and an optionalseg 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.
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.
./scripts/tf/train.py --img-list /images/list.txt --model-dir /models/output --gpu 0The--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.
If you simply want to register two images, you can use theregister.py script with the desired model file. For example, if we have a modelmodel.h5 trained to register a subject (moving) to an atlas (fixed), we could run:
./scripts/tf/register.py --moving moving.nii.gz --fixed atlas.nii.gz --moved warped.nii.gz --model model.h5 --gpu 0This will save the moved image towarped.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.
To test the quality of a model by computing dice overlap between an atlas segmentation and warped test scan segmentations, run:
./scripts/tf/test.py --model model.h5 --atlas atlas.npz --scans scan01.npz scan02.npz scan03.npz --labels labels.npzJust like for the training data, the atlas and test npz files includevol andseg parameters and thelabels.npz file contains a list of corresponding anatomical labels to include in the computed dice score.
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.
For our data, we foundimage_sigma=0.01 andprior_lambda=25 to work best.
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 usexy indexing anduse_miccai_int network option, with MICCAI2018 parameters.
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 usedxyindexing, whereas we are now emphasizingijindexing.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.
If you use VoxelMorph or some part of the code, please cite (seebibtex):
HyperMorph, avoiding the need to tune registration hyperparameters:
Learning the Effect of Registration Hyperparameters with HyperMorph
Andrew Hoopes,Malte Hoffmann, Bruce Fischl,John Guttag,Adrian V. Dalca
MELBA: Machine Learning for Biomedical Imaging. 2022.eprint arXiv:2203.16680HyperMorph: Amortized Hyperparameter Learning for Image Registration.
Andrew Hoopes,Malte Hoffmann, Bruce Fischl,John Guttag,Adrian V. Dalca
IPMI: Information Processing in Medical Imaging. 2021.eprint arXiv:2101.01035SynthMorph, avoiding the need to have data at training (!):
Anatomy-aware and acquisition-agnostic joint registration with SynthMorph.
Malte Hoffmann, Andrew Hoopes, Douglas N. Greve, Bruce Fischl,Adrian V. Dalca
Imaging Neuroscience. 2024.eprint arXiv:2301.11329Anatomy-specific acquisition-agnostic affine registration learned from fictitious images.
Malte Hoffmann, Andrew Hoopes, Bruce Fischl,Adrian V. Dalca
SPIE Medical Imaging: Image Processing. 2023.SynthMorph: learning contrast-invariant registration without acquired images.
Malte Hoffmann, Benjamin Billot,Juan Eugenio Iglesias, Bruce Fischl,Adrian V. Dalca
IEEE TMI: Transactions on Medical Imaging. 2022.eprint arXiv:2004.10282For the atlas formation model:
Learning Conditional Deformable Templates with Convolutional Networks
Adrian V. Dalca,Marianne Rakic,John Guttag,Mert R. Sabuncu
NeurIPS 2019.eprint arXiv:1908.02738For the diffeomorphic or probabilistic model:
Unsupervised Learning of Probabilistic Diffeomorphic Registration for Images and Surfaces
Adrian V. Dalca,Guha Balakrishnan,John Guttag,Mert R. Sabuncu
MedIA: Medial Image Analysis. 2019.eprint arXiv:1903.03545Unsupervised Learning for Fast Probabilistic Diffeomorphic Registration
Adrian V. Dalca,Guha Balakrishnan,John Guttag,Mert R. Sabuncu
MICCAI 2018.eprint arXiv:1805.04605For the original CNN model, MSE, CC, or segmentation-based losses:
VoxelMorph: A Learning Framework for Deformable Medical Image Registration
Guha Balakrishnan,Amy Zhao,Mert R. Sabuncu,John Guttag,Adrian V. Dalca
IEEE TMI: Transactions on Medical Imaging. 2019.eprint arXiv:1809.05231An Unsupervised Learning Model for Deformable Medical Image Registration
Guha Balakrishnan,Amy Zhao,Mert R. Sabuncu,John Guttag,Adrian V. Dalca
CVPR 2018.eprint arXiv:1802.02604
- keywords: machine learning, convolutional neural networks, alignment, mapping, registration
- data in papers: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-allsteps up to skull stripping and affine normalization to Talairach space, and crop the images via((48, 48), (31, 33), (3, 29)).
We encourage users to download and process their own data. Seea list of medical imaging datasets here. 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.
To experiment with this method, please usetrain_template.py for unconditional templates andtrain_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).
We've also provided an unconditional atlas indata/generated_uncond_atlas.npz.npy.
Models in h5 format weights are provided forunconditional atlas here, andconditional atlas here.
Explore the atlasesinteractively here with tipiX!
SynthMorph is a strategy for learning registration without acquired imaging data, producing powerful networks agnostic to contrast induced by MRI (eprint arXiv: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, visitsynthmorph.voxelmorph.net.
We provide model files for a"shapes" variant of SynthMorph, that we train using images synthesized from random shapes only, and a"brains" variant, 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 aselection of brain labels. For registration with either model, please use theregister.py script with the respective model weights.
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 areference image. The affine registration can be performed with a variety of packages, and we choose FreeSurfer. First, we skull-strip the images withSAMSEG, keeping brain labels only. Second, we runmri_robust_register:
mri_robust_register --mov in.nii.gz --dst out.nii.gz --lta transform.lta --satit --iscalemri_robust_register --mov in.nii.gz --dst out.nii.gz --lta transform.lta --satit --iscale --ixform transform.lta --affinewhere we replace--satit --iscale with--cost NMI for registration across MRI contrasts.
While we cannot release most of the data used in the VoxelMorph papers as they prohibit redistribution, we thorough processed andre-released OASIS1 while developingHyperMorph. We now include a quickVoxelMorph tutorial to train VoxelMorph on neurite-oasis data.
For any code-related problems or questions pleaseopen an issue orstart a discussion of general registration/VoxelMorph topics.
About
Unsupervised Learning for Image Registration
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors15
Uh oh!
There was an error while loading.Please reload this page.