filenames_filter (Optional[list[Union[Path, str]]]) – List of filenames to include in the dataset, should be the same as the ones that can be
derived from a glob on the root. If set, will skip searching for files in the root. Default: None.
filenames_lists (Optional[list[Union[Path, str]]]) – List of paths pointing to .lst file(s) that contain file-names in root to filter.
Should be the same as the ones that can be derived from a glob on the root. If this is set, this will
override the filenames_filter option if not None. Default: None.
filenames_lists_root (Union[Path, str, None]) – Root of filenames_lists. Ignored if filename_lists is None.
Default: None.
regex_filter (Optional[str]) – Regular expression filter on the absolute filename. Will be applied after any filenames
filter. Default: None.
metadata – If given, this dictionary will be passed to the output transform. Default: None.
sensitivity_maps – Path to sensitivity maps, or None. Default: None.
extra_keys – Add extra keys in h5 file to output. Default: None.
pass_attrs – Pass the attributes saved in the h5 file. Default: False.
text_description – Description of dataset, can be useful for logging. Default: None.
kspace_context – K-space context. Default: None.
pass_dictionaries – Pass a dictionary of dictionaries, e.g. if {"name":{"filename_0":val}}, then to
filename_0``ssampledict,akeywithname``"name" and value val will be added.
Default: None.
pass_h5s (Optional[dict]) – Pass a dictionary of paths. If {"name":path} is given then to the sample of filename
the same slice of path/filename will be added to the sample dictionary and will be assigned key
"name". This can for instance be convenient when you want to pass sensitivity maps as well.
Default: None.
slice_data – If set, for instance to slice(50,-50) only data within this slice will be added to the
dataset. This is for instance convenient in the validation set of the public Calgary-Campinas dataset
as the first 50 and last 50 slices are excluded in the evaluation. Default: None.
Assuming the instructions in direct/projects/CMRxRecon have been followed, this dataset can be loaded
with different options:
Load the original fully sampled data by setting kspace_key = ‘kspace_full’.
Load the custom-made fully-sampled data containing provided masks by the challenge by setting
kspace_key``="kspace_full"and``extra_keys = [‘maskxx’,…] where ‘xx’ can be ‘04’, ‘08’ or ‘10’.
Load the original sub-sampled data by setting kspace_key = ‘kspace_subxx’ ‘xx’
can be ‘04’, ‘08’ or ‘10’. For this option, you can opt to compute the masks from
the sub-sampled k-space data by setting compute_mask = True.
Additionally, the dataset allows for the option to load 2D or 3D data:
If kspace_context = None, 2D data will be loaded.
If kspace_context = “time”, sequence 3D (2D + time) data will be loaded.
If kspace_context = “slice”, 3D (x, y, z) data will be loaded.
Parameters:
data_root (Path) – Root directory to data.
transform (Optional[Callable[[tuple[Any, ...]], dict]]) – A list of transforms to be applied on the generated samples. Default: None.
filenames_filter (Optional[list[Union[Path, str]]]) – List of filenames to include in the dataset, should be the same as the ones that can be derived from a glob on the root. If set, will skip searching for files in the root. Default: None.
filenames_lists (Optional[list[Union[Path, str]]]) – List of paths pointing to .lst file(s) that contain file-names in root to filter. Should be the same as the ones that can be derived from a glob on the root. If this is set, this will override the filenames_filter option if not None. Default: None.
filenames_lists_root (Union[Path, str, None]) – Root of filenames_lists. Ignored if filename_lists is None. Default: None.
kspace_key (str) – Key to load the k-space. Typically, ‘kspace_full’ for fully-sampled data, or ‘kspace_subxx’ (xx can be ‘04’, ‘08’ or ‘10) for sub-sampled data. Default: ‘kspace_full’.
extra_keys (Optional[tuple[str]]) – Add extra keys in h5 file to output. May be used to load sampling masks, e.g. “maskxx”. Note that this should contain at most one of the following “mask04”, “mask08” or “mask10”. Default: None.
text_description (Optional[str]) – Description of dataset, can be useful for logging.
compute_mask (bool) – If True, it will compute the sampling mask from data. This should be typically True at inference, where data are already undersampled. This will also compute acs_mask, which is by default the 24 center lines. Default: False.
kspace_context (Optional[str]) – Can be either None, “time” or “slice”. If None, data will be loaded per slice or time-frame (2D data). If “time”, all time frames(phases) per slice will be loaded (3D data). If “slice”, all sliced per time frame will be loaded (3D data). Default: None.
transform (Optional[Callable[[tuple[Any, ...]], dict]]) – A list of transforms to be applied on the generated samples. Default is None.
filenames_filter (Optional[list[Union[Path, str]]]) – List of filenames to include in the dataset, should be the same as the ones that can
be derived from a glob on the root. If set, will skip searching for files in the root. Default: None.
filenames_lists (Optional[list[Union[Path, str]]]) – List of paths pointing to .lst file(s) that contain file-names in root to filter.
Should be the same as the ones that can be derived from a glob on the root. If this is set,
this will override the filenames_filter option if not None. Default: None.
filenames_lists_root (Union[Path, str, None]) – Root of filenames_lists. Ignored if filename_lists is None. Default: None.
kspace_key (str) – Key to load the k-space. Typically, ‘kspace_full’ for fully-sampled data, or ‘kspace_subxx’
(xx can be ‘04’, ‘08’ or ‘10) for sub-sampled data. Default: ‘kspace_full’.
extra_keys (Optional[tuple[str]]) – Add extra keys in h5 file to output. May be used to load sampling masks, e.g. “maskxx”.
Note that this should contain at most one of the following “mask04”, “mask08” or “mask10”. Default: None.
text_description (Optional[str]) – Description of dataset, can be useful for logging.
compute_mask (bool) – If True, it will compute the sampling mask from data. This should be typically True at
inference, where data are already undersampled. This will also compute acs_mask, which is by default
the 24 center lines. Default: False.
kspace_context (Optional[str]) – Can be either None, “time” or “slice”. If None, data will be loaded per slice or
time-frame (2D data). If “time”, all time frames(phases) per slice will be loaded (3D data).
If “slice”, all sliced per time frame will be loaded (3D data). Default: None.
transform (Optional[Callable]) – A list of transforms to be applied on the generated samples. Default is None.
filenames_filter (Optional[list[Union[Path, str]]]) – List of filenames to include in the dataset, should be the same as the ones that can
be derived from a glob on the root. If set, will skip searching for files in the root. Default: None.
filenames_lists (Optional[list[Union[Path, str]]]) – List of paths pointing to .lst file(s) that contain file-names in root to filter.
Should be the same as the ones that can be derived from a glob on the root. If this is set,
this will override the filenames_filter option if not None. Default: None.
filenames_lists_root (Union[Path, str, None]) – Root of filenames_lists. Ignored if filename_lists is None. Default: None.
regex_filter (Optional[str]) – Regular expression filter on the absolute filename. Will be applied after any filenames filter.
pass_mask (bool) – If True this will load in the sample a sampling mask saved in the h5 file. Default: False.
pass_max (bool) – If True this will load the maximum k-space magnitude value saved in the h5 file.
initial_images (Optional[list[Path]]) – List of paths to initial images.
initial_images_key (Optional[str]) – Key for initial images.
noise_data (Optional[dict]) – Noise data dictionary.
pass_h5s (Optional[dict]) – Pass a dictionary of paths. If {“name”: path} is given then to the sample of filename the same
slice of path / filename will be added to the sample dictionary and will be asigned key name. This can
be convenient when you want to pass sensitivity maps. For instance: pass_h5s = {“sensitivity_map”:
“/data/sensitivity_maps”} will add to each output sample a key sensitivity_map with value a numpy array
containing the same slice of /data/sensitivity_maps/filename.h5 as the one of the original filename.h5.
filenames_filter (Optional[list[Union[Path, str]]]) – List of filenames to include in the dataset, should be the same as the ones that can be
derived from a glob on the root. If set, will skip searching for files in the root. Default: None.
filenames_lists (Optional[list[Union[Path, str]]]) – List of paths pointing to .lst file(s) that contain file-names in root to filter.
Should be the same as the ones that can be derived from a glob on the root. If this is set, this will
override the filenames_filter option if not None. Default: None.
filenames_lists_root (Union[Path, str, None]) – Root of filenames_lists. Ignored if filename_lists is None.
Default: None.
regex_filter (Optional[str]) – Regular expression filter on the absolute filename. Will be applied after any filenames
filter. Default: None.
metadata – If given, this dictionary will be passed to the output transform. Default: None.
sensitivity_maps – Path to sensitivity maps, or None. Default: None.
extra_keys – Add extra keys in h5 file to output. Default: None.
pass_attrs – Pass the attributes saved in the h5 file. Default: False.
text_description – Description of dataset, can be useful for logging. Default: None.
kspace_context – K-space context. Default: None.
pass_dictionaries – Pass a dictionary of dictionaries, e.g. if {"name":{"filename_0":val}}, then to
filename_0``ssampledict,akeywithname``"name" and value val will be added.
Default: None.
pass_h5s (Optional[dict]) – Pass a dictionary of paths. If {"name":path} is given then to the sample of filename
the same slice of path/filename will be added to the sample dictionary and will be assigned key
"name". This can for instance be convenient when you want to pass sensitivity maps as well.
Default: None.
slice_data – If set, for instance to slice(50,-50) only data within this slice will be added to the
dataset. This is for instance convenient in the validation set of the public Calgary-Campinas dataset
as the first 50 and last 50 slices are excluded in the evaluation. Default: None.
A PyTorch Dataset class which outputs random fake k-space images which reconstruct into Gaussian blobs.
Parameters:
sample_size (int) – Size of the dataset.
num_coils (int) – Number of coils for the fake k-space data.
spatial_shape (Union[list[int], tuple[int]]) – Shape of the reconstructed fake data. Should be (height, width) or (slice, height, width),
corresponding to ndim = 2 and ndim = 3.
transform (Optional[Callable]) – A list of transforms to be performed on the generated samples. Default is None.
seed (Optional[int]) – Seed. Default is None.
filenames (Union[list[str], str, None]) – Names for the generated samples. If string is given, a number order starting from “00001” is
appended to the name of each sample.
pass_attrs (Optional[bool]) – Pass the attributes of the generated sample.
text_description (Optional[str]) – Description of dataset, can be useful for logging.
kspace_context (Optional[bool]) – If true corresponds to 3D reconstruction, else reconstruction is 2D.
num_coils (int) – Number of coils for the fake k-space data.
spatial_shape (Union[list[int], tuple[int]]) – Shape of the reconstructed fake data. Should be (height,width) or
(slice,height,width), corresponding to ndim=2 and ndim=3.
transform (Optional[Callable]) – A list of transforms to be performed on the generated samples. Default: None.
seed (Optional[int]) – Random seed. Default: None.
filenames (Union[list[str], str, None]) – Names for the generated samples. If string is given, a number order starting from "00001"
is appended to the name of each sample. Default: None.
pass_attrs (Optional[bool]) – Pass the attributes of the generated sample. Default: None.
text_description (Optional[str]) – Description of dataset, can be useful for logging. Default: None.
kspace_context (Optional[bool]) – If True corresponds to 3D reconstruction, else reconstruction is 2D. Default: None.
Returns default parameters of ellipsoids as in [1]_.
Return type:
ndarray
Returns:
Array containing the parameters for the ellipsoids used to construct the phantom. Each row of the form
[x, y, z, a, b, c, theta, m_0, A, C, T1, T2, chi] represents an ellipsoid, where:
(x, y, z): denotes the center of the ellipsoid
(a, b, c): denote the lengths of the semi-major axis aligned with the x, y, z-axis, respectively
theta: denotes the rotation angle of the ellipsoid in rads
m_0: denotes the spin density
(A, C): denote the T1 parameters
T1: denotes the T1 value if explicit, otherwise T1 = A × B_0^C
Type of transforms. By default the transforms are set for supervised learning (TransformsType.SUPERVISED).
To use SSL transforms, set transforms_type to SSL_SSDU. This will require additional parameters to be set:
mask_split_ratio, mask_split_acs_region, mask_split_keep_acs, mask_split_type, mask_split_gaussian_std.
Default is TransformsType.SUPERVISED.
Standard deviation of the Gaussian mask splitter. Ignored if mask_split_type is not MaskSplitterType.GAUSSIAN.
Ignored if transforms_type is not SSL_SSDU. Default is 3.0.
Direction to split the mask if mask_split_type is MaskSplitterType.HALF.
Ignored if MaskSplitterType is not HALF or transforms_type is not SSL_SSDU.
Default is HalfSplitType.VERTICAL.
Returns fake mri samples in the form of gaussian blobs.
Parameters:
sample_size (int) – Size of the samples. Default: 1.
num_coils (int) – Number of simulated coils. Default: 1.
spatial_shape (Union[List[int], Tuple[int, ...]]) – Must be (slice,height,width) or (height,width). Default: (100,100).
name (Union[str, List[str]]) – Name of file. Default: "fake_mri_sample".
seed (Optional[int]) – Random seed. Default: None.
root (Optional[Path]) – Root to save data. To be used with save_as_h5=True. Default: None.
Returns:
"kspace" of shape (slice,num_coils,height,width)
and "reconstruction_rss" of shape (slice,height,width). If spatial_shape is of shape 2
(height,width), slice=1.
filenames_filter (Optional[List[Union[Path, str]]]) – List of filenames to include in the dataset, should be the same as the ones that can be
derived from a glob on the root. If set, will skip searching for files in the root. Default: None.
filenames_lists (Optional[List[Union[Path, str]]]) – List of paths pointing to .lst file(s) that contain file-names in root to filter.
Should be the same as the ones that can be derived from a glob on the root. If this is set, this will
override the filenames_filter option if not None. Default: None.
filenames_lists_root (Union[Path, str, None]) – Root of filenames_lists. Ignored if filename_lists is None.
Default: None.
regex_filter (Optional[str]) – Regular expression filter on the absolute filename. Will be applied after any filenames
filter. Default: None.
pass_dictionaries (Optional[Dict[str, Dict]]) – Pass a dictionary of dictionaries, e.g. if {"name":{"filename_0":val}}, then to
filename_0``ssampledict,akeywithname``"name" and value val will be added.
Default: None.
pass_h5s (Optional[Dict[str, List]]) – Pass a dictionary of paths. If {"name":path} is given then to the sample of filename
the same slice of path/filename will be added to the sample dictionary and will be assigned key
"name". This can for instance be convenient when you want to pass sensitivity maps as well.
Default: None.
slice_data (Optional[slice]) – If set, for instance to slice(50,-50) only data within this slice will be added to the
dataset. This is for instance convenient in the validation set of the public Calgary-Campinas dataset
as the first 50 and last 50 slices are excluded in the evaluation. Default: None.
The direct.data.mri_transforms module contains mri transformations utilized to transform or augment k-space data,
used for DIRECT’s training pipeline. They can be also used individually by importing them into python scripts.
use_seed (bool) – If true, a pseudo-random number based on the filename is computed so that every slice of the
volume get the same mask every time. Default: True.
return_acs (bool) – If True, it will generate an ACS mask. Default: False.
Data Transformer for training MRI reconstruction models.
Masks the input k-space (with key input_kspace_key) using a sampling mask with key sampling_mask_key onto
a new masked k-space with key target_kspace_key.
crop (Union[str, tuple[int, ...], list[int]]) – Shape to crop the input to or a string pointing to a crop key (e.g. reconstruction_size).
forward_operator (Callable) – The forward operator, e.g. some form of FFT (centered or uncentered).
Default: direct.data.transforms.fft2.
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
Default: direct.data.transforms.ifft2.
image_space_center_crop (bool) – If set, the crop in the data will be taken in the center.
random_crop_sampler_type (Optional[str]) – If “uniform” the random cropping will be done by uniformly sampling crop,
as opposed to gaussian which will sample from a gaussian distribution. If image_space_center_crop
is True, then this is ignored. Default: “uniform”.
random_crop_sampler_use_seed (Optional[bool]) – If true, a pseudo-random number based on the filename is computed so that
every slice of the volume is cropped the same way. Default: True.
random_crop_sampler_gaussian_sigma (Optional[list[float]]) – Standard variance of the gaussian when random_crop_sampler_type
is gaussian. If image_space_center_crop is True, then this is ignored. Default: None.
Rescales the k-space:
* It first projects the k-space to the image-domain via the backward operator,
* It rescales the back-projected k-space to specified shape,
* It transforms the rescaled back-projected k-space to the k-space domain via the forward operator.
Parameters:
shape (Union[tuple[int, int], list[int]]) – Shape to rescale the input. Must be correspond to (height, width).
forward_operator (Callable) – The forward operator, e.g. some form of FFT (centered or uncentered).
shape (Union[tuple[int, int], list[int]]) – Shape to rescale the input. Must be correspond to (height, width).
forward_operator (Callable) – The forward operator, e.g. some form of FFT (centered or uncentered).
Default: direct.data.transforms.fft2.
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
Default: direct.data.transforms.ifft2.
rescale_mode (RescaleMode) – Mode to be used for rescaling. Can be RescaleMode.AREA, RescaleMode.BICUBIC,
RescaleMode.BILINEAR, RescaleMode.NEAREST, RescaleMode.NEAREST_EXACT, or RescaleMode.TRILINEAR.
Note that not all modes are supported for 2D or 3D data. Default: RescaleMode.NEAREST.
rescale_2d_if_3d (Optional[bool]) – If True and input k-space data is 3D, rescaling will be done only on the height and
width dimensions, by combining the slice/time dimension with the batch dimension. Default: False.
Rescales the k-space by:
* It first projects the k-space to the image-domain via the backward operator,
* It pads the back-projected k-space to specified shape,
* It transforms the rescaled back-projected k-space to the k-space domain via the forward operator.
Parameters:
pad_shape (Union[tuple[int, ...], list[int]]) – Shape to zero-pad the input. Must be correspond to (height, width) or (slice/time, height, width).
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
type_reconstruction (ReconstructionType) – Type of reconstruction. Can be ReconstructionType.RSS, ReconstructionType.COMPLEX,
ReconstructionType.COMPLEX_MOD, ReconstructionType.SENSE, ReconstructionType.SENSE_MOD or
ReconstructionType.IFFT. Default: ReconstructionType.RSS.
sample (dict[str, Any]) – Contains key kspace_key with value a torch.Tensor of shape (coil, *spatial_dims, complex=2).
Return type:
dict[str, Any]
Returns:
Dict with key target_key with value a torch.Tensor of shape (*spatial_dims) if type_reconstruction is
ReconstructionType.RSS, ReconstructionType.COMPLEX_MOD, ReconstructionType.SENSE_MOD, and of shape
(*spatial_dims, complex_dim=2) otherwise.
mask_func (Callable) – A function which creates a sampling mask of the appropriate shape.
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
use_seed (bool) – If true, a pseudo-random number based on the filename is computed so that every slice of the
volume get the same mask every time. Default: True.
Data Transformer for training MRI reconstruction models.
Estimates sensitivity maps given masked k-space data using one of three methods:
Unit: unit sensitivity map in case of single coil acquisition.
RSS-estimate: sensitivity maps estimated by using the root-sum-of-squares of the autocalibration-signal.
ESPIRIT: sensitivity maps estimated with the ESPIRIT method [1]_. Note that this is currently not
implemented for 3D data, and attempting to use it in such cases will result in a NotImplementedError.
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
type_of_map (Optional[SensitivityMapType]) – Type of map to estimate. Can be SensitivityMapType.RSS_ESTIMATE, SensitivityMapType.UNIT or
SensitivityMapType.ESPIRIT. Default: SensitivityMapType.RSS_ESTIMATE.
gaussian_sigma (Optional[float]) – If non-zero, acs_image well be calculated.
espirit_threshold (Optional[float]) – Threshold for the calibration matrix when type_of_map is set to
SensitivityMapType.ESPIRIT. Default: 0.05.
espirit_kernel_size (Optional[int]) – Kernel size for the calibration matrix when type_of_map is set to
SensitivityMapType.ESPIRIT. Default: 6.
espirit_crop (Optional[float]) – Output eigenvalue cropping threshold when type_of_map is set to
SensitivityMapType.ESPIRIT. Default: 0.95.
espirit_max_iters (Optional[int]) – Power method iterations when type_of_map is set to SensitivityMapType.ESPIRIT.
Default: 30.
normalize_key (Optional[TransformKey]) – Key name to compute the data for. If the maximum has to be computed on the ACS, ensure the
reconstruction on the ACS is available (typically body_coil_image). Default: “masked_kspace”.
percentile (Optional[float]) – Rescale data with the given percentile. If None, the division is done by the maximum. Default: 0.99.
scaling_factor_key (TransformKey) – Name of how the scaling factor will be stored. Default: “scaling_factor”.
More specifically, the following transformations are applied:
Converts input to (complex-valued) tensor.
Applies k-space (center) crop if requested.
Applies random augmentations (rotation, flip, reverse) if requested.
Adds a sampling mask if mask_func is defined.
Pads the coil dimension if requested.
Parameters:
forward_operator (Callable) – The forward operator, e.g. some form of FFT (centered or uncentered).
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
mask_func (Optional[Callable]) – A function which creates a sampling mask of the appropriate shape.
crop (Union[tuple[int, int], str, None]) – If not None, this will transform the “kspace” to an image domain, crop it, and transform it back.
If a tuple of integers is given then it will crop the backprojected kspace to that size. If
“reconstruction_size” is given, then it will crop the backprojected kspace according to it, but
a key “reconstruction_size” must be present in the sample. Default: None.
crop_type (Optional[str]) – Type of cropping, either “gaussian” or “uniform”. This will be ignored if crop is None. Default: “uniform”.
rescale (Union[tuple[int, int], list[int], None]) – If not None, this will transform the “kspace” to the image domain, rescale it, and transform it back.
Must correspond to (height, width). This is ignored if rescale is None. Default: None.
It is not recommended to be used in combination with crop.
rescale_mode (Optional[RescaleMode]) – Mode to be used for rescaling. Can be RescaleMode.AREA, RescaleMode.BICUBIC, RescaleMode.BILINEAR,
RescaleMode.NEAREST, RescaleMode.NEAREST_EXACT, or RescaleMode.TRILINEAR. Note that not all modes are
supported for 2D or 3D data. Default: RescaleMode.NEAREST.
rescale_2d_if_3d (Optional[bool]) – If True and k-space data is 3D, rescaling will be done only on the height
and width dimensions, by combining the slice/time dimension with the batch dimension.
This is ignored if rescale is None. Default: False.
pad (Union[tuple[int, int], list[int], None]) – If not None, this will zero-pad the “kspace” to the given size. Must correspond to (height, width)
or (slice/time, height, width). Default: None.
image_center_crop (bool) – If True the backprojected kspace will be cropped around the center, otherwise randomly.
This will be ignored if crop is None. Default: True.
random_rotation_degrees (Optional[Sequence[int]]) – Sequence of integers. Default: (-90, 90).
random_rotation_probability (float) – If greater than 0.0, random rotations will be applied of random_rotation_degrees degrees, with probability random_rotation_probability. Default: 0.0.
random_flip_probability (float) – If greater than 0.0, random rotation of random_flip_type type, with probability random_flip_probability. Default: 0.0.
estimate_body_coil_image (bool) – Estimate body coil image. Default: False.
use_seed (bool) – If true, a pseudo-random number based on the filename is computed so that every slice of the volume get
the same mask every time. Default: True.
Builds post (can be put on gpu) supervised MRI transforms.
More specifically, the following transformations are applied:
Adds coil sensitivities and / or the body coil_image
Masks the fully sampled k-space, if there is a mask function or a mask in the sample.
Computes a scaling factor based on the masked k-space and normalizes data.
Computes a target (image).
Deletes the acs mask and the fully sampled k-space if requested.
Parameters:
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
estimate_sensitivity_maps (bool) – Estimate sensitivity maps using the acs region. Default: True.
sensitivity_maps_type (SensitivityMapType) – Can be SensitivityMapType.RSS_ESTIMATE, SensitivityMapType.UNIT or SensitivityMapType.ESPIRIT. Will be ignored if estimate_sensitivity_maps is equal to False. Default: SensitivityMapType.RSS_ESTIMATE.
sensitivity_maps_gaussian (Optional[float]) – Optional sigma for gaussian weighting of sensitivity map.
sensitivity_maps_espirit_threshold (Optional[float]) – Threshold for the calibration matrix when type_of_map is equal to “espirit”. Default: 0.05.
sensitivity_maps_espirit_kernel_size (Optional[int]) – Kernel size for the calibration matrix when type_of_map is equal to “espirit”. Default: 6.
sensitivity_maps_espirit_crop (Optional[float]) – Output eigenvalue cropping threshold when type_of_map is equal to “espirit”. Default: 0.95.
sensitivity_maps_espirit_max_iters (Optional[int]) – Power method iterations when type_of_map is equal to “espirit”. Default: 30.
delete_acs_mask (bool) – If True will delete key acs_mask. Default: True.
delete_kspace (bool) – If True will delete key kspace (fully sampled k-space). Default: True.
image_recon_type (ReconstructionType) – Type to reconstruct target image. Default: ReconstructionType.RSS.
scaling_key (TransformKey) – Key in sample to scale scalable items in sample. Default: TransformKey.MASKED_KSPACE.
scale_percentile (Optional[float]) – Data will be rescaled with the given percentile. If None, the division is done by the maximum. Default: 0.99
More specifically, the following transformations are applied:
Converts input to (complex-valued) tensor.
Applies k-space (center) crop if requested.
Applies k-space rescaling if requested.
Applies k-space padding if requested.
Applies random augmentations (rotation, flip, reverse) if requested.
Adds a sampling mask if mask_func is defined.
Compreses the coil dimension if requested.
Pads the coil dimension if requested.
Adds coil sensitivities and / or the body coil_image
Masks the fully sampled k-space, if there is a mask function or a mask in the sample.
Computes a scaling factor based on the masked k-space and normalizes data.
Computes a target (image).
Deletes the acs mask and the fully sampled k-space if requested.
Parameters:
forward_operator (Callable) – The forward operator, e.g. some form of FFT (centered or uncentered).
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
mask_func (Optional[Callable]) – A function which creates a sampling mask of the appropriate shape.
crop (Union[tuple[int, int], str, None]) – If not None, this will transform the “kspace” to an image domain, crop it, and transform it back.
None (If not)
domain (this will transform the "kspace" to an image)
it (then it will crop the backprojected kspace according to)
back. (and transform it)
given (If a tuple of integers is given then it will crop the backprojected kspace to that size. If "reconstruction_size" is) – None.
it – None.
Default (Estimate body coil image.) – None.
crop_type (Optional[str]) – Type of cropping, either “gaussian” or “uniform”. This will be ignored if crop is None. Default: “uniform”.
rescale (Union[tuple[int, int], list[int], None]) – If not None, this will transform the “kspace” to the image domain, rescale it, and transform it back. Must correspond to (height, width). This is ignored if rescale is None. Default: None. It is not recommended to be used in combination with crop.
rescale_mode (Optional[RescaleMode]) – Mode to be used for rescaling. Can be RescaleMode.AREA, RescaleMode.BICUBIC, RescaleMode.BILINEAR, RescaleMode.NEAREST, RescaleMode.NEAREST_EXACT, or RescaleMode.TRILINEAR. Note that not all modes are supported for 2D or 3D data. Default: RescaleMode.NEAREST.
rescale_2d_if_3d (Optional[bool]) – If True and k-space data is 3D, rescaling will be done only on the height and width dimensions, by combining the slice/time dimension with the batch dimension. This is ignored if rescale is None. Default: False.
pad (Union[tuple[int, int], list[int], None]) – If not None, this will zero-pad the “kspace” to the given size. Must correspond to (height, width) or (slice/time, height, width). Default: None.
image_center_crop (bool) – If True the backprojected kspace will be cropped around the center, otherwise randomly. This will be ignored if crop is None. Default: True.
random_rotation_degrees (Optional[Sequence[int]]) – Sequence of integers. Default: (-90, 90).
random_rotation_probability (float) – If greater than 0.0, random rotations will be applied of random_rotation_degrees degrees, with probability random_rotation_probability. Default: 0.0.
random_flip_probability (float) – If greater than 0.0, random rotation of random_flip_type type, with probability random_flip_probability. Default: 0.0.
random_reverse_probability (float) – If greater than 0.0, will perform random reversion along the time or slice dimension (2) with probability random_reverse_probability. Default: 0.0.
estimate_body_coil_image (bool) – Estimate body coil image. Default: False.
Default – False.
estimate_sensitivity_maps (bool) – Estimate sensitivity maps using the acs region. Default: True.
sensitivity_maps_type (SensitivityMapType) – Can be SensitivityMapType.RSS_ESTIMATE, SensitivityMapType.UNIT or SensitivityMapType.ESPIRIT. Will be ignored if estimate_sensitivity_maps is False. Default: SensitivityMapType.RSS_ESTIMATE.
sensitivity_maps_gaussian (Optional[float]) – Optional sigma for gaussian weighting of sensitivity map.
sensitivity_maps_espirit_threshold (Optional[float]) – Threshold for the calibration matrix when type_of_map is set to SensitivityMapType.ESPIRIT. Default: 0.05.
sensitivity_maps_espirit_kernel_size (Optional[int]) – Kernel size for the calibration matrix when type_of_map is set to SensitivityMapType.ESPIRIT. Default: 6.
sensitivity_maps_espirit_crop (Optional[float]) – Output eigenvalue cropping threshold when type_of_map is set to SensitivityMapType.ESPIRIT. Default: 0.95.
sensitivity_maps_espirit_max_iters (Optional[int]) – Power method iterations when type_of_map is set to SensitivityMapType.ESPIRIT. Default: 30.
delete_acs_mask (bool) – If True will delete key acs_mask. Default: True.
delete_kspace (bool) – If True will delete key kspace (fully sampled k-space). Default: True.
kspace (If True will delete key) – True.
image_recon_type (ReconstructionType) – Type to reconstruct target image. Default: ReconstructionType.RSS.
compress_coils (Optional[int]) – Number of coils to compress input k-space. It is not recommended to be used in combination with pad_coils. Default: None.
pad_coils (Optional[int]) – Number of coils to pad data to.
scaling_key (TransformKey) – Key in sample to scale scalable items in sample. Default: TransformKey.MASKED_KSPACE.
scale_percentile (Optional[float]) – Data will be rescaled with the given percentile. If None, the division is done by the maximum. Default: 0.99
use_seed (bool) – If true, a pseudo-random number based on the filename is computed so that every slice of the volume get the same mask every time. Default: True.
More specifically, the following transformations are applied:
Converts input to (complex-valued) tensor.
Applies k-space (center) crop if requested.
Applies k-space rescaling if requested.
Applies k-space padding if requested.
Applies random augmentations (rotation, flip, reverse) if requested.
Adds a sampling mask if mask_func is defined.
Compreses the coil dimension if requested.
Pads the coil dimension if requested.
Adds coil sensitivities and / or the body coil_image
Masks the fully sampled k-space, if there is a mask function or a mask in the sample.
Computes a scaling factor based on the masked k-space and normalizes data.
Computes a target (image).
Deletes the acs mask and the fully sampled k-space if requested.
Splits the mask if requested for self-supervised learning.
Parameters:
forward_operator (Callable) – The forward operator, e.g. some form of FFT (centered or uncentered).
backward_operator (Callable) – The backward operator, e.g. some form of inverse FFT (centered or uncentered).
mask_func (Optional[Callable]) – A function which creates a sampling mask of the appropriate shape.
crop (Union[tuple[int, int], str, None]) – If not None, this will transform the “kspace” to an image domain, crop it, and transform it back.
None (If not)
domain (this will transform the "kspace" to an image)
it (then it will crop the backprojected kspace according to)
back. (and transform it)
given (If a tuple of integers is given then it will crop the backprojected kspace to that size. If "reconstruction_size" is) – None.
it – None.
Default (but a key "reconstruction_size" must be present in the sample.) – None.
crop_type (Optional[str]) – Type of cropping, either “gaussian” or “uniform”. This will be ignored if crop is None. Default: “uniform”.
rescale (Union[tuple[int, int], list[int], None]) – If not None, this will transform the “kspace” to the image domain, rescale it, and transform it back. Must correspond to (height, width). This is ignored if rescale is None. Default: None. It is not recommended to be used in combination with crop.
rescale_mode (Optional[RescaleMode]) – Mode to be used for rescaling. Can be RescaleMode.AREA, RescaleMode.BICUBIC, RescaleMode.BILINEAR, RescaleMode.NEAREST, RescaleMode.NEAREST_EXACT, or RescaleMode.TRILINEAR. Note that not all modes are supported for 2D or 3D data. Default: RescaleMode.NEAREST.
rescale_2d_if_3d (Optional[bool]) – If True and k-space data is 3D, rescaling will be done only on the height and width dimensions, by combining the slice/time dimension with the batch dimension. This is ignored if rescale is None. Default: False.
pad (Union[tuple[int, int], list[int], None]) – If not None, this will zero-pad the “kspace” to the given size. Must correspond to (height, width) or (slice/time, height, width). Default: None.
image_center_crop (bool) – If True the backprojected kspace will be cropped around the center, otherwise randomly. This will be ignored if crop is None. Default: True.
random_rotation_degrees (Optional[Sequence[int]]) – Sequence of integers. Default: (-90, 90).
random_rotation_probability (float) – If greater than 0.0, random rotations will be applied of random_rotation_degrees degrees, with probability random_rotation_probability. Default: 0.0.
random_flip_probability (float) – If greater than 0.0, random rotation of random_flip_type type, with probability random_flip_probability. Default: 0.0.
RescaleMode.AREA (Mode to be used for rescaling. Can be)
RescaleMode.BICUBIC
RescaleMode.BILINEAR
:param :
:param RescaleMode.NEAREST:
:param RescaleMode.NEAREST_EXACT:
:param or RescaleMode.TRILINEAR. Note that not all modes are:
:param supported for 2D or 3D data. Default: RescaleMode.NEAREST.
:param rescale_2d_if_3d: If True and k-space data is 3D, rescaling will be done only on the height and width dimensions, by combining the slice/time dimension with the batch dimension. This is ignored if rescale is None. Default: False.
:param pad: If not None, this will zero-pad the “kspace” to the given size. Must correspond to (height, width) or (slice/time, height, width). Default: None.
:param image_center_crop: If True the backprojected kspace will be cropped around the center, otherwise randomly.
This will be ignored if crop is None. Default: True.
Parameters:
random_rotation_degrees – Sequence of integers. Default: (-90, 90).
random_rotation_probability – If greater than 0.0, random rotations will be applied of random_rotation_degrees degrees, with probability random_rotation_probability. Default: 0.0.
random_flip_probability – If greater than 0.0, random rotation of random_flip_type type, with probability random_flip_probability. Default: 0.0.
random_reverse_probability (float) – If greater than 0.0, will perform random reversion along the time or slice dimension (2) with probability random_reverse_probability. Default: 0.0.
estimate_body_coil_image (bool) – Estimate body coil image. Default: False.
estimate_sensitivity_maps (bool) – Estimate sensitivity maps using the acs region. Default: True.
sensitivity_maps_type (SensitivityMapType) – Can be SensitivityMapType.RSS_ESTIMATE, SensitivityMapType.UNIT or SensitivityMapType.ESPIRIT. Will be ignored if estimate_sensitivity_maps is False. Default: SensitivityMapType.RSS_ESTIMATE.
sensitivity_maps_gaussian (Optional[float]) – Optional sigma for gaussian weighting of sensitivity map.
sensitivity_maps_espirit_threshold (Optional[float]) – Threshold for the calibration matrix when type_of_map is set to SensitivityMapType.ESPIRIT.
sensitivity_maps_espirit_kernel_size (Optional[int]) – Kernel size for the calibration matrix when type_of_map is set to SensitivityMapType.ESPIRIT. Default: 6.
sensitivity_maps_espirit_crop (Optional[float]) – Output eigenvalue cropping threshold when type_of_map is set to SensitivityMapType.ESPIRIT. Default: 0.95.
sensitivity_maps_espirit_max_iters (Optional[int]) – Power method iterations when type_of_map is set to SensitivityMapType.ESPIRIT. Default: 30.
delete_acs_mask (bool) – If True will delete key acs_mask. Default: True.
delete_kspace (bool) – If True will delete key kspace (fully sampled k-space). Default: True.
image_recon_type (ReconstructionType) – Type to reconstruct target image. Default: ReconstructionType.RSS.
compress_coils (Optional[int]) – Number of coils to compress input k-space. It is not recommended to be used in combination with pad_coils. Default: None.
pad_coils (Optional[int]) – Number of coils to pad data to.
scaling_key (TransformKey) – Key in sample to scale scalable items in sample. Default: TransformKey.MASKED_KSPACE.
scale_percentile (Optional[float]) – Data will be rescaled with the given percentile. If None, the division is done by the maximum. Default: 0.99
use_seed (bool) – If true, a pseudo-random number based on the filename is computed so that every slice of the volume get the same mask every time. Default: True.
transforms_type (Optional[TransformsType]) – Can be TransformsType.SUPERVISED for supervised learning transforms or TransformsType.SSL_SSDU for self-supervised learning transforms. Default: TransformsType.SUPERVISED.
mask_split_ratio (Union[float, list[float], tuple[float, ...]]) – The ratio(s) of the sampling mask splitting. If transforms_type is TransformsKey.SUPERVISED, this is ignored.
mask_split_acs_region (Union[list[int], tuple[int, int]]) – A rectangle for the acs region that will be used in the input mask. This applies only if transforms_type is set to TransformsKey.SSL_SSDU. Default: (0, 0).
mask_split_keep_acs (Optional[bool]) – If True, acs region according to the “acs_mask” of the sample will be used in both mask splits. This applies only if transforms_type is set to TransformsKey.SSL_SSDU. Default: False.
mask_split_type (MaskSplitterType) – How the sampling mask will be split. Can be MaskSplitterType.UNIFORM, MaskSplitterType.GAUSSIAN, or
Default (set to TransformsKey.SSL_SSDU.) – MaskSplitterType.GAUSSIAN. This applies only if transforms_type is
Default – MaskSplitterType.GAUSSIAN.
mask_split_gaussian_std (float) – Standard deviation of gaussian mask splitting. This applies only if transforms_type is
MaskSplitterType.GAUSSIAN. (set to TransformsKey.SSL_SSDU. Ignored if mask_split_type is not set to)
Default – 3.0.
mask_split_half_direction (HalfSplitType) – Split type if mask_split_type is MaskSplitterType.HALF. Can be HalfSplitType.VERTICAL, HalfSplitType.HORIZONTAL, HalfSplitType.DIAGONAL_LEFT or HalfSplitType.DIAGONAL_RIGHT. This applies only if transforms_type is set to TransformsKey.SSL_SSDU. Ignored if mask_split_type is not set to MaskSplitterType.HALF. Default: HalfSplitType.VERTICAL.
In training, we only care about the “infinite stream” of training data.
So this sampler produces an infinite stream of indices and all workers cooperate to correctly shuffle the indices
and sample different indices. The samplers in each worker effectively produces indices[worker_id::num_workers]
where indices is an infinite stream of indices consisting of shuffle(range(size))+shuffle(range(size))+...
(if shuffle is True) or range(size)+range(size)+... (if shuffle is False).
Sequential Sampler that restricts data loading to a subset of the dataset.
It is useful during evaluation. It is especially useful when combined with
torch.nn.parallel.DistributedDataParallel. Such that each process gets a subpart of the dataset.
This module contains functions for complex-valued data manipulation in PyTorch. This includes functions for complex
multiplication, division, modulus, fft, ifft, fftshift, ifftshift, and more. The functions are designed to work with
complex-valued data where the last axis denotes the real and imaginary parts respectively. The functions are designed to
work with complex-valued data where the last axis denotes the real and imaginary parts respectively.
For an input tensor of size (N,...,2) where the last dimension of size 2 represents the real and imaginary
components of complex numbers, this function returns a new complex tensor of size (N,...).
Parameters:
data – Input data with torch.dtypetorch.float64 and torch.float32 with complex axis
(last) of dimension 2 and of shape (N,*,2).
Returns:
Output complex-valued data of shape (N,*) with complex torch.dtype.
For an input complex tensor of size (N,...) this function returns a new real tensor of size (N,...,2)
where the last dimension of size 2 represents the real and imaginary components of complex numbers.
Parameters:
data – Input data with complex torch.dtype of shape (N,*).
Apply centered two-dimensional Inverse Fast Fourier Transform.
Can be performed in half precision when input shapes are powers of two. Version for PyTorch >= 1.7.0.
Parameters:
data (Tensor) – Complex-valued input tensor. Should be of shape (*,2) and dim is in *.
dim (tuple[int, int]) – Dimensions over which to compute. Should be positive. Negative indexing not supported.
Default: (1,2), corresponding to ('height','width').
centered (bool) – Whether to apply a centered fft (center of kspace is in the center versus in the corners).
For FastMRI dataset this has to be True and for the Calgary-Campinas dataset False.
Default: True.
normalized (bool) – Whether to normalize the fft. For the FastMRI this has to be True and for the Calgary-Campinas
dataset False. Default: True.
complex_input (bool) – True if input is complex [real-valued] tensor (complex dim = 2). False if
complex-valued tensor is inputted. Default: True.
Apply centered two-dimensional Inverse Fast Fourier Transform.
Can be performed in half precision when input shapes are powers of two. Version for PyTorch >= 1.7.0.
Parameters:
data (Tensor) – Complex-valued input tensor. Should be of shape (*,2) and dim is in *.
dim (tuple[int, int]) – Dimensions over which to compute. Should be positive. Negative indexing not supported.
Default: (1,2), corresponding to ('height','width').
centered (bool) – Whether to apply a centered ifft (center of kspace is in the center versus in the corners).
For FastMRI dataset this has to be True and for the Calgary-Campinas dataset False.
Default: True.
normalized (bool) – Whether to normalize the ifft. For the FastMRI this has to be True and for the
Calgary-Campinas dataset False. Default: True.
complex_input (bool) – True if input is complex [real-valued] tensor (complex dim = 2). False if
complex-valued tensor is inputted. Default: True.
Performs a matrix multiplication of the 2D complex matrices input_tensor and other_tensor. If input_tensor is a
(n×m) tensor, other_tensor is a (m×p) tensor, out will be a (n×p) tensor.
data (Tensor) – Batched or not input to be padded of shape (batch,*,height,width,*).
padding (Optional[Tensor]) – Binary tensor of shape (batch,1,height,width,1). Entries in padding with non-zero value
point to samples in data that will be zero-padded. If None, data will be returned.
Subsample kspace by setting kspace to zero as given by a binary mask.
Parameters:
kspace (Tensor) – k-space as a complex-valued tensor.
mask_func (Union[Callable, Tensor]) – Masking function, taking a shape and returning a mask with this shape or can be broadcast as such.
Can also be a sampling mask.
seed (Optional[int]) – Seed for the random number generator. Default: None.
return_mask (bool) – If True, mask will be returned. Default: True.
Return type:
Union[tuple[Tensor, Tensor], Tensor]
Returns:
Tuple of masked data and mask if return_mask is True, otherwise just masked data.
Apply a center crop to the input data, or to a list of complex images.
Parameters:
data_list (Union[list[Tensor], Tensor]) – The complex input tensor to be center cropped. It should have at least 3 dimensions and the
cropping is applied along dimensions didx and didx+1 and the last dimensions should have a size
of 2.
crop_shape (Union[list[int], tuple[int, ...]]) – The output shape. The shape should be smaller than the corresponding dimensions of data.
If one value is None, this is filled in by the image shape.
offset (int) – Starting dimension for cropping. Default: 1.
contiguous (bool) – Return as a contiguous array. Useful for fast reshaping or viewing. Default: False.
Apply a random crop to the input data tensor or a list of complex.
Parameters:
data_list (Union[list[Tensor], Tensor]) – The complex input tensor to be center cropped. It should have at least 3 dimensions and the
cropping is applied along dimensions -3 and -2 and the last dimensions should have a size of 2.
crop_shape (Union[list[int], tuple[int, ...]]) – The output shape. The shape should be smaller than the corresponding dimensions of data.
offset (int) – Starting dimension for cropping. Default: 1.
contiguous (bool) – Return as a contiguous array. Useful for fast reshaping or viewing. Default: False.
sampler (str) – Select the random indices from either a "uniform" or "gaussian" distribution (around the
center). Default: "uniform".
sigma (Union[float, list[float], None]) – Standard variance of the gaussian when sampler is "gaussian". If not set will take 1/3th of image
shape. Default: None.