The example may be launched interactively via any of the following:
BrainWeb-based multimodal models of 20 normal brains
This project was initially inspired by "BrainWeb: 20 Anatomical Models of 20 Normal Brains"
However there are a number of generally useful tools, image processing &
display functions included in this project. For example, this includes
volshow() for interactive comparison of multiple 3D volumes,
get_file() for caching data URLs, and register() for image
coregistration.
Download and Preprocessing for PET-MR Simulations
This notebook will not re-download/re-process files if they already exist.
- Output data
~/.brainweb/subject_*.npz: dtype(shape):float32(127, 344, 344)
- Raw data source
~/.brainweb/subject_*.bin.gz: dtype(shape):uint16(362, 434, 362)
- Install
pip install brainweb
%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)
Raw Data
# 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/subject_54.bin.gz
Transform
Convert raw image data:
- Siemens Biograph mMR resolution (~2mm) & dimensions (127, 344, 344)
- PET/T1/T2/uMap intensities
- PET defaults to FDG intensity ratios; could use e.g. Amyloid instead
- randomised structure for PET/T1/T2
- $t (1 + g [2 G_sigma(r) - 1])$, where
- r =
rand(127, 344, 344)$\in [0, 1)$, - Gaussian smoothing sigma = 1,
- g = 1 for PET; 0.75 for MR, and
- t = the PET or MR piecewise constant phantom
- r =
- $t (1 + g [2 G_sigma(r) - 1])$, where
# show region probability masks
PetClass = brainweb.FDG
label_probs = brainweb.get_label_probabilities(files[-1], labels=PetClass.all_labels)
volshow(label_probs[brainweb.trim_zeros_ROI(label_probs)], titles=PetClass.all_labels, frameon=False);
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,
PetClass=PetClass)
# 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"],
frameon=False);
~/.brainweb/subject_54.bin.gz
# add some lesions
brainweb.seed(1337)
im3d = brainweb.add_lesions(vol['PET'])
volshow(im3d[:, 100:-100, 100:-100], cmaps=['hot']);
# bonus: use brute-force registration to transform
#!pip install -U 'brainweb[register]'
reg = brainweb.register(
data[:, ::-1], target=vol['PET'],
src_resolution=brainweb.Res.brainweb,
target_resolution=brainweb.Res.mMR)
volshow({
"PET": vol['PET'][:, 100:-100, 100:-100],
"RawReg": reg[ :, 100:-100, 100:-100],
"T1": vol['T1' ][:, 100:-100, 100:-100],
}, cmaps=['hot', 'gist_ncar', 'Greys_r'], ncols=3, tight_layout=5, figsize=(9.5, 3.5), frameon=False);
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file brainweb-1.7.0.tar.gz.
File metadata
- Download URL: brainweb-1.7.0.tar.gz
- Upload date:
- Size: 287.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8d7dde584a01a269c2a66cd1684af5658343b986ba961ba0599e80e86ab7c1d
|
|
| MD5 |
66f1c1d8b5129a2fbc85fff3b1ba84e2
|
|
| BLAKE2b-256 |
13a400a5f042e511ca51858dc9059b234c4e372ce41bc7b113d2a436a8720818
|
Provenance
The following attestation bundles were made for brainweb-1.7.0.tar.gz:
Publisher:
test.yml on casperdcl/brainweb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brainweb-1.7.0.tar.gz -
Subject digest:
b8d7dde584a01a269c2a66cd1684af5658343b986ba961ba0599e80e86ab7c1d - Sigstore transparency entry: 2289920738
- Sigstore integration time:
-
Permalink:
casperdcl/brainweb@5c58afa8171044e6eb56c1312c5552e852541c63 -
Branch / Tag:
refs/tags/v1.7.0 - Owner: https://github.com/casperdcl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@5c58afa8171044e6eb56c1312c5552e852541c63 -
Trigger Event:
push
-
Statement type:
File details
Details for the file brainweb-1.7.0-py3-none-any.whl.
File metadata
- Download URL: brainweb-1.7.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fad653624ba332ea772b4e4fefd8d830614097322f305c313da3c0906b6f2895
|
|
| MD5 |
75033925ac916b78800f044f6e83f091
|
|
| BLAKE2b-256 |
c6c58307be4d26ddd65bb4532ef521cae3a3af093b5e02f9b267455f8e72a302
|
Provenance
The following attestation bundles were made for brainweb-1.7.0-py3-none-any.whl:
Publisher:
test.yml on casperdcl/brainweb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
brainweb-1.7.0-py3-none-any.whl -
Subject digest:
fad653624ba332ea772b4e4fefd8d830614097322f305c313da3c0906b6f2895 - Sigstore transparency entry: 2289920725
- Sigstore integration time:
-
Permalink:
casperdcl/brainweb@5c58afa8171044e6eb56c1312c5552e852541c63 -
Branch / Tag:
refs/tags/v1.7.0 - Owner: https://github.com/casperdcl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test.yml@5c58afa8171044e6eb56c1312c5552e852541c63 -
Trigger Event:
push
-
Statement type: