virtualscanner.server.recon.drunck¶
Deep learning Reconstruction of Undersampled Cartesian K-space (DRUNCK) is a convolutional neural network that reconstructs 4x undersampled Cartesian acquisitions. Front end integration coming soon!
nifti2npy.py¶
-
load_dataset_from_nifti
(nifti_path: pathlib.Path, img_size: int = 128) → numpy.ndarray¶ Make dataset by reading NIFTI files from nifti_path and resizing each image to img_size x img_size.
- Parameters
nifti_path (str) – Path to folder containing NIFTI files.
img_size (int, optional) – Desired size of images in dataset. Images read from NIFTI files will be resized. Default value is 128.
- Returns
dataset – ndarray of images converted from NIFTI files.
- Return type
numpy.ndarray
-
main
(nifti_path: pathlib.Path, img_size: int, low_freq_pc: float, save_path: pathlib.Path, reduction_factor: int, plot_flag: bool = True)¶ Load NIFTI data as numpy.ndarray and resize each image to img_size x img_size.
Undersample by skip_factor and add low_freq_pc low-frequency k-space values.
Save files to disk.
- Parameters
nifti_path (str) – Path to folder containing NIFTI files.
img_size (int) – Desired size of images in dataset. Images read from NIFTI files will be resized.
low_freq_pc (float) – Percentage of low-frequency fully-sampled k-space values to add to undersampled k-space.
save_path (str) – Path to save ndarray files.
reduction_factor (int) – Undersampling factor.
plot_flag (bool, optional) – Boolean flag to plot img_ind sample of dataset, undersampled dataset and corresponding k-space. Default value is True.
-
normalise_dataset
(dataset: numpy.ndarray) → numpy.ndarray¶ Normalised dataset to [0, 1].
- Parameters
dataset (numpy.ndarray) – ndarray of dataset samples.
- Returns
normalised_dataset – ndarray of dataset normalised to [0, 1].
- Return type
numpy.ndarray
-
plot
(dataset: numpy.ndarray, ft_dataset: numpy.ndarray, dataset_undersampled: numpy.ndarray, ft_dataset_undersampled: numpy.ndarray, img_ind: int)¶ Plot fully-sampled and under-sampled data sample at img_ind position with corresponding k-space data.
- Parameters
dataset (numpy.ndarray) – ndarray of dataset samples.
ft_dataset (numpy.ndarray) – ndarray of Fourier Transform of dataset.
dataset_undersampled (numpy.ndarray) – ndarray of undersampled dataset.
ft_dataset_undersampled (numpy.ndarray) – Fourier Transform of dataset_undersampled.
img_ind (int) – Index of data sample to plot.
-
save2disk
(filename1: str, file1: numpy.ndarray, filename2: str, file2: numpy.ndarray, save_path: pathlib.Path)¶ Save file1 and file2 to disk as filename1 and filename2 at save_path.
- Parameters
filename1 (str) – Filename of file1.
file1 (numpy.ndarray) – ndarray to be saved to disk.
filename2 (str) – Filename of file2.
file2 (numpy.ndarray) – ndarray to be saved to disk.
save_path (str) – Path to save ndarray files to.
-
undersample
(dataset: numpy.ndarray, low_freq_pc: float, reduction_factor: int) -> (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>, <class 'numpy.ndarray'>)¶ Undersample dataset as follows: 1. Obtain ft_dataset - Fourier Transform of dataset 2. Obtain ft_dataset_undersampled - undersample of ft_dataset 3. Add low_freq_pc low-frequency k-space components from ft_dataset to ft_dataset_undersampled. 4. Obtain dataset_undersampled - Inverse Fourier Transform of ft_dataset_undersampled.
- Parameters
dataset (numpy.ndarray) – ndarray of dataset samples.
low_freq_pc (float) – Percentage of low-frequency fully-sampled k-space values to add to undersampled k-space.
reduction_factor (int) – Undersampling factor.
- Returns
ft_dataset (numpy.ndarray) – ndarray of Fourier Transform of dataset.
dataset_undersampled (numpy.ndarray) – ndarray of undersampled dataset.
ft_dataset_undersampled (numpy.ndarray) – Fourier Transform of dataset_undersampled.
reconstruct.py¶
-
main
(img_path: str, img_type: str) → tuple¶ Perform inference on pre-trained network, compute and display time to perform inference and plot results.
- Parameters
model_path (keras.models.Model) – Path to load pre-trained Keras model.
test_data_path (str) – Path to folder containing input.npy and ground_truth.npy.
reduction_factor (int) – Undersampling factor of the dataset that the model was pre-trained on.
num_pred (int) – Number of test samples to perform inference on.
- Returns
output_image – ndarray containing num_pred number of reconstructed samples.
- Return type
numpy.ndarray