-
Notifications
You must be signed in to change notification settings - Fork 4
72 feature update brats tutorial #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,22 @@ | ||
| from pathlib import Path | ||
| from typing import Union | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import nibabel as nib | ||
| import numpy as np | ||
|
|
||
| DATA_FOLDER = "data" | ||
| DATA_FOLDER = Path("data") | ||
|
|
||
|
|
||
| def visualize_segmentation_data( | ||
| data_folder: str = DATA_FOLDER, | ||
| data_folder: Union[str, Path] = DATA_FOLDER, | ||
| subject_id: str = "BraTS-GLI-00001-000", | ||
| slice_index: int = 75, | ||
| ): | ||
| """Visualize the MRI modalities for a given slice index | ||
|
|
||
| Args: | ||
| data_folder (str, optional): Path to the folder containing the t1, t1c, t2 & flair file. Defaults to DATA_FOLDER. | ||
| data_folder (Union[str, Path]): Path to the folder containing the t1, t1c, t2 & flair file. Defaults to DATA_FOLDER. | ||
| slice_index (int, optional): Slice to be visualized (first index in data of shape (155, 240, 240)). Defaults to 75. | ||
| """ | ||
| _, axes = plt.subplots(1, 4, figsize=(12, 10)) | ||
|
|
@@ -29,14 +32,14 @@ def visualize_segmentation_data( | |
|
|
||
|
|
||
| def visualize_inpainting_data( | ||
| data_folder: str = DATA_FOLDER, | ||
| data_folder: Union[str, Path] = DATA_FOLDER, | ||
| subject_id: str = "BraTS-GLI-00001-000", | ||
| slice_index: int = 75, | ||
| ): | ||
| """Visualize the MRI modalities for a given slice index | ||
|
|
||
| Args: | ||
| data_folder (str, optional): Path to the folder containing the t1n and mask files. Defaults to DATA_FOLDER. | ||
| data_folder (Union[str, Path]): Path to the folder containing the t1n and mask files. Defaults to DATA_FOLDER. | ||
|
neuronflow marked this conversation as resolved.
Outdated
|
||
| slice_index (int, optional): Slice to be visualized (first index in data of shape (155, 240, 240)). Defaults to 75. | ||
| """ | ||
| _, axes = plt.subplots(1, 2, figsize=(6, 10)) | ||
|
|
@@ -51,32 +54,39 @@ def visualize_inpainting_data( | |
| axes[i].axis("off") | ||
|
|
||
|
|
||
| def visualize_segmentation(modality_file: str, segmentation_file: str): | ||
| def visualize_segmentation( | ||
| modality_file: Union[str, Path], segmentation_file: Union[str, Path] | ||
| ): | ||
| """Visualize the MRI modality and the segmentation | ||
|
|
||
| Args: | ||
| modality_file (str): Path to the desired modality file | ||
| segmentation_file (str): Path to the segmentation file | ||
| modality_file (Union[str, Path]): Path to the desired modality file | ||
| segmentation_file (Union[str, Path]): Path to the segmentation file | ||
| """ | ||
| modality_np = nib.load(modality_file).get_fdata().transpose(2, 1, 0) | ||
| seg_np = nib.load(segmentation_file).get_fdata().transpose(2, 1, 0) | ||
|
|
||
| _, ax = plt.subplots(1, 2, figsize=(8, 4)) | ||
|
|
||
| slice_index = modality_np.shape[0] // 2 # You can choose any slice here | ||
|
|
||
| # Mask out background (0) in the segmentation | ||
| seg_slice = seg_np[slice_index, :, :] | ||
| ax[0].imshow(modality_np[slice_index, :, :], cmap="gray") | ||
| ax[1].imshow(modality_np[slice_index, :, :], cmap="gray") | ||
| ax[1].imshow(seg_np[slice_index, :, :], cmap="plasma", alpha=0.3) | ||
| ax[1].imshow(seg_slice, cmap="plasma", alpha=np.where(seg_slice > 0, 0.3, 0)) | ||
|
|
||
|
Comment on lines
75
to
+78
|
||
| for ax in ax: | ||
| ax.axis("off") | ||
| plt.tight_layout() | ||
|
|
||
|
|
||
| def visualize_inpainting(t1n_voided: str, prediction: str): | ||
| def visualize_inpainting(t1n_voided: Union[str, Path], prediction: Union[str, Path]): | ||
| """Visualize the inpainting results | ||
|
|
||
| Args: | ||
| t1n_voided (str): Voided T1 modality file | ||
| prediction (str): Inpainting prediction file | ||
| t1n_voided (Union[str, Path]): Voided T1 modality file | ||
| prediction (Union[str, Path]): Inpainting prediction file | ||
| """ | ||
| voided_np = nib.load(t1n_voided).get_fdata().transpose(2, 1, 0) | ||
| inpainting_np = nib.load(prediction).get_fdata().transpose(2, 1, 0) | ||
|
|
@@ -91,15 +101,17 @@ def visualize_inpainting(t1n_voided: str, prediction: str): | |
|
|
||
|
|
||
| def visualize_missing_mri_t2w( | ||
| synthesized_t2w: str, | ||
| data_folder: str = DATA_FOLDER, | ||
| synthesized_t2w: Union[str, Path], | ||
| data_folder: Union[str, Path] = DATA_FOLDER, | ||
| subject_id: str = "BraTS-GLI-00001-000", | ||
| slice_index: int = 75, | ||
| ): | ||
| """Visualize the MRI modalities for a given slice index | ||
|
|
||
| Args: | ||
| data_folder (str, optional): Path to the folder containing the t1, t1c, t2 & flair file. Defaults to DATA_FOLDER. | ||
| synthesized_t2w (Union[str, Path]): Path to the synthesized T2w file | ||
| data_folder (Union[str, Path], optional): Path to the folder containing the t1, t1c, t2 & flair file. Defaults to DATA_FOLDER. | ||
| subject_id (str, optional): Subject ID to visualize. Defaults to "BraTS-GLI-00001-000". | ||
| slice_index (int, optional): Slice to be visualized (first index in data of shape (155, 240, 240)). Defaults to 75. | ||
| """ | ||
| _, axes = plt.subplots(1, 5, figsize=(12, 10)) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.