Image widget#

The Image widget is a versatile tool designed for visualizing both 1D and 2D data, such as camera images or waveform data, in real-time. Directly integrated with the BEC framework, it can display live data streams from connected detectors or other data sources within the current BEC session. The widget provides advanced customization options for color maps and scale bars, allowing users to tailor the visualization to their specific needs.

Key Features:

  • Flexible Integration: The widget can be integrated into BECDockArea, or used as an individual component in your application through BEC Designer.

  • Live Data Visualization: Real-time plotting of both 1D and 2D data from detectors or other data sources, provided that a data stream is available in the BEC session.

  • Support for Multiple Monitor Types: The Image widget supports different monitor types ('1d' and '2d'), allowing visualization of various data dimensions. It can automatically determine the best way to visualise the data based on the shape of the data source.

  • Customizable Color Maps and Scale Bars: Users can customize the appearance of images with various color maps and adjust scale bars to better interpret the visualized data.

  • Real-time Image Processing: Apply real-time image processing techniques directly within the widget to enhance the quality or analyze specific aspects of the data, such as rotation, logarithmic scaling, and Fast Fourier Transform (FFT).

  • Data Export: Export visualized data to various formats such as PNG, TIFF, or H5 for further analysis or reporting.

  • Interactive Controls: Offers interactive controls for zooming, panning, and adjusting the visual properties of the images on the fly.

Image 2D

ImageWidget can be embedded in BECDockArea, or used as an individual component in your application through BEC Designer. The command-line API is the same for all cases.

Example 1 - Visualizing 2D Image Data from a Detector

In this example, we demonstrate how to add an ImageWidget to a BECDockArea to visualize live 2D image data from a connected camera detector.

# Add a new dock with BECFigure widget
dock_area = gui.new()
img_widget = dock_area.new().new(gui.available_widgets.Image)

# Add an ImageWidget to the BECFigure for a 2D detector
img_widget.image(device='eiger', signal='preview')
img_widget.title = "Camera Image - Eiger Detector"

Example 2 - Visualizing 1D Waveform Data from a Detector

This example demonstrates how to set up the Image widget to visualize 1D waveform data from a detector, such as a line detector or a spectrometer. The widget will stack incoming 1D data arrays to construct a 2D image.

# Add a new dock with BECFigure widget
dock_area = gui.new()
img_widget = dock_area.new().new(gui.available_widgets.Image)

# Add an ImageWidget to the BECFigure for a 2D detector
img_widget.image(device='waveform', signal='data')
img_widget.title = "Line Detector Data"

# Optional: Set the color map and value range
img_widget.colormap = "plasma"
img_widget.vrange= [0, 100]

Example 3 - Real-time Image Processing

The Image provides real-time image processing capabilities, such as rotating, scaling, applying logarithmic scaling, and performing FFT on the displayed images. The following example demonstrates how to apply these transformations to an image.

# Rotate the image by 90 degrees (1,2,3,4 are multiplied by 90 degrees)
img_widget.num_rotation_90 = 1

# Transpose the image
img_widget.transpose = True

# Apply FFT to the image
img_widget.fft = True

# Set logarithmic scaling for the image display
img_widget.log = True

# Set autorange for the image color map
img_widget.autorange = True
img_widget.autorange_mode = 'mean'# or 'max' 
class Image(gui_id: str | None = None, config: dict | None = None, object_name: str | None = None, parent=None, **kwargs)[source]#

Bases: RPCBase

Image widget for displaying 2D data.

add_roi(kind: Literal['rect', 'circle', 'ellipse'] = 'rect', name: str | None = None, line_width: int | None = 5, pos: tuple[float, float] | None = (10, 10), size: tuple[float, float] | None = (50, 50), movable: bool = True, **pg_kwargs) RectangularROI | CircularROI[source]#

Add a ROI to the image.

Parameters:
  • kind (str) – The type of ROI to add. Options are “rect” or “circle”.

  • name (str) – The name of the ROI.

  • line_width (int) – The line width of the ROI.

  • pos (tuple) – The position of the ROI.

  • size (tuple) – The size of the ROI.

  • movable (bool) – Whether the ROI is movable.

  • **pg_kwargs – Additional arguments for the ROI.

Returns:

The created ROI object.

Return type:

RectangularROI | CircularROI

attach()[source]#

None

auto_range(value: bool = True)[source]#

On demand apply autorange to the plot item based on the visible curves.

Parameters:

value (bool) – If True, apply autorange to the visible curves.

property auto_range_x: bool#

Set auto range for the x-axis.

property auto_range_y: bool#

Set auto range for the y-axis.

property autorange: bool#

Whether autorange is enabled.

property autorange_mode: str#

Autorange mode.

Options:
  • “max”: Use the maximum value of the image for autoranging.

  • “mean”: Use the mean value of the image for autoranging.

property color_map: str#

Set the color map of the image.

detach()[source]#

Detach the widget from its parent dock widget (if widget is in the dock), making it a floating widget.

property device: str#

The name of the device to monitor for image data.

enable_colorbar(enabled: bool, style: Literal['full', 'simple'] = 'full', vrange: tuple[int, int] | None = None)[source]#

Enable the colorbar and switch types of colorbars.

Parameters:
  • enabled (bool) – Whether to enable the colorbar.

  • style (Literal["full", "simple"]) – The type of colorbar to enable.

  • vrange (tuple) – The range of values to use for the colorbar.

property enable_fps_monitor: bool#

Enable the FPS monitor.

property enable_full_colorbar: bool#

Enable the full colorbar.

property enable_side_panel: bool#

Show Side Panel

property enable_simple_colorbar: bool#

Enable the simple colorbar.

property enable_toolbar: bool#

Show Toolbar.

property fft: bool#

Whether FFT postprocessing is enabled.

image(device: str | None = None, signal: str | None = None, color_map: str | None = None, color_bar: Literal['full', 'simple'] | None = None, vrange: tuple[int, int] | None = None) ImageItem | None[source]#

Set the image source and update the image.

Parameters:
  • device (str|None) – The name of the device to monitor. If None or empty string, the current monitor will be disconnected.

  • signal (str|None) – The signal/entry name to monitor on the device.

  • color_map (str) – The color map to use for the image.

  • color_bar (str) – The type of color bar to use. Options are “simple” or “full”.

  • vrange (tuple) – The range of values to use for the color map.

Returns:

The image object, or None if connection failed.

Return type:

ImageItem

property inner_axes: bool#

Show inner axes of the plot widget.

property legend_label_size: int#

The font size of the legend font.

property lock_aspect_ratio: bool#

Whether the aspect ratio is locked.

property log: bool#

Whether logarithmic scaling is applied.

property main_image: ImageItem#

Access the main image item.

property minimal_crosshair_precision: int#

Minimum decimal places for crosshair when dynamic precision is enabled.

property num_rotation_90: int#

The number of 90° rotations to apply counterclockwise.

property outer_axes: bool#

Show the outer axes of the plot widget.

remove()[source]#

Cleanup the BECConnector

remove_roi(roi: int | str)[source]#

Remove an ROI by index or label via the ROIController.

property rois: list[BaseROI]#

Get the list of ROIs.

screenshot(file_name: str | None = None)[source]#

Take a screenshot of the dock area and save it to a file.

set(**kwargs)[source]#

Set the properties of the plot widget.

Parameters:

**kwargs – Keyword arguments for the properties to be set.

Possible properties:
  • title: str

  • x_label: str

  • y_label: str

  • x_scale: Literal[“linear”, “log”]

  • y_scale: Literal[“linear”, “log”]

  • x_lim: tuple

  • y_lim: tuple

  • legend_label_size: int

property signal: str#

The signal/entry name to monitor on the device.

property title: str#

Set title of the plot.

property transpose: bool#

Whether the image is transposed.

property v_max: float#

Get the maximum value of the v_range.

property v_min: float#

Get the minimum value of the v_range.

property v_range: QPointF#

Set the v_range of the main image.

property x_grid: bool#

Show grid on the x-axis.

property x_label: str#

The set label for the x-axis.

property x_limits: QPointF#

Get the x limits of the plot.

property x_log: bool#

Set X-axis to log scale if True, linear if False.

property y_grid: bool#

Show grid on the y-axis.

property y_label: str#

The set label for the y-axis.

property y_limits: QPointF#

Get the y limits of the plot.

property y_log: bool#

Set Y-axis to log scale if True, linear if False.