magmap.gui.plot_editor module

Editor for 2D plot with overlaid planes.

Integrates with :class:atlas_editor.AtlasEditor for synchronized 3D view of orthogonal planes.

class magmap.gui.plot_editor.PlotAxImg(ax_img, vmin=None, vmax=None, img=None)[source]

Bases: object

Axes image storage class.

Tracks settings that may differ between the currently displayed image and input values, such as None to specify auto-intensity and values for brightness and contrast that are not stored in the image itself.

Variables:
  • ax_img – Displayed Matplotlib image.

  • vmin – Specified vmin; defaults to None for auto-scaling. See ax_img.norm.vmin for the output vmin.

  • vmax – Specified vmax; defaults to None for auto-scaling. See ax_img.norm.vmax for the output vmax.

  • brightness – Brightness addend; defaults to 0.0.

  • contrast – Contrast factor; defaults to 1.0.

  • alpha – Opacity level; defaults to None.

  • alpha_blend – Opacity level of the first level in the area of blending between two images; defaults to None.

img: ndarray

Original array of the displayed Matplotlib image. If None (default), the displayed image’s array will be copied to allow adjusting the array in ax_img while retaining the original data.

input_img: Optional[ndarray]

Original input image data; defaults to None.

rgb: bool

True if the image is displayed as RGB(A); defaults to False.

class magmap.gui.plot_editor.PlotEditor(overlayer, img3d, img3d_labels=None, cmap_labels=None, plane=None, fn_update_coords=None, fn_refresh_images=None, scaling=None, plane_slider=None, img3d_borders=None, cmap_borders=None, fn_show_label_3d=None, interp_planes=None, fn_update_intensity=None, max_size=None, fn_status_bar=None, img3d_extras=None)[source]

Bases: object

Show a scrollable, editable plot of sequential planes in a 3D image.

Variables:
  • intensity (int) – Chosen intensity value of img3d_labels.

  • intensity_spec (int) – Intensity value specified directly rather than chosen from the labels image.

  • intensity_shown (int) – Displayed intensity in the matplotlib.AxesImage corresponding to img3d_labels.

  • coord (List[int]) – Coordinates in z, y, x.

  • scale_bar (bool) – True to add a scale bar; defaults to False.

  • enable_painting (bool) – True to enable label painting; defaults to True.

  • max_intens_proj (int) – Number of planes to include in a maximum intensity projection; defaults to 0 for no projection. The planes are taken starting from the given z-value in coord, limited by the number of planes available. Applied to the first intensity image.

ALPHA_DEFAULT = 0.5
alpha: float

Labels opacity from 0-1; defaults to ALPHA_DEFAULT.

alpha_img3d: Sequence[float]

Main image opacity as a sequence of values from 0-1 for each channel. Defaults to a list of the first element in config.alphas.

alpha_updater(alpha)[source]

Update labels image opacity level.

Params:

alpha (float): Alpha level.

blitter: Optional[Blitter]

Blit manager.

static change_brightness_contrast(plot_ax_img, brightness, contrast)[source]

Change image brightness and contrast.

All changes are made relative to the original image, so both brightness and contrast should be given together. For example, if brightness is changed, and later contrast is changed, the contrast change will wipe out the brightness change unless the brightness value is given again.

Parameters:
  • plot_ax_img (PlotAxImg) – Axes image storage instance.

  • brightness (Optional[float]) – Brightness value, centered on 0. Can be None to ignore brightness changes.

  • contrast (Optional[float]) – Contrast value, centered on 1. Can be None to ignore contrast changes.

cmap_labels: Optional[ListedColormap]

Labels colormap, generally of magmap.plot.colormaps.DiscreteColormap. Defaults to None.

connect()[source]

Connect events to functions.

disconnect()[source]

Disconnect event listeners.

draw_crosslines(show=None)[source]

Draw crosshairs depicting the x and y values in orthogonal viewers.

Parameters:

show (bool) – True to show crosslines, False to make them invisible; defaults to None to use show_crosslines.

property edit_mode: bool

Atlas labels edit mode status.

Returns:

True if in edit mode, False otherwise.

fn_update_coords: Callable[[Sequence[int], str], None]

Callback when updating coordinates, typically mouse click events in x,y; takes two arguments, the updated coordinates and plane to indicate the coordinates’ orientation.

get_displayed_img(imgi, chl=None)[source]

Get display settings for the given image.

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

  • chl (int) – Index of channel within the group; defaults to None.

Returns:

The currently displayed image.

Return type:

PlotAxImg

static get_plot_ax_img(plot_ax_imgs, imgi, channels=None, chl=None)[source]

Get a plotted image based on image group and channel.

Parameters:
  • plot_ax_imgs (Sequence[Sequence[PlotAxImg]]) – Plotted image objects, organized as [[img0_chl0, img0_chl1, ...], [img1_chl0, ...], ....].

  • imgi (int) – Index of image group in plot_ax_imgs.

  • channels (Optional[Sequence[Sequence[int]]], default: None) – List of channel lists corresponding to plot_ax_imgs; defalts to None to use chl directly.

  • chl (Optional[int], default: None) – Index of channel within the selected image group; defaults to None to use the first channel.

Return type:

Optional[PlotAxImg]

Returns:

The selected plotted image, or None if image corresponding to imgi and chl is not found.

img3d: ndarray

Main 3D image.

img3d_labels: Optional[ndarray]

Labels 3D image; defaults to None.

label_motion_thresh: float

Threshold for triggering label motion events. Use 0 (default) to respond to all events except those within the same pixel. Higher values filter more movements, especially fast and short motions. Use np.inf to ignore motion and respond to left-click instead.

labels_level: Optional[int]

Ontology level at which to show region names.

nav_motion_thresh: float

Threshold for triggering navigation (eg pan/zoom) events. See label_motion_thresh, except np.inf simply turns off navigation.

on_axes_exit(event)[source]

Remove any mouse circle and region label.

on_key_press(event)[source]

Change pen radius with bracket ([/]) buttons.

The “ctrl” modifier will have the increment.

Parameters:

event – Key press event.

on_motion(event)[source]

Handle motion events, including navigation and label editing.

on_press(event)[source]

Respond to mouse press events.

on_release(event)[source]

Respond to mouse button release events.

If labels were edited during the current mouse press, update plane interpolation values. Also reset any specified intensity value.

Parameters:

event – Key press event.

overlayer: ImageOverlayer

Manager for plotting overlaid images.

plane: str

One of magmap.settings.config.PLANE specifying the orthogonal plane to view.

property plot_ax_imgs: List[PlotAxImg] | None
refresh_img3d_labels()[source]

Replace the displayed labels image with underlying plane’s data.

scroll_overview(event, only_in_axes=True, fn_jump=None)[source]
set_show_label(val)[source]

Set whether to show labels on hover.

Parameters:

val (bool) – True to show labels, False otherwise.

show_labels(show=True, **kwargs)[source]

Show or remove labels for all regions.

Parameters:
  • show (bool, default: True) – True (default) to show all labels; False to remove them.

  • kwargs – Arguments passed to magmap.plot_support.ImageOverlayer.annotate_labels().

show_overview()[source]

Show the main 2D plane, taken as a z-plane.

show_roi(offset=None, size=None, preview=False)[source]

Show an ROI as an empty rectangular patch.

If offset and size cannot be retrieved, no ROI will be shown.

Parameters:
  • offset (List[int]) – ROI offset in y, x. Defaults to None to use the saved ROI offset if available.

  • size (List[int]) – ROI size in y, x. Defaults to None to use the saved ROI size if available.

  • preview (bool) – True if the ROI should be displayed as a preview, which is lighter and transient, removed when another preview ROI is displayed. Defaults to False. If False, ROI parameters for a displayed ROI will be shown.

translate_coord(coord, up=False, coord_slice=None)[source]

Translate coordinate based on downsampling factor of the main image.

Coordinates sent to and received from the Atlas Editor are assumed to be in the original image space. All overlaid images are assumed to be resized to the shape of the main image.

Parameters:
  • coord (Sequence[int]) – Coordinates in z,y,x.

  • up (bool, default: False) – True to upsample; defaults to False, which adjusts coordinates for downsampled images.

  • coord_slice (Union[slice, Sequence[slice], None], default: None) – Slice of each set of coordinates to transpose. Defaults to None, which gives a slice starting at 1 so that the z-value will not be adjusted on the assumption that downsampling is only performed in x,y.

Returns:

The translated coordinates.

Return type:

List[int]

update_alpha_blend(imgi, alpha_blend)[source]

Update alpha blending between two images.

Parameters:
  • imgi (int) – Index of image group. The first two images in this group will be blended.

  • alpha_blend (float) – Alpha opacity level for the blending.

Return type:

List[PlotAxImg]

Returns:

List of the updated axes image storage instances.

update_coord(coord=None)[source]

Update the displayed image for the given coordinates.

Scroll to the given z-plane if changed and draw crosshairs to indicated the corresponding x,y values.

Parameters:

coord (List[int]) – Coordinates in z,y,x, assumed to be transposed so the z-plane is show in this editor; defaults to None to use coord.

update_img_display(imgi, chl=None, minimum=nan, maximum=nan, brightness=None, contrast=None, alpha=None, alpha_blend=None)[source]

Update displayed image settings.

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

  • chl (Optional[int], default: None) – Index of channel within the group; defaults to None.

  • minimum (float, default: nan) – Vmin; can be None for auto setting; defaults to np.nan to ignore.

  • maximum (float, default: nan) – Vmax; can be None for auto setting; defaults to np.nan to ignore.

  • brightness (Optional[float], default: None) – Brightness addend; defaults to None.

  • contrast (Optional[float], default: None) – Contrast multiplier; defaults to None.

  • alpha (Optional[float], default: None) – Opacity value; defaults to None.

  • alpha_blend (Optional[float], default: None) – Opacity blending value; defaults to None. False turns off alpha blending, resetting the images to their stored alpha values.

Return type:

PlotAxImg

Returns:

The updated axes image plot.

update_plane_slider(val)[source]
static update_plot_ax_img_display(plot_ax_img, minimum=nan, maximum=nan, brightness=None, contrast=None, alpha=None, **kwargs)[source]

Update plotted image display settings.

Parameters:
  • plot_ax_img (PlotAxImg) – Plotted image.

  • minimum (float, default: nan) – Vmin; can be None for auto setting; defaults to np.nan to ignore.

  • maximum (float, default: nan) – Vmax; can be None for auto setting; defaults to np.nan to ignore.

  • brightness (Optional[float], default: None) – Brightness addend; defaults to None.

  • contrast (Optional[float], default: None) – Contrast multiplier; defaults to None.

  • alpha (Optional[float], default: None) – Opacity value; defalts to None.

  • **kwargs – Extra arguments, currently ignored.

Return type:

Optional[PlotAxImg]

Returns:

The updated axes image plot.

view_subimg(offset, size)[source]

View a sub-image.

Parameters: