DynamicMRI#
- class deepinv.physics.DynamicMRI(mask=None, img_size=(320, 320), three_d=False, device='cpu', **kwargs)[source]#
-
Single-coil accelerated dynamic magnetic resonance imaging.
The linear operator operates in 2D+t videos and is defined as
\[y_t = M_t Fx_t\]where \(M_t\) applies a time-varying mask, and \(F\) is the 2D discrete Fourier Transform. This operator has a simple singular value decomposition, so it inherits the structure of
deepinv.physics.DecomposablePhysics
and thus have a fast pseudo-inverse and prox operators.The complex images \(x\) and measurements \(y\) should be of size (B, 2, T, H, W) where the first channel corresponds to the real part and the second channel corresponds to the imaginary part.
A fixed mask can be set at initialisation, or a new mask can be set either at forward (using
physics(x, mask=mask)
) or usingupdate_parameters
.Note
We provide various random mask generators (e.g. Cartesian undersampling) that can be used directly with this physics. See e.g.
deepinv.physics.generator.mri.RandomMaskGenerator
- Parameters:
mask (torch.Tensor) – binary mask, where 1s represent sampling locations, and 0s otherwise. The mask size can either be (H,W), (T,H,W), (C,T,H,W) or (B,C,T,H,W) where H, W are the image height and width, T is time-steps, C is channels (typically 2) and B is batch size.
img_size (tuple) – if mask not specified, flat mask of ones is created using
img_size
, whereimg_size
can be of any shape specified above. If mask provided,img_size
is ignored.device (torch.device) – cpu or gpu.
- Examples:
Single-coil accelerated 2D+t MRI operator:
>>> from deepinv.physics import DynamicMRI >>> seed = torch.manual_seed(0) # Random seed for reproducibility >>> x = torch.randn(1, 2, 2, 2, 2) # Define random video of shape (B,C,T,H,W) >>> mask = torch.rand_like(x) > 0.75 # Define random 4x subsampling mask >>> physics = DynamicMRI(mask=mask) # Physics with given mask >>> physics.update_parameters(mask=mask) # Alternatively set mask on-the-fly >>> physics(x) tensor([[[[[-0.0000, 0.7969], [-0.0000, -0.0000]], [[-0.0000, -1.9860], [-0.0000, -0.4453]]], [[[ 0.0000, 0.0000], [-0.8137, -0.0000]], [[-0.0000, -0.0000], [-0.0000, 1.1135]]]]])
- A(x, mask=None, **kwargs)[source]#
Applies the forward operator \(y = A(x)\).
If a mask/singular values is provided, it is used to apply the forward operator, and also stored as the current mask/singular values.
- Parameters:
x (torch.Tensor) – input tensor
mask (torch.nn.parameter.Parameter, float) – singular values.
- Returns:
output tensor
- Return type:
- A_adjoint(y, mask=None, mag=False, **kwargs)[source]#
Adjoint operator.
Optionally perform magnitude to reduce channel dimension.
- Parameters:
y (torch.Tensor) – input kspace of shape
(B,2,T,H,W)
mask (torch.Tensor) – optionally set mask on-the-fly, see class docs for shapes allowed.
mag (bool) – perform complex magnitude.
- A_dagger(y, mask=None, **kwargs)[source]#
Computes \(A^{\dagger}y = x\) in an efficient manner leveraging the singular vector decomposition.
- Parameters:
y (torch.Tensor) – a measurement \(y\) to reconstruct via the pseudoinverse.
- Returns:
(
torch.Tensor
) The reconstructed image \(x\).- Return type:
- check_mask(mask=None, **kwargs)[source]#
Updates MRI mask and verifies mask shape to be B,C,T,H,W.
:param torch.nn.parameter.Parameter, float MRI subsampling mask.
- noise(x, **kwargs)[source]#
Incorporates noise into the measurements \(\tilde{y} = N(y)\)
- Parameters:
x (torch.Tensor) – clean measurements
- Return torch.Tensor:
noisy measurements
- to_static(mask=None)[source]#
Convert dynamic MRI to static MRI by removing time dimension.
- Parameters:
mask (torch.Tensor) – new static MRI mask. If None, existing mask is flattened (summed) along the time dimension.
- Return MRI:
static MRI physics
- Return type:
Examples using DynamicMRI
:#

Self-supervised MRI reconstruction with Artifact2Artifact