|
| 1 | +from pathlib import Path |
| 2 | +from typing import List, Optional |
| 3 | +import matplotlib.pyplot as plt |
| 4 | +import nibabel as nib |
| 5 | + |
| 6 | + |
| 7 | +def visualize_data(files: List[Path], label: str, titles: Optional[List[str]] = None): |
| 8 | + """Visualize the MRI modalities |
| 9 | +
|
| 10 | + Args: |
| 11 | + files (List[Path]): List of paths to the MRI modalities |
| 12 | + label (str): Label for the y-axis on the far left left, i.e. category of the passed images (e.g. input, output) |
| 13 | + titles (Optional[List[str]], optional): Title of images. Defaults to None. |
| 14 | + """ |
| 15 | + _, axes = plt.subplots(1, len(files), figsize=(len(files) * 4, 10)) |
| 16 | + |
| 17 | + for i, file in enumerate(files): |
| 18 | + modality_np = nib.load(file).get_fdata().transpose(2, 1, 0) |
| 19 | + axes[i].set_title(titles[i] if titles else file.name) |
| 20 | + axes[i].imshow(modality_np[modality_np.shape[0] // 2, :, :], cmap="gray") |
| 21 | + axes[0].set_ylabel(label) |
| 22 | + |
| 23 | + |
| 24 | +def visualize_defacing( |
| 25 | + file: Path, |
| 26 | +): |
| 27 | + """Visualize the defacing of the MRI modality |
| 28 | +
|
| 29 | + Args: |
| 30 | + file (Path): Path to the MRI modality |
| 31 | + """ |
| 32 | + |
| 33 | + modality_np = nib.load(file).get_fdata().transpose(2, 1, 0) |
| 34 | + plt.figure(figsize=(6, 6)) |
| 35 | + plt.title(file.name) |
| 36 | + plt.imshow(modality_np[:, ::-1, 75], cmap="gray", origin="lower") |
0 commit comments