Skip to content

Commit 7e87ded

Browse files
authored
Merge pull request #54 from BrainLesion/53-tutorials-for-brats
53 tutorials for brats
2 parents f063392 + c9e9036 commit 7e87ded

10 files changed

Lines changed: 508 additions & 0 deletions
2.77 MB
Binary file not shown.
2.49 MB
Binary file not shown.
2.67 MB
Binary file not shown.
2.59 MB
Binary file not shown.
4.74 MB
Binary file not shown.
4.82 MB
Binary file not shown.
4.76 MB
Binary file not shown.
4.89 MB
Binary file not shown.

BraTS/tutorial.ipynb

Lines changed: 460 additions & 0 deletions
Large diffs are not rendered by default.

BraTS/utils.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from pathlib import Path
2+
import matplotlib.pyplot as plt
3+
import nibabel as nib
4+
5+
DATA_FOLDER = "data"
6+
7+
8+
def visualize_data(
9+
data_folder: str = DATA_FOLDER,
10+
subject_id: str = "BraTS-GLI-00001-000",
11+
slice_index: int = 75,
12+
):
13+
"""Visualize the MRI modalities for a given slice index
14+
15+
Args:
16+
data_folder (str, optional): Path to the folder containing the t1, t1c, t2 & flair file. Defaults to DATA_FOLDER.
17+
slice_index (int, optional): Slice to be visualized (first index in data of shape (155, 240, 240)). Defaults to 75.
18+
"""
19+
_, axes = plt.subplots(1, 4, figsize=(12, 10))
20+
21+
subject_path = Path(data_folder) / subject_id
22+
modalities = ["t1n", "t1c", "t2f", "t2w"]
23+
for i, mod in enumerate(modalities):
24+
modality_file = subject_path / f"{subject_id}-{mod}.nii.gz"
25+
modality_np = nib.load(modality_file).get_fdata().transpose(2, 1, 0)
26+
axes[i].set_title(mod)
27+
axes[i].imshow(modality_np[slice_index, :, :], cmap="gray")
28+
axes[i].axis("off")
29+
30+
31+
def visualize_segmentation(modality_file: str, segmentation_file: str):
32+
"""Visualize the MRI modality and the segmentation
33+
34+
Args:
35+
modality_file (str): Path to the desired modality file
36+
segmentation_file (str): Path to the segmentation file
37+
"""
38+
modality_np = nib.load(modality_file).get_fdata().transpose(2, 1, 0)
39+
seg_np = nib.load(segmentation_file).get_fdata().transpose(2, 1, 0)
40+
_, ax = plt.subplots(1, 2, figsize=(8, 4))
41+
42+
slice_index = modality_np.shape[0] // 2 # You can choose any slice here
43+
ax[0].imshow(modality_np[slice_index, :, :], cmap="gray")
44+
ax[1].imshow(modality_np[slice_index, :, :], cmap="gray")
45+
ax[1].imshow(seg_np[slice_index, :, :], cmap="plasma", alpha=0.3)
46+
for ax in ax:
47+
ax.axis("off")
48+
plt.tight_layout()

0 commit comments

Comments
 (0)