Show2D#

class quantem.widget.Show2D(**kwargs: Any)[source]#

Bases: AnyWidget

Static 2D image viewer with optional FFT and histogram analysis.

Display a single image or multiple images in a gallery layout. For interactive stack viewing with playback, use Show3D instead.

Parameters:
  • data (array_like) – 2D array (height, width) for single image, or 3D array (N, height, width) for multiple images displayed as gallery.

  • labels (list of str, optional) – Labels for each image in gallery mode.

  • title (str, optional) – Title to display above the image(s).

  • cmap (str, default "inferno") – Colormap name (“magma”, “viridis”, “gray”, “inferno”, “plasma”).

  • pixel_size (float, optional) – Pixel size in angstroms for scale bar display.

  • show_fft (bool, default False) – Show FFT and histogram panels.

  • show_stats (bool, default True) – Show statistics (mean, min, max, std).

  • log_scale (bool, default False) – Use log scale for intensity mapping.

  • auto_contrast (bool, default False) – Use percentile-based contrast.

  • ncols (int, default 3) – Number of columns in gallery mode.

  • disabled_tools (list of str, optional) – Tool groups to lock while still showing controls. Supported: "display", "histogram", "stats", "navigation", "view", "export", "roi", "profile", "all".

  • disable_* (bool, optional) – Convenience flags (disable_display, disable_histogram, disable_stats, disable_navigation, disable_view, disable_export, disable_roi, disable_profile, disable_all) equivalent to adding those keys to disabled_tools.

  • hidden_tools (list of str, optional) – Tool groups to hide from the UI. Uses the same keys as disabled_tools.

  • hide_* (bool, optional) – Convenience flags mirroring disable_* for hidden_tools.

Examples

>>> import numpy as np
>>> from quantem.widget import Show2D
>>>
>>> # Single image with FFT
>>> Show2D(image, title="HRTEM Image", show_fft=True, pixel_size=1.0)
>>>
>>> # Gallery of multiple images
>>> labels = ["Raw", "Filtered", "FFT"]
>>> Show2D([img1, img2, img3], labels=labels, ncols=3)

Key Methods

Show2D.set_image(data, labels=None)[source]#

Replace the displayed image(s). Preserves all display settings.

Show2D.save_image(path: str | Path, *, idx: int | None = None, format: str | None = None, dpi: int = 150) Path[source]#

Save current image as PNG or PDF.

Parameters:
  • path (str or pathlib.Path) – Output file path.

  • idx (int, optional) – Image index in gallery mode. Defaults to current selected_idx.

  • format (str, optional) – ‘png’ or ‘pdf’. If omitted, inferred from file extension.

  • dpi (int, default 150) – Output DPI metadata.

Returns:

The written file path.

Return type:

pathlib.Path

Line Profile

Show2D.set_profile(start: tuple, end: tuple)[source]#

Set a line profile between two points (image pixel coordinates).

Parameters:
  • start (tuple of (row, col)) – Start point in pixel coordinates.

  • end (tuple of (row, col)) – End point in pixel coordinates.

Show2D.clear_profile()[source]#

Clear the current line profile.

ROI

Show2D.add_roi(row: int | None = None, col: int | None = None, shape: str = 'square') Self[source]#
Show2D.set_roi(row: int, col: int, radius: int = 10) Self[source]#
Show2D.clear_rois() Self[source]#
Show2D.delete_selected_roi() Self[source]#
Show2D.roi_circle(radius: int = 10) Self[source]#
Show2D.roi_square(half_size: int = 10) Self[source]#
Show2D.roi_rectangle(width: int = 20, height: int = 10) Self[source]#
Show2D.roi_annular(inner: int = 5, outer: int = 10) Self[source]#

State Persistence

Show2D.state_dict()[source]#
Show2D.save(path: str)[source]#
Show2D.load_state_dict(state)[source]#
Show2D.summary()[source]#