= 8 # acceleration A
Prepare masks
Simulate 2D+t Gaussian Cartesian random subsampling masks at varying accelerations using the deepinv
library.
%cd ..
import os, pickle
from pathlib import Path
from tqdm import tqdm
import numpy as np
from scipy.io import savemat
import torch
from deepinv.physics.generator import GaussianMaskGenerator
from utils.utils import set_posix_windows
= Path("M:/data/CMRxRecon")
root = "TrainingSet"
set_name = root / "SingleCoil/Cine" / set_name
root = "FullSample"
acc_folder = "TimeVaryingGaussianMask" + str(A).zfill(2) new_mask_folder
= 0
seed = np.random.default_rng(seed)
rng
torch.manual_seed(seed) np.random.seed(seed)
# Open existing dataset cache
with open("dataset_cache_windows.pkl", "rb") as f:
with set_posix_windows():
= pickle.load(f) dataset_cache
# Iterate through existing dataset cache
= []
done_fnames for sample in tqdm(dataset_cache[root]):
if sample.fname in done_fnames: continue
done_fnames.append(sample.fname)
= sample.fname.replace(acc_folder, new_mask_folder)[:-4] + "_mask.mat"
mask_fname =True)
os.makedirs(os.path.dirname(mask_fname), exist_ok
= GaussianMaskGenerator(
generator 2, sample.metadata["timeframes"], sample.metadata["width"], sample.metadata["height"]),
(=A,
acceleration=rng,
rng
)
= generator.step()["mask"].detach().numpy().astype("uint8")
mask = mask[0, 0, :, :, :] #only save T,H,W
mask = np.moveaxis(mask, 0, -1) #H, W, T
mask
"mask": mask}, do_compression=True) savemat(mask_fname, {
0%| | 0/1492 [00:00<?, ?it/s]100%|██████████| 1492/1492 [00:48<00:00, 31.03it/s]