Plotting utilities#

MBIRJAX includes some utilities to view 3D data slice-by-slice and to plot the relationship between granularity and loss function.

Here is an example showing views of a modified Shepp-Logan phantom, with changing intensity window and displayed slice.

An animated image of the slice viewer.

Functions:

mbirjax.plot_utils.slice_viewer(data, data2=None, title='', vmin=None, vmax=None, slice_label='Slice', slice_label2=None, slice_axis=2, slice_axis2=None, cmap='gray', show_instructions=True)[source]#

Display slices of one or two 3D image volumes with a consistent grayscale across slices. Allows interactive selection of slices and intensity window. If two images are provided, they are displayed side by side for comparative purposes. If the two images have the same shape, then zoom and pan will be applied to each image simultaneously. If not, pan and zoom are applied to one image at a time. Also allows the user to click and drag to select a circle to compute the mean and standard deviation of the values of the pixels whose centers lie inside the circle.

Parameters:
  • data (ndarray or jax array) – 3D image volume with shape (height, width, depth) or 2D (height, width).

  • data2 (numpy array or jax array, optional) – Second 2D or 3D image volume with the same constraints.

  • title (string, optional, default=’’) – Figure super title

  • vmin (float, optional) – minimum for displayed intensity

  • vmax (float, optional) – maximum for displayed intensity

  • slice_label (str, optional) – Text label to be used for a given slice. Defaults to ‘Slice’

  • slice_label2 (str, optional) – Text label to be used for a given slice for data2. Defaults to slice_label.

  • slice_axis (int, optional) – The dimension of data to use for the slice index. That is, if slice_axis=1, then the displayed images will be data[:, cur_slice, :]

  • slice_axis2 (int, optional) – The dimension of data to use for the slice index for data2.

  • show_instructions (bool, optional) – If True, then display basic instructions on the plot.

Example

data1 = np.random.rand(100, 100, 50)  # Random 3D volume
data2 = np.random.rand(100, 100, 50)  # Another random 3D volume
slice_viewer(data1, data2, slice_axis=2, title='Slice Demo', slice_label='Current slice')  # View slices of both volumes side by side
mbirjax.plot_utils.debug_plot_partitions(partitions, recon_shape)[source]#

Visualizes a set of partitions as color images in a single row, where each partition is represented by a different color.

Parameters:
  • partitions (tuple of arrays) – A tuple where each element is a 2D numpy array representing a partition.

  • recon_shape (tuple) – Shape of phantom in (rows, columns, slices).

mbirjax.plot_utils.debug_plot_indices(num_recon_rows, num_recon_cols, indices, recon_at_indices=None, num_recon_slices=1, title='Debug Plot')[source]#

Visualizes indices on a reconstruction grid and optionally displays reconstruction data at these indices.

Parameters:
  • num_recon_rows (int) – Number of rows in the reconstruction grid.

  • num_recon_cols (int) – Number of columns in the reconstruction grid.

  • indices (array) – Flat indices in the reconstruction grid to be highlighted or modified.

  • recon_at_indices (array, optional) – Values to set at specified indices in the reconstruction grid. If provided, displays the reconstruction at these indices across slices.

  • num_recon_slices (int) – Number of slices in the reconstruction grid, default is 1.

  • title (str) – Title for the plot.

Usage:

When recon_at_indices is not provided, the function visualizes the indices on a 2D grid. When recon_at_indices is provided, it also shows the reconstructed values at these indices in 3D.

Example

debug_plot_indices_or_reconstruction(100, 100, [5050, 10001], recon_at_indices=[1, -1], num_recon_slices=5, title=’Recon Visualization’)

mbirjax.plot_utils.plot_granularity_and_loss(granularity_sequences, fm_losses, prior_losses, labels, granularity_ylim=None, loss_ylim=None, fig_title='granularity')[source]#

Plots multiple granularity and loss data sets on a single figure.

Parameters:
  • granularity_sequences (list of lists) – A list containing different granularity sequences.

  • losses (list of lists) – A list containing different loss data corresponding to the granularity sequences.

  • labels (list of str) – Labels for each subplot to distinguish between different data sets.

  • granularity_ylim (tuple, optional) – Limits for the granularity axis (y-limits), applied to all plots.

  • loss_ylim (tuple, optional) – Limits for the loss axis (y-limits), applied to all plots.

mbirjax.plot_utils.make_figure_folder(fig_folder_name=None)[source]#