brainweb_phantom#
- mrtwin.brainweb_phantom(ndim, subject, shape=None, model='single-pool', segtype='crisp', output_res=None, B0=1.5, cache=True, cache_dir=None, brainweb_dir=None, force=False, verify=True)[source]#
Get BrainWeb phantom.
- Parameters:
ndim (int) – Number of spatial dimensions. If ndim == 2, use a single slice (central axial slice).
subject (int) – Subject id to download.
shape (int | Sequence[int] | None, optional) – Shape of the output data, the data will be interpolated to the given shape. If int, assume isotropic matrix. The default is
None(original shape).model (str, optional) –
String selecting one of the built-in tissue models. Valid entries are:
"single-pool": Single pool tissue model."mw-model": Myelin Water (MW) + Free Water (Intra-Extracellular, IEW)"mt-model": Macromolecular pool + Free Water (IEW + MW)"mwmt-model": Macromolecular pool + MW + IEW
The default is
"single-pool".segtype (str | bool, optional) – Phantom type. If it is a string (
"fuzzy"or"crisp") select fuzzy and crisp segmentation, respectively. If it isFalse, return a dense numeric phantom. The default iscrisp.output_res (float | Sequence[float] | None, optional) – Resolution of the output data, the data will be rescaled to the given resolution. If scalar, assume isotropic resolution. The default is
None(estimate from shape assuming same fov).B0 (float, optional) – Static field strength in [T]. The default is 1.5.
cache (bool, optional) – If
True, cache the phantom. The default isTrue.cache_dir (CacheDirType, optional) – cache_directory for phantom caching. The default is
None(~/.cache/mrtwin).brainweb_dir (CacheDirType, optional) – Brainweb_directory for brainweb segmentation caching. The default is
None(~/.cache/brainweb).force (bool, optional) – Force download even if the file already exists. The default is
False.verify (bool, optional) – Enable SSL verification. DO NOT DISABLE (i.e.,
verify=False) IN PRODUCTION. The default isTrue.
- Returns:
Brainweb phantom.
- Return type:
PhantomType
Examples
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from mrtwin import brainweb_phantom
We can generate a dense single slice 2D phantom with a matrix size of
(200, 200)at 1.085 mm isotropic resolution for the brainweb subjectn=4as:>>> phantom = brainweb_phantom(ndim=2, subject=4, segtype=False)
Phantom T1 and T2 maps, can be accessed as:
>>> fig, ax = plt.subplots(2, 1)
>>> im1 = ax[0].imshow(phantom.T1, cmap="magma", vmax=1500) >>> ax[0].axis("off"), ax[0].set_title("T1 [ms]") >>> fig.colorbar(im1, ax=ax[0], fraction=0.046, pad=0.04)
>>> im2 = ax[1].imshow(phantom.T2, cmap="viridis", vmax=150) >>> ax[1].axis("off"), ax[1].set_title("T2 [ms]") >>> fig.colorbar(im, ax=ax[1], fraction=0.046, pad=0.04)