CalgarySliceDataset#

class deepinv.datasets.CalgarySliceDataset(root, transform=None, **kwargs)[source]#

Bases: FastMRISliceDataset

Dataset for Calgary-Campinas 12-coil raw brain kspace.

Loads Calgary h5 volumes of shape (num_slices, H, W, 2N), where slice dim is in image domain and H,W is kspace. The dataset loads and preprocesses all kspace slices per volume, of shape (2, N, H, W). These are fully-sampled for train/val volumes and masked for the test set.

Also computes the GT x, the magnitude root-sum-square reconstructions of shape (1, H, W), or torch.nan for the masked test set.

The dataset is loaded as a dict with keys 'x', 'y', 'params' when use_dict_output=True (default) or tuples (x, y, params) when False, where params optionally contains the sampling mask and, if desired, estimated coil_maps.

Note

The test set comes already masked, which deepinv.datasets.CalgarySliceTransform estimates. For the validation set, the data is fully-sampled. You can simulate masked data using precomputed Poisson-disk masks as follows

mask_file = f"R{acceleration}_{y.shape[-2]}x{y.shape[-1]}.npy"
torch.hub.download_url_to_file(f"https://huggingface.co/datasets/NKI-AI/direct-mri-masks/resolve/main/calgary_campinas_masks/{mask_file.name}", str(mask_file))
masks = np.load(mask_file) # (100, H, W) bool
mask = torch.from_numpy(masks[0]).float().unsqueeze(0).unsqueeze(0) # (1, 1, H, W)
y *= mask

Calgary kspace uses the opposite centering convention to deepinv, so it is converted here (a half-FOV checkerboard shift) so that y works directly with deepinv.physics.MultiCoilMRI.

Parameters:


Examples:

Download a Calgary test volume and load its middle slice:

>>> import deepinv as dinv
>>> from deepinv.datasets import CalgarySliceDataset, download_archive
>>> root = dinv.utils.get_cache_home() / "calgary"
>>> download_archive(dinv.utils.get_image_url("demo_calgary_test_e13991s3_P01536.7.h5"), root / "vol.h5")
>>> batch = CalgarySliceDataset(root, slice_index="middle", use_dict_output=True)[0]
>>> batch['y'].shape  # (2, N, H, W) multicoil k-space
torch.Size([2, 12, 218, 170])

Examples using CalgarySliceDataset:#

Reconstruct undersampled k-space for cardiac and brain MRI

Reconstruct undersampled k-space for cardiac and brain MRI