MR data handling and image reconstruction.
Project description
MR data processing and image reconstruction.
This project is a faster moving continuation/fork of MRpro. Some of the additional features of mrtwo will eventually get backported to MRpro, all new features of MRpro will be included in mrtwo.
In most cases, you can replace mrpro by mr2 in you code and everything works.
- Source code: https://github.com/fzimmermann89/mr2
- Documentation: https://fzimmermann89.github.io/mr2/
- Bug reports: https://github.com/fzimmermann89/mr2/issues
- Try it out:
Main features
- Data handling Custom dataclasses for fast data subsetting, sorting, rearranging
- Neural Network Block Common blocks and networks used for ML based MRI reconstruction
- ISMRMRD support mrtwo supports ismrmrd-format for MR raw data.
- PyTorch All data containers utilize PyTorch tensors to ensure easy integration in PyTorch-based network schemes.
- Cartesian and non-Cartesian trajectories mrtwo can reconstruct data obtained with Cartesian and non-Cartesian (e.g. radial, spiral...) sapling schemes. mrtwo automatically detects if FFT or nuFFT is required to reconstruct the k-space data.
- Pulseq support If the data acquisition was carried out using a pulseq-based sequence, the seq-file can be provided to mrtwo and the used trajectory is automatically calculated.
- Signal models A range of different MR signal models are implemented (e.g. T1 recovery, WASABI).
- Regularized image reconstruction Regularized image reconstruction algorithms including Wavelet-based compressed sensing or total variation regularized image reconstruction are available.
Examples
In the following, we show some code snippets to highlight the use of mrtwo. Each code snippet only shows the main steps. A complete working notebook can be found in the provided link.
Simple reconstruction
Read the data and trajectory and reconstruct an image by applying a density compensation function and then the adjoint of the Fourier operator and the adjoint of the coil sensitivity operator.
# Read the trajectory from the ISMRMRD file
trajectory = mr2.data.traj_calculators.KTrajectoryIsmrmrd()
# Load in the Data from the ISMRMRD file
kdata = mr2.data.KData.from_file(data_file.name, trajectory)
# Perform the reconstruction
reconstruction = mr2.algorithms.reconstruction.DirectReconstruction(kdata)
img = reconstruction(kdata)
Full example: https://github.com/fzimmermann89/mr2/blob/main/examples/scripts/direct_reconstruction.py
Estimate quantitative parameters
Quantitative parameter maps can be obtained by creating a functional to be minimized and calling a non-linear solver such as ADAM.
# Define signal model
model = MagnitudeOp() @ InversionRecovery(ti=idata_multi_ti.header.ti)
# Define loss function and combine with signal model
mse = MSE(idata_multi_ti.data.abs())
functional = mse @ model
[...]
# Run optimization
params_result = adam(functional, [m0_start, t1_start], n_iterations=n_iterations, learning_rate=learning_rate)
Full example: https://github.com/fzimmermann89/mr2/blob/main/examples/scripts/qmri_sg_challenge_2024_t1.py
Pulseq support
The trajectory can be calculated directly from a provided pulseq-file.
# Read raw data and calculate trajectory using KTrajectoryPulseq
kdata = KData.from_file(data_file.name, KTrajectoryPulseq(seq_path=seq_file.name))
Full example: https://github.com/fzimmermann89/mr2/blob/main/examples/scripts/comparison_trajectory_calculators.py
Development
pip install -e ".[dev]"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mrtwo-0.260212.tar.gz.
File metadata
- Download URL: mrtwo-0.260212.tar.gz
- Upload date:
- Size: 259.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a9d664896dd170bebdbaeefcbe1f1b37e8e741564cc52074d58e6ea6c2a5ce0
|
|
| MD5 |
406fb64d9b7bc182189505bac0d183fc
|
|
| BLAKE2b-256 |
04bfefd51a0aa902ac56d6349b8a2f76e88711b7259878f3dffc6d756169968f
|
Provenance
The following attestation bundles were made for mrtwo-0.260212.tar.gz:
Publisher:
deployment.yml on fzimmermann89/mr2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mrtwo-0.260212.tar.gz -
Subject digest:
6a9d664896dd170bebdbaeefcbe1f1b37e8e741564cc52074d58e6ea6c2a5ce0 - Sigstore transparency entry: 947290350
- Sigstore integration time:
-
Permalink:
fzimmermann89/mr2@4cb354f64b13b1e3f4f0648652863b997328d756 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/fzimmermann89
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deployment.yml@4cb354f64b13b1e3f4f0648652863b997328d756 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mrtwo-0.260212-py3-none-any.whl.
File metadata
- Download URL: mrtwo-0.260212-py3-none-any.whl
- Upload date:
- Size: 346.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c42436d03e367f6d4ca1f3efeb5506441dbd8124d508b0b814383e0e9a50f36
|
|
| MD5 |
c630c70dadbaf59e27bc96e6aed35b71
|
|
| BLAKE2b-256 |
ac45bfdd2affb2ad5f08a9e6d29dea29dbe4394ff49a1546fe75b8f344bd1f3d
|
Provenance
The following attestation bundles were made for mrtwo-0.260212-py3-none-any.whl:
Publisher:
deployment.yml on fzimmermann89/mr2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mrtwo-0.260212-py3-none-any.whl -
Subject digest:
4c42436d03e367f6d4ca1f3efeb5506441dbd8124d508b0b814383e0e9a50f36 - Sigstore transparency entry: 947290351
- Sigstore integration time:
-
Permalink:
fzimmermann89/mr2@4cb354f64b13b1e3f4f0648652863b997328d756 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/fzimmermann89
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deployment.yml@4cb354f64b13b1e3f4f0648652863b997328d756 -
Trigger Event:
push
-
Statement type: