Skip to content

Commit

Permalink
new - addded slice_explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
bmandracchia committed Aug 28, 2024
1 parent 817b314 commit 192e3b1
Show file tree
Hide file tree
Showing 3 changed files with 3,150 additions and 21 deletions.
1 change: 1 addition & 0 deletions bioMONAI/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@
'bioMONAI.visualize.mosaic_image_3d': ('visualize.html#mosaic_image_3d', 'bioMONAI/visualize.py'),
'bioMONAI.visualize.show_images_grid': ('visualize.html#show_images_grid', 'bioMONAI/visualize.py'),
'bioMONAI.visualize.show_plane': ('visualize.html#show_plane', 'bioMONAI/visualize.py'),
'bioMONAI.visualize.slice_explorer': ('visualize.html#slice_explorer', 'bioMONAI/visualize.py'),
'bioMONAI.visualize.visualize_slices': ('visualize.html#visualize_slices', 'bioMONAI/visualize.py')}}}
38 changes: 33 additions & 5 deletions bioMONAI/visualize.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/09_visualize.ipynb.

# %% auto 0
__all__ = ['mosaic_image_3d', 'show_images_grid', 'show_plane', 'visualize_slices']
__all__ = ['mosaic_image_3d', 'show_images_grid', 'show_plane', 'visualize_slices', 'slice_explorer']

# %% ../nbs/09_visualize.ipynb 3
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import plotly
import plotly.io as pio
import plotly.express as px
from skimage import exposure, util
from skimage import util
from skimage.data import cells3d
import torchvision

Expand Down Expand Up @@ -151,7 +151,7 @@ def show_images_grid(images, ax=None, ncols=10, figsize=None, title=None, spacin

return ax

# %% ../nbs/09_visualize.ipynb 11
# %% ../nbs/09_visualize.ipynb 12
def show_plane(ax, plane, cmap="gray", title=None, lines=None, linestyle='--', linecolor='white'):
"""
Display a slice of the image tensor on a given axis with optional dashed lines.
Expand All @@ -175,7 +175,7 @@ def show_plane(ax, plane, cmap="gray", title=None, lines=None, linestyle='--', l
ax.axvline(lines[1], color=linecolor, linestyle=linestyle)


# %% ../nbs/09_visualize.ipynb 12
# %% ../nbs/09_visualize.ipynb 13
def visualize_slices(data, planes=None, showlines=True, **kwargs):
"""
Visualize slices of a 3D image tensor along its planes, rows, and columns.
Expand Down Expand Up @@ -209,3 +209,31 @@ def visualize_slices(data, planes=None, showlines=True, **kwargs):
# Show the plot
plt.show()


# %% ../nbs/09_visualize.ipynb 16
def slice_explorer(data, width=500, height=500, **kwargs):
"""
Visualizes the provided data using Plotly's interactive imshow function with animation support.
Args:
data (np.array or pd.DataFrame): The data to be visualized, typically a 2D array representing an image sequence.
Returns:
None: Displays the plot directly.
"""
fig = px.imshow(data, animation_frame=0, binary_string=True)

# Remove tick labels from axes
fig.update_xaxes(showticklabels=False)
fig.update_yaxes(showticklabels=False)

# Set custom size for the plot
fig.update_layout(autosize=False, width=width, height=height, **kwargs)

# Drop animation buttons as they are not supported in this specific configuration
fig['layout'].pop('updatemenus')

# Display the plot using Plotly's show function
pio.show(fig)


3,132 changes: 3,116 additions & 16 deletions nbs/09_visualize.ipynb

Large diffs are not rendered by default.

0 comments on commit 192e3b1

Please sign in to comment.