magmap.gui.roi_editor module#

ROI editing GUI in the MagellanMapper package.

ivar verify:

If true, verification mode is turned on, which for now simply turns on interior borders as the picker remains on by default.

class magmap.gui.roi_editor.DraggableCircle(circle, segment, fn_update_seg, picked, color='none')[source]#

Bases: object

Circle representation of a blob to allow the user to manipulate blob position, size, and status.

Variables:
  • BLOB_COLORS (dict) – Mapping of integers to Matplotlib color strings.

  • CUT (str) – Flag to cut a circle.

  • circle (patches.Circle) – A circle patch.

  • segment (np.ndarray) – Array in the format, [z, y, x, r, confirmation, truth] of the blob.

  • fn_update_seg (meth) – Function that takes (segment_new, segment_old) to call when updating the blob.

  • picked (list) – List of picked, active blobs in the tuple format, (segment, pick_flag).

BLOB_COLORS = {-1: 'none', 0: 'r', 1: 'g', 2: 'y'}#
CUT = 'cut'#
connect()[source]#

Connect events to functions.

disconnect()[source]#

Disconnect event listeners.

on_motion(event)[source]#

Move the circle if the drag event has been initiated.

on_pick(event)[source]#

Select the verification flag with button press on a circle when not dragging the circle.

on_press(event)[source]#

Initiate drag events with Shift- or Alt-click inside a circle.

Shift-click to move a circle, and Alt-click to resize a circle’s radius.

on_release(event)[source]#

Finalize the circle and segment’s position after a drag event is completed with a button release.

picked = None#
remove_self()[source]#
class magmap.gui.roi_editor.ROIEditor(img5d, labels_img=None, img_region=None, fn_show_label_3d=None, fn_status_bar=None)[source]#

Bases: ImageSyncMixin

Graphical interface for viewing and annotating 3D ROIs through serial 2D planes.

Provides overview plots showing context for the ROI at various zoom levels, which can be synchronized with the selected 2D plane or scrolled to other planes.

Overlays detected blobs as :class:DraggableCircle objects to flag, reposition, or add/subtract annotations.

plot_eds are dictionaries where keys are zoom levels and values are Plot Editors.

Variables:
  • ROI_COLS (int) – Default number of columns for the “zoomed-in” 2D plots, the 2D planes for the ROI.

  • ZLevels (Enum) – Enum denoting the possible positions of the z-plane shown in the overview plots.

  • fig (figure.figure) – Matplotlib figure.

  • labels_img (np.ndarray) – Atlas labels image in z,y,x format; defaults to None.

  • img_region (np.ndarray) – 3D boolean or binary array with the selected region labeled as True or 1. Defaults to None, in which case the region will be ignored.

  • fn_status_bar (func) – Function to call during status bar updates in pixel_display.PixelDisplay; defaults to None.

  • plane (str) – The plane to show in each 2D plot, eg “xy” to show the XY plane (default) or “xz” to show the XZ plane.

  • zoom_shift (List[float]) – Sequence of x,y shift in zoomed plot origin when zooming into ROI; defaults to None.

  • fn_update_coords (func) – Function to call when updating coordinates in the overview plots; defaults to None.

  • fn_redraw (func) – Function to call when double-clicking in an overview plot; defaults to None.

  • blobs (magmap.cv.detector.Blobs]) – Blobs object; defaults to None. Blobs should have coordinates relative to the ROI and may include blobs from adjacent regions.

class CircleStyles(value)[source]#

Bases: Enum

An enumeration.

CIRCLES = 'Blob circles'#
FULL_ANNOTATION = 'Full annotation'#
NO_CIRCLES = 'No circles'#
REPEAT_CIRCLES = 'Repeat circles'#
ROI_COLS = 9#
class ZLevels(value)#

Bases: Enum

An enumeration.

BOTTOM = 1#
MIDDLE = 2#
TOP = 3#
property additive_blend: bool#

Get additive blend setting.

get_save_path()[source]#

Get default figure save path.

Returns:

Figure save path based on ROI offset, shape, plane axis, z-plane of overview image, and extension based on config.savefig if available or config.DEFAULT_SAVEFIG if not.

Return type:

str

image5d: Optional['np_io.Image5d']#

Image instance to display.

plot_2d_stack(fn_update_seg, filename, channel, roi_size, offset, mask_in, blobs_cmap, fn_close_listener, border=None, zoom_levels=1, single_roi_row=False, z_level=ZLevels.BOTTOM, roi=None, labels=None, blobs_truth=None, circles=None, mlab_screenshot=None, grid=False, roi_cols=None, fig=None, region_name=None)[source]#

Shows a figure of 2D plots to compare with the 3D plot.

Parameters:
  • fn_update_seg (func) – Callback when updating a DraggableCircle.

  • filename (str) – Path to use when saving the plot.

  • channel – Channel of the image to display.

  • roi_size – List of x,y,z dimensions of the ROI.

  • offset – Tuple of x,y,z coordinates of the ROI.

  • mask_in – Boolean mask of segments within the ROI.

  • blobs_cmap – Colormap for blobs inside the ROI.

  • fn_close_listener – Handle figure close events.

  • border (default: None) – Border dimensions in pixels given as (x, y, z); defaults to None.

  • zoom_levels (int, List[int]) – Number of overview zoom levels to include or sequence of zoom multipliers; defaults to 1.

  • single_roi_row (default: False) – True if the ROI-sized plots should be displayed on a single row; defaults to False.

  • z_level (default: <ZLevels.BOTTOM: 1>) – Position of the z-plane shown in the overview plots, based on the Z_LEVELS attribute constant; defaults to Z_LEVELS[0].

  • roi (np.ndarray) – A denoised region of interest for display in ROI plots, such as a preprocessed ROI. Defaults to None, in which case image5d will be used instead.

  • labels (np.ndarray) – Segmentation labels of the same shape as that of image5d; defaults to None.

  • blobs_truth (np.ndarray) – Array of blobs to display as ground truth; defaults to None.

  • circles (default: None) – :class:CircleStyles enum member; defaults to None.

  • mlab_screenshot (np.ndarray) – Array from Mayavi screenshot; defaults to None.

  • grid (bool) – True to overlay a grid on all plots.

  • roi_cols (int) – Number of columns per row to reserve for ROI plots; defaults to None, in which case ROI_COLS will be used.

  • fig (figure.Figure) – Matplotlib figure; defaults to None to generate a new figure.

  • region_name (str) – Name of atlas region for title; defaults to None.

plot_roi(roi, segments, channel, show=True, title='')[source]#

Plot ROI as sequence of z-planes containing only the ROI itself.

Parameters:
  • roi – The ROI image as a 3D array in (z, y, x) order.

  • segments – Numpy array of segments to display in the subplot, which can be None. Segments are generally given as an (n, 4) dimension array, where each segment is in (z, y, x, radius). All segments are assumed to be within the ROI for display.

  • channel – Channel of the image to display.

  • show (default: True) – True if the plot should be displayed to screen; defaults to True.

  • title (default: '') – String used as basename of output file. Defaults to “” and only used if :attr:config.savefig is set to a file extension.

set_circle_visibility(visible)[source]#

Set the visibility of detection circles.

Parameters:

visible (bool) – True to make the circles visible, False for invisibility.

show_colocalized_blobs(visible)[source]#

Show blob co-localization by overlaying text showing all the channels with signal at each blob’s position.

Parameters:

visible (bool) – True to make the co-localization text visible.

show_subplot(fig, gs, row, col, channel, roi_size, offset, fn_update_seg, segs_in, segs_out, segs_cmap, alpha, z_relative, highlight=False, border=None, plane='xy', roi=None, labels=None, blobs_truth=None, circles=None, aspect=None, grid=False, cmap_labels=None)[source]#

Shows subplots of the region of interest.

Parameters:
  • fig (figure.Figure) – Matplotlib figure.

  • gs – Gridspec layout.

  • row – Row number of the subplot in the layout.

  • col – Column number of the subplot in the layout.

  • channel – Channel of the image to display.

  • roi_size – List of x,y,z dimensions of the ROI.

  • offset – Tuple of x,y,z coordinates of the ROI.

  • fn_update_seg – Function to update blob.

  • segs_in – Numpy array of segments within the ROI to display in the subplot, which can be None. Segments are generally given as an (n, 4) dimension array, where each segment is in (z, y, x, radius).

  • segs_out – Subset of segments that are adjacent to rather than inside the ROI, which will be drawn in a different style. Can be None.

  • segs_cmap – Colormap for segments.

  • alpha – Opacity level.

  • z_relative – Index of the z-plane relative to the start of the ROI.

  • highlight (default: False) – If true, the plot will be highlighted; defaults to False.

  • border (default: None) – Border dimensions in pixels given as (x, y, z); defaults to None.

  • plane (default: 'xy') – The plane to show in each 2D plot, with “xy” to show the XY plane (default) and “xz” to show XZ plane.

  • roi (default: None) – A denoised region of interest, to show in place of image5d for the zoomed images. Defaults to None, in which case image5d will be used instead.

  • labels (default: None) – Segmentation labels; defaults to None.

  • blobs_truth (default: None) – Truth blobs formatted similarly to segs_in; defaults to None.

  • circles (default: None) – :class:CircleStyles enum member; defaults to None.

  • aspect (default: None) – Image aspect; defauls to None.

  • grid (default: False) – True if a grid should be overlaid; defaults to False.

  • cmap_labels (default: None) – :class:colormaps.DiscreteColormap for labels; defaults to None.

Return type:

Tuple[Axes, Optional[PlotEditor]]

update_imgs_display(imgi, refresh=False, **kwargs)[source]#

Update images with the given display settings.

Parameters:
  • imgi (int) – Index of image group.

  • refresh (bool, default: False) – True to refresh all zoomed Plot Editors; defaults to False.

  • **kwargs – Arguments to pass to the updater.

Return type:

PlotAxImg

Returns:

Updated plotted image.

update_max_intens_proj(shape, show=False)[source]#

Update max intensity projection planes.

Parameters:
  • shape (Sequence[int]) – Number of planes in z,y,x, of which the value corresponding to plane will be used.

  • show (bool) – True to trigger an update in the Plot Editors; defaults to False.