Skip to content

Commit 00cb711

Browse files
authored
Merge branch 'main' into AURORA-only
2 parents c8e941e + e4a3d09 commit 00cb711

8 files changed

Lines changed: 1017 additions & 1295 deletions

AURORA/tutorial.ipynb

Lines changed: 5 additions & 4 deletions
Large diffs are not rendered by default.
187 KB
Loading

BraTS-Toolkit/glioma_segmentation_with_BraTS_Toolkit.ipynb

Lines changed: 594 additions & 879 deletions
Large diffs are not rendered by default.

BraTS-Toolkit/utils.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
import os
22
import matplotlib.pyplot as plt
33
import nibabel as nib
4+
from pathlib import Path
5+
6+
7+
def visualize_data2(t1c, t1, t2, flair, height_p=0.5): #
8+
"""Visualize the MRI modalities. This function is different from "visualize_data" in the following ways:
9+
a) it expects the four file paths directly (no naming convention required)
10+
b) it does not take a slice index but a percentage height (e.g. 0.5 = 50% = middle slice) as imputs may have different dimensions
11+
12+
Args:
13+
height_p (float, optional): the percentage of slicing height. 0.5 means 50% means exactly in the middle of the cuboid
14+
slice_index (int, optional): Slice to be visualized (first index in data of shape (155, 240, 240)). Defaults to 75.
15+
"""
16+
_, axes = plt.subplots(1, 4, figsize=(12, 10))
17+
18+
for i, (mod, modality_file) in enumerate(
19+
[("t1", t1), ("t1c", t1c), ("t2", t2), ("flair", flair)]
20+
):
21+
22+
data = nib.load(modality_file).get_fdata()
23+
# Get the middle slice along the specified axis
24+
slice_index = int(
25+
data.shape[2] * height_p
26+
) # show slice that is exactly in the middle
27+
slice_data = data[:, ::-1, slice_index].T
28+
29+
axes[i].set_title(mod)
30+
axes[i].imshow(slice_data, cmap="gray")
31+
axes[i].axis("off")
32+
433

534
DATA_FOLDER = "data"
635

@@ -23,7 +52,7 @@ def visualize_data(data_folder: str = DATA_FOLDER, slice_index: int = 75):
2352
axes[i].axis("off")
2453

2554

26-
def visualize_segmentation(modality_file: str, segmentation_file: str):
55+
def visualize_segmentation(modality_file: str, segmentation_file: str, slice_p=0.5):
2756
"""Visualize the MRI modality and the segmentation
2857
2958
Args:
@@ -34,10 +63,10 @@ def visualize_segmentation(modality_file: str, segmentation_file: str):
3463
seg_np = nib.load(segmentation_file).get_fdata().transpose(2, 1, 0)
3564
_, ax = plt.subplots(1, 2, figsize=(8, 4))
3665

37-
slice_index = modality_np.shape[0] // 2 # You can choose any slice here
66+
slice_index = int(modality_np.shape[0] * slice_p) # You can choose any slice here
3867
ax[0].imshow(modality_np[slice_index, :, :], cmap="gray")
3968
ax[1].imshow(modality_np[slice_index, :, :], cmap="gray")
40-
ax[1].imshow(seg_np[slice_index, :, :], cmap="plasma", alpha=0.3)
69+
ax[1].imshow(seg_np[slice_index, :, :], cmap="plasma", alpha=0.5)
4170
for ax in ax:
4271
ax.axis("off")
4372
plt.tight_layout()

panoptica/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
This folder contains several Jupyter notebooks to showcase different possible use cases of the [panoptica package](https://github.com/BrainLesion/panoptica).
44
The package allows to compute instance-wise segmentation quality metrics for 2D and 3D semantic- and instance segmentation maps by providing 3 core modules:
55

6-
1. Instance Approximator: instance approximation algorithms in panoptic segmentation evaluation. Available now: connected components algorithm.
7-
1. Instance Matcher: instance matching algorithm in panoptic segmentation evaluation, to align and compare predicted instances with reference instances.
8-
1. Instance Evaluator: Evaluation of panoptic segmentation performance by evaluating matched instance pairs and calculating various metrics like true positives, Dice score, IoU, and ASSD for each instance.
6+
**1. Instance Approximator:** instance approximation algorithms in panoptic segmentation evaluation. Available now: connected components algorithm.
7+
8+
**2. Instance Matcher:** instance matching algorithm in panoptic segmentation evaluation, to align and compare predicted instances with reference instances.
9+
10+
**3. Instance Evaluator:** Evaluation of panoptic segmentation performance by evaluating matched instance pairs and calculating various metrics like true positives, Dice score, IoU, and ASSD for each instance.
911

1012
![workflow_figure](https://github.com/BrainLesion/panoptica/blob/main/examples/figures/workflow.png)
1113

@@ -17,7 +19,7 @@ The package allows to compute instance-wise segmentation quality metrics for 2D
1719

1820
Although for many biomedical segmentation problems, an instance-wise evaluation is highly relevant and desirable, they are still addressed as semantic segmentation problems due to lack of appropriate instance labels.
1921

20-
Modules [1-3] can be used to obtain panoptic metrics of matched instances based on a semantic segmentation input.
22+
**Modules [1-3]** can be used to obtain panoptic metrics of matched instances based on a semantic segmentation input.
2123

2224
[Jupyter Notebook Example](https://github.com/BrainLesion/tutorials/tree/main/panoptica/example_spine_semantic.ipynb)
2325

@@ -27,7 +29,7 @@ Modules [1-3] can be used to obtain panoptic metrics of matched instances based
2729

2830
It is a common issue that instance segementation outputs have good segmentations with mismatched labels.
2931

30-
For this case modules [2-3] can be utilized to match the instances and report panoptic metrics.
32+
For this case **modules [2-3]** can be utilized to match the instances and report panoptic metrics.
3133

3234
[Jupyter Notebook Example](https://github.com/BrainLesion/tutorials/tree/main/panoptica/example_spine_unmatched_instance.ipynb)
3335

@@ -37,7 +39,7 @@ For this case modules [2-3] can be utilized to match the instances and report pa
3739

3840
Ideally the input data already provides matched instances.
3941

40-
In this case module 3 can be used to directly report panoptic metrics without requiring any internal preprocessing.
42+
In this case **module 3** can be used to directly report panoptic metrics without requiring any internal preprocessing.
4143

4244
[Jupyter Notebook Example](https://github.com/BrainLesion/tutorials/tree/main/panoptica/example_spine_matched_instance.ipynb)
4345

0 commit comments

Comments
 (0)