DynamicMRI
- class deepinv.physics.DynamicMRI(mask: Tensor | None = None, img_size: tuple | None = (320, 320), three_d: bool = 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: Tensor, mask: Tensor | None = None, **kwargs) Tensor [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, float) – singular values.
- Returns:
(torch.Tensor) output tensor
- A_adjoint(y: Tensor, mask: Tensor | None = None, **kwargs) Tensor [source]
Computes the adjoint of the forward operator \(\tilde{x} = A^{\top}y\).
If a mask/singular values is provided, it is used to apply the adjoint operator, and also stored as the current mask/singular values.
- Parameters:
y (torch.Tensor) – input tensor
mask (torch.nn.Parameter, float) – singular values.
- Returns:
(torch.Tensor) output tensor
- A_dagger(y: Tensor, mask: Tensor | None = None, **kwargs) Tensor [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\).
- check_mask(mask: Tensor | None = None, **kwargs) None [source]
Updates MRI mask and verifies mask shape to be B,C,T,H,W.
:param torch.nn.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
Examples using DynamicMRI
:
Self-supervised MRI reconstruction with Artifact2Artifact