Skip to content
Snippets Groups Projects

Implementation of slice_viz

Merged ofhkr requested to merge slice_viz into main
1 file
+ 8
8
Compare changes
  • Side-by-side
  • Inline
+ 8
8
@@ -192,13 +192,13 @@ def grid_pred(in_targ_preds, num_images=7, cmap_im="gray", cmap_segm="viridis",
@@ -192,13 +192,13 @@ def grid_pred(in_targ_preds, num_images=7, cmap_im="gray", cmap_segm="viridis",
fig.show()
fig.show()
def slice_viz(input, position = 'mid', cmap_im="viridis",axis = False):
def slice_viz(input, position = 'mid', cmap="viridis", axis=False, img_height=2, img_width=2):
""" Displays one or several slices from a 3d array.
""" Displays one or several slices from a 3d array.
Args:
Args:
input (str, numpy.ndarray): Path to the file or 3-dimensional array.
input (str, numpy.ndarray): Path to the file or 3-dimensional array.
position (str, int, list, array, optional): One or several slicing levels.
position (str, int, list, array, optional): One or several slicing levels.
cmap_im (str, optional): Specifies the color map for the image.
cmap (str, optional): Specifies the color map for the image.
axis (bool, optional): Specifies whether the axes should be included.
axis (bool, optional): Specifies whether the axes should be included.
Raises:
Raises:
@@ -233,12 +233,12 @@ def slice_viz(input, position = 'mid', cmap_im="viridis",axis = False):
@@ -233,12 +233,12 @@ def slice_viz(input, position = 'mid', cmap_im="viridis",axis = False):
if isinstance(position,str):
if isinstance(position,str):
if position.lower() in ['mid','middle']:
if position.lower() in ['mid','middle']:
height = [int(vol.shape[-1]/2)]
height = [int(vol.shape[-1]/2)]
elif position.lower() in ['top','upper']:
elif position.lower() in ['top','upper', 'start']:
height = [0]
height = [0]
elif position.lower() in ['bot','bottom']:
elif position.lower() in ['bot','bottom', 'end']:
height = [vol.shape[-1]-1]
height = [vol.shape[-1]-1]
else:
else:
raise ValueError('Position not recognized. Choose an integer, list, array or "top","mid","bot".')
raise ValueError('Position not recognized. Choose an integer, list, array or "start","mid","end".')
# Position is an integer
# Position is an integer
elif isinstance(position,int):
elif isinstance(position,int):
@@ -250,12 +250,12 @@ def slice_viz(input, position = 'mid', cmap_im="viridis",axis = False):
@@ -250,12 +250,12 @@ def slice_viz(input, position = 'mid', cmap_im="viridis",axis = False):
num_images = len(height)
num_images = len(height)
fig = plt.figure(figsize=(2 * num_images, 5), constrained_layout = True)
fig = plt.figure(figsize=(img_width * num_images, img_height), constrained_layout = True)
axs = fig.subplots(nrows = 1, ncols = num_images)
axs = fig.subplots(nrows = 1, ncols = num_images)
for col, ax in enumerate(np.atleast_1d(axs)):
for col, ax in enumerate(np.atleast_1d(axs)):
ax.imshow(vol[:,:,height[col]],cmap = cmap_im)
ax.imshow(vol[:,:,height[col]],cmap = cmap)
ax.title.set_text(f'Slice {height[col]}')
ax.set_title(f'Slice {height[col]}', fontsize=8)
if not axis:
if not axis:
ax.axis('off')
ax.axis('off')
Loading