Skip to content

Image#

Image widget

Available in backends: qt

Signals#

  • changed(object) - Emitted when the widget value changes.
  • label_changed(str) - Emitted when the widget label changes.
  • native_parent_changed(object) - Emitted with the backend widget when the widget parent changes.

Image #

Bases: ValueWidget

A non-editable image display.

Parameters:

  • value (Any, default: Undefined ) –

    The starting value for the widget.

  • bind (Callable[[ValueWidget], Any] | Any, default: Undefined ) –

    A value or callback to bind this widget. If provided, whenever widget.value is accessed, the value provided here will be returned instead. bind may be a callable, in which case bind(self) will be returned (i.e. your bound callback must accept a single parameter, which is this widget instance).

  • nullable (bool, default: False ) –

    If True, the widget will accepts None as a valid value, by default False.

  • **base_widget_kwargs (Any, default: {} ) –

    All additional keyword arguments are passed to the base magicgui.widgets.Widget constructor.

image_data: np.ndarray | None property #

Return image data.

image_rgba: np.ndarray | None property #

Return rendered numpy array.

__repr__() -> str #

Return representation of widget of instance.

get_clim() -> tuple[float | None, float | None] #

Get contrast limits (for monochromatic images).

get_value() #

Return current image array.

scale_widget_to_image_size() #

Set the size of the widget to the size of the image.

set_clim(vmin: float | None = None, vmax: float | None = None) #

Set contrast limits (for monochromatic images).

Parameters:

  • vmin (float, default: None ) –

    The min contrast limit to use when scaling monochromatic images

  • vmax (float, default: None ) –

    The max contrast limit to use when scaling monochromatic images

set_cmap(cmap: str | Colormap | matplotlib.colors.Colormap) #

Set colormap (for monochromatic images).

Parameters:

  • cmap (str, magicgui.types.Colormap, or matplotlib.colors.Colormap) –

    A colormap to use for monochromatic images. If a string, matplotlib must be installed and the colormap will be selected with cm.get_cmap(cmap).

set_data(val: str | Path | np.ndarray | PIL.Image.Image, cmap: str | Colormap | matplotlib.colors.Colormap | None = None, norm: _mpl_image.Normalize | matplotlib.colors.Normalize | None = None, vmin: float | None = None, vmax: float | None = None, width: int | Literal['auto'] | None = None, height: int | Literal['auto'] | None = None, format: str | None = None) #

Set image data with various optional display parameters.

Parameters:

  • val ((str, Path, ndarray or Image)) –

    The image data or file to load. Data must be 2D (monochromatic), or 3D: MxNx3 (RGB) or MxNx4 (RGBA).

  • cmap (str, magicgui.types.Colormap, or matplotlib.colors.Colormap, default: None ) –

    A colormap to use for monochromatic images. If a string, matplotlib must be installed and the colormap will be selected with cm.get_cmap(cmap).

  • norm (magicgui.types.Normalize, or matplotlib.colors.Normalize, default: None ) –

    A normalization object to use for rendering images. Accepts matplotlib Normalize objects.

  • vmin (float, default: None ) –

    The min contrast limit to use when scaling monochromatic images

  • vmax (float, default: None ) –

    The max contrast limit to use when scaling monochromatic images

  • width (int or 'auto', default: None ) –

    Set the width of the widget. If "auto", sets the widget size to the image size (1:1). If width is provided, height is auto-set based on aspect ratio.

  • height (int or 'auto', default: None ) –

    Set the height of the widget. If "auto", sets the widget size to the image size (1:1). If width is provided, height is auto-set based on aspect ratio.

  • format (str, default: None ) –

    Force image format type for imread when val is provided as a string, by default None

Raises:

  • TypeError

    If the provided data shape or type is invalid.

  • ImportError

    If a string is provided for val and PIL is not installed.

  • RuntimeError

    If a PIL.Image.Image instance is provided as data, with an unrecognized image mode.

set_norm(norm: Normalize | matplotlib.colors.Normalize) #

Set normalization method.

Parameters:

  • norm (magicgui.types.Normalize, or matplotlib.colors.Normalize) –

    A normalization object to use for rendering images. Accepts matplotlib Normalize objects.

set_value(value) #

Set current data. Alias for image.set_data(value).