Download and Preprocessing for PET-MR Simulations
This notebook will not re-download/re-process files if they already exist.
~/.brainweb/subject_*.npz
: dtype(shape): float32(127, 344, 344)
~/.brainweb/subject_*.bin.gz
: dtype(shape): uint16(362, 434, 362)
pip install -r requirements.txt
)from __future__ import print_function, division
%matplotlib notebook
import brainweb
from brainweb import volshow
import numpy as np
from os import path
from tqdm.auto import tqdm
import logging
logging.basicConfig(level=logging.INFO)
# download
files = brainweb.get_files()
# read last file
data = brainweb.load_file(files[-1])
# show last subject
print(files[-1])
volshow(data, cmaps=['gist_ncar']);
brainweb.seed(1337)
for f in tqdm(files, desc="mMR ground truths", unit="subject"):
vol = brainweb.get_mmr_fromfile(
f,
petNoise=1, t1Noise=0.75, t2Noise=0.75,
petSigma=1, t1Sigma=1, t2Sigma=1)
# show last subject
print(f)
volshow([vol['PET' ][:, 100:-100, 100:-100],
vol['uMap'][:, 100:-100, 100:-100],
vol['T1' ][:, 100:-100, 100:-100],
vol['T2' ][:, 100:-100, 100:-100]],
cmaps=['hot', 'bone', 'Greys_r', 'Greys_r'],
titles=["PET", "uMap", "T1", "T2"]);
# add some lesions
brainweb.seed(1337)
im3d = brainweb.add_lesions(vol['PET'])
volshow(im3d[:, 100:-100, 100:-100], cmaps=['hot']);