Skip to main content

Model-driven image registration

Project description

Description

Python implementation of model-based image coregistration for quantitative medical imaging applications.

The distribution comes with a number of common signal models and uses ITK-Elastix for deformable image registration.

CAUTION: mdreg is developed in public but is work in progress and backwards compatibility is not guaranteed. It is likely there WILL be breaking changes in future versions

Installation

Run pip install mdreg.

Example data

Example data in DICOM format are provided for testing the setup.

How to run

Input data must be image arrays in numpy format, with dimensions (x,y,z,t) or (x,y,t). To perform MDR on an image array im with default settings do:

from mdreg import MDReg

mdr = MDReg()
mdr.set_array(im)
mdr.fit()

These default settings will apply a linear signal model and coregistration as defined in the elastix parameter file Bsplines.txt.

Outputs

When fitting is complete the following data are available:

  • mdr.coreg: motion-corrected data are in the same dimensions as the original im.
  • mdr.deformation: the calculated deformation fields in format (x,y,d,t) or (x,y,z,d,t). The dimension d holds x, y components of the deformation field. The third z component exists if the input array is 3D.
  • mdr.fit: the model fit to the coregistered images in the same dimensions (x,y,z,t) or (x,y,t) as the original im.
  • mdr.par: the fitted parameters are in dimensions (x,z,p) or (x,y,z,p) (for 3D data), where p enumerates the model parameters.

Customization

MDR can be configured to apply different signal models and elastix coregistration settings. A number of example models and alternative elastix parameter files are included in the distribution as templates.

The following example fits a mono-exponential decay, uses a mask im_mask for co-registration and applies an elastix parameter file par_file optimized for a previous DTI-MRI study:

from mdreg import MDReg
from mdreg.models import exponential_decay

mdr = MDReg()
mdr.set_array(im)
mdr.set_mask(im_mask)
mdr.signal_model = exponential_decay
mdr.read_elastix(par_file)
mdr.fit()

im_mask must be a binary (0's and 1's) or boolean (True's and False's) image array in numpy format with the same dimensions as im.

The signal model often depends on fixed constants and signal parameters such as sequence parameters in MRI, or patient-specific constants. These should all be grouped in a list and set before running the signal model.

Equally elastix parameters can be fine tuned, either by importing a dedicated elastix file, or by modifying the settings.

You may also choose if you wish to run the process in multiple cores (parallel) and to print the co-registration progress to the terminal plus a text file (log) or not.

Then, a number of parameters are available to optimize MDR such as the precision (stopping criterion) and maximum number of iterations.

Some examples:

from mdreg import MDReg
from mdreg.models import exponential_decay

t = [0.0, 1.25, 2.50, 3.75]     # time points for exponential in sec

mdr = MDReg()
mdr.set_array(im)
mdr.signal_parameters = t
mdr.signal_model = exponential_decay
mdr.set_elastix(MaximumNumberOfIterations = 256)   # change defaults
mdr.precision = 0.5         # default = 1
mdr.max_iterations = 3      # default = 5
mdr.parallel = False        # default = True
mdr.log = True              # default = False
mdr.fit()

mdreg comes with a number of options to export results and diagnostics:

mdr.export_unregistered = True      # export parameters and fit without registration
mdr.export_path = filepath          # default is a results folder in the current working directory
mdr.export()                        # export results after calling fit. 

This export creates movies of original images, motion corrected images, modelfits, and maps of the fitted parameters.

Model fitting without motion correction

MDReg also can be used to perform model fitting without correcting the motion. The following script fits a linearised exponential model to each pixel and exports data of model and fit:

from mdreg import MDReg
from mdreg.models import exponential_decay

mdr = MDReg()
mdr.set_array(im)
mdr.signal_model = linear_exponential_decay
mdr.fit_signal()
mdr.export_data()
mdr.export_fit()

Defining new MDR models

A model must be defined as a separate module or class with two required functions main() and pars().

pars() must return a list of strings specifying the names of the model parameters. main(im, const) performs the pixel based model fitting and has two required arguments. im is a numpy ndarray with dimensions (x,y,z,t), (x,y,t) or (x,t). const is a list of any constant model parameters.

The function must return the fit to the model as an numpy ndarray with the same dimensions as im, and an ndarray pars with dimensions (x,y,z,p), (x,y,p) or (x,p). Here p enumerates the model parameters.

Context

mdreg was first developed for use in quantitative renal MRI in the iBEAt study, and validated against group-wise model-free registration (Tagkalakis F, et al. Model-based motion correction outperforms a model-free method in quantitative renal MRI. Abstract-1383, ISMRM 2021).

Acknowledgement

The iBEAt study is part of the BEAt-DKD project. The BEAt-DKD project has received funding from the Innovative Medicines Initiative 2 Joint Undertaking under grant agreement No 115974. This Joint Undertaking receives support from the European Union’s Horizon 2020 research and innovation programme and EFPIA with JDRF. For a full list of BEAt-DKD partners, see www.beat-dkd.eu.

Authors

Kanishka Sharma, Joao Almeida e Sousa, Steven Sourbron

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

mdreg-0.3.4.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdreg-0.3.4-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file mdreg-0.3.4.tar.gz.

File metadata

  • Download URL: mdreg-0.3.4.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.8

File hashes

Hashes for mdreg-0.3.4.tar.gz
Algorithm Hash digest
SHA256 9afbd23d3417f9570009d0300c9b001a86f79aa7a6670c08900d43de2a9eb3b8
MD5 d9ce9897493e5a2270027c333e138f6b
BLAKE2b-256 538e89bb979b810b86482df67a4ae8393cd66c7b43f73bcdf463d8647de0e74d

See more details on using hashes here.

File details

Details for the file mdreg-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: mdreg-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.8

File hashes

Hashes for mdreg-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1860bedd99a6f3c0f74ad937b648c1707aec8ab6fb6f3f131166e9a97cc38012
MD5 bac9fa14a263ad736b935650e08635ba
BLAKE2b-256 7dcec978beca9650814b8edcddba5a7ff5573543307070f960c0eb7feec17957

See more details on using hashes here.

Supported by

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