Created
May 11, 2020 05:00
-
-
Save Mistobaan/d8c8b97f790a0bb6b4c10b5ed22aa27b to your computer and use it in GitHub Desktop.
Interactive Plot example
This file contains 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
# Create layer slider | |
# Import all the necessary packages | |
import numpy as np | |
import nibabel as nib | |
from ipywidgets import interact, interactive, IntSlider, ToggleButtons | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
import seaborn as sns | |
sns.set_style('darkgrid') | |
# Create button values | |
select_class = ToggleButtons( | |
options=['Normal','Edema', 'Non-enhancing tumor', 'Enhancing tumor'], | |
description='Select Class:', | |
disabled=False, | |
button_style='info', | |
) | |
select_layer = IntSlider(min=0, max=154, description='Select Layer', continuous_update=False) | |
# Define a function for plotting images | |
def plot_image(seg_class, layer): | |
print(f"Plotting {layer} Layer Label: {seg_class}") | |
img_label = classes_dict[seg_class] | |
mask = np.where(label_array[:,:,layer] == img_label, 255, 0) | |
plt.figure(figsize=(10,5)) | |
plt.imshow(mask, cmap='gray') | |
plt.axis('off'); | |
# Use the interactive() tool to create the visualization | |
interactive(plot_image, seg_class=select_class, layer=select_layer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment