Skip to content

Commit 774d8e0

Browse files
authored
Merge pull request #20 from BrainLesion/19-feature-request-add-open-in-collab-badge
19 feature request add open in collab badge
2 parents eb3974e + 20168e2 commit 774d8e0

8 files changed

Lines changed: 201 additions & 823 deletions

File tree

AURORA/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

AURORA/LICENSE

Lines changed: 0 additions & 661 deletions
This file was deleted.
109 KB
Binary file not shown.

AURORA/tutorial.ipynb

Lines changed: 169 additions & 155 deletions
Large diffs are not rendered by default.

AURORA/utils.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
1+
import os
12
import matplotlib.pyplot as plt
23
import nibabel as nib
34

5+
DATA_FOLDER = "data"
46

5-
def visualize_results(t1_file: str, segmentation_file: str):
6-
t1_np = nib.load(t1_file).get_fdata().transpose(2, 1, 0)
7+
8+
def visualize_data(data_folder: str = DATA_FOLDER, slice_index: int = 75):
9+
"""Visualize the MRI modalities for a given slice index
10+
11+
Args:
12+
data_folder (str, optional): Path to the folder containing the t1, t1c, t2 & flair file. Defaults to DATA_FOLDER.
13+
slice_index (int, optional): Slice to be visualized (first index in data of shape (155, 240, 240)). Defaults to 75.
14+
"""
15+
_, axes = plt.subplots(1, 4, figsize=(12, 10))
16+
17+
modalities = ["t1", "t1c", "t2", "flair"]
18+
for i, mod in enumerate(modalities):
19+
modality_file = os.path.join(data_folder, f"{mod}.nii.gz")
20+
modality_np = nib.load(modality_file).get_fdata().transpose(2, 1, 0)
21+
axes[i].set_title(mod)
22+
axes[i].imshow(modality_np[slice_index, :, :], cmap="gray")
23+
axes[i].axis("off")
24+
25+
26+
def visualize_segmentation(modality_file: str, segmentation_file: str):
27+
"""Visualize the MRI modality and the segmentation
28+
29+
Args:
30+
modality_file (str): Path to the desired modality file
31+
segmentation_file (str): Path to the segmentation file
32+
"""
33+
modality_np = nib.load(modality_file).get_fdata().transpose(2, 1, 0)
734
seg_np = nib.load(segmentation_file).get_fdata().transpose(2, 1, 0)
835
_, ax = plt.subplots(1, 2, figsize=(8, 4))
936

10-
slice_index = t1_np.shape[0] // 2 # You can choose any slice here
11-
ax[0].imshow(t1_np[slice_index, :, :], cmap="gray")
12-
ax[1].imshow(t1_np[slice_index, :, :], cmap="gray")
37+
slice_index = modality_np.shape[0] // 2 # You can choose any slice here
38+
ax[0].imshow(modality_np[slice_index, :, :], cmap="gray")
39+
ax[1].imshow(modality_np[slice_index, :, :], cmap="gray")
1340
ax[1].imshow(seg_np[slice_index, :, :], cmap="plasma", alpha=0.3)
1441
for ax in ax:
1542
ax.axis("off")

0 commit comments

Comments
 (0)