Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions preprocessing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output
outputs
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
573 changes: 319 additions & 254 deletions preprocessing/preprocessing_tutorial.ipynb

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions preprocessing/temporary_directory/.gitignore

This file was deleted.

36 changes: 36 additions & 0 deletions preprocessing/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pathlib import Path
from typing import List, Optional
import matplotlib.pyplot as plt
import nibabel as nib


def visualize_data(files: List[Path], label: str, titles: Optional[List[str]] = None):
"""Visualize the MRI modalities

Args:
files (List[Path]): List of paths to the MRI modalities
label (str): Label for the y-axis on the far left left, i.e. category of the passed images (e.g. input, output)
titles (Optional[List[str]], optional): Title of images. Defaults to None.
"""
_, axes = plt.subplots(1, len(files), figsize=(len(files) * 4, 10))

for i, file in enumerate(files):
modality_np = nib.load(file).get_fdata().transpose(2, 1, 0)
axes[i].set_title(titles[i] if titles else file.name)
axes[i].imshow(modality_np[modality_np.shape[0] // 2, :, :], cmap="gray")
axes[0].set_ylabel(label)


def visualize_defacing(
file: Path,
):
"""Visualize the defacing of the MRI modality

Args:
file (Path): Path to the MRI modality
"""

modality_np = nib.load(file).get_fdata().transpose(2, 1, 0)
plt.figure(figsize=(4, 5))
plt.title(file.name)
plt.imshow(modality_np[:, ::-1, 75], cmap="gray", origin="lower")