radioviz.controllers.image_window_controller

Image window controller module.

This module contains the controller class for managing image windows in the radioviz application. It handles the interaction between the image data, the view, and various mouse events.

Functions

scale_image(input_image, factor)

Scale an image to a specified factor using local mean downsampling.

Classes

ImageWindowController(source, image_data[, ...])

Controller for managing image windows in the application.

class radioviz.controllers.image_window_controller.ImageWindowController(source: DataSource, image_data: ndarray, storage: DataStorage | None = None, metadata: dict[str, Any] | None = None, view: ImageWindow | None = None)[source]

Bases: SubWindowController[ImageWindow]

Controller for managing image windows in the application.

It is responsible for the business logic and for the data ownership.

This class handles the logic for displaying and interacting with image data through the image window view. It manages mouse events, display properties, and communication between the model and view layers.

Variables:
  • request_canvas_update – Signal emitted to request canvas update

  • point_selection_mode – Signal emitted when point selection mode changes

Initialize the ImageWindowController.

Parameters:
  • source (DataSource) – The source information for the image

  • image_data (numpy.ndarray) – The actual image data as a numpy array

  • metadata (Optional[dict[str, Any]]) – Optional metadata associated with the image

  • view (ImageWindow, optional) – Optional view instance to associate with this controller

_context(pos: tuple[float, float]) None[source]

Handle context menu requests.

Parameters:

pos (tuple) – Position where context menu was requested

_describe_derivation(source: DataSource | None = None) str | None[source]

Describe the derivation of the current or provided data source.

Parameters:

source (DataSource | None) – Optional data source to describe; defaults to controller source.

Returns:

Derivation description or None if not derived.

Return type:

str | None

_format_extents(extents: Any, n_decimal: int = 2) str[source]

Format ROI extents values with configurable decimal places.

Parameters:
  • extents (Any) – ROI extents sequence.

  • n_decimal (int) – Number of decimal places for formatting numeric values.

Returns:

Formatted extents string.

Return type:

str

_launch_worker(factor: int) None[source]

Launch a worker thread to compute the image at the specified resolution.

Creates a worker using the scale_image() function and connects its returned signal to the _on_level_ready() method.

Parameters:

factor (int) – The resolution factor to compute

_move(ev: MouseEvent) None[source]

Handle mouse move events.

Parameters:

ev (matplotlib.backend_bases.MouseEvent) – Mouse event from matplotlib

_on_level_ready(result: tuple[int, ndarray]) None[source]

Handle the completion of a resolution level computation.

Stores the computed image data and removes the factor from pending resolutions, then emits a signal indicating the resolution is ready.

Parameters:

result (tuple[int, numpy.ndarray]) – Tuple containing (factor, image_data)

_press(ev: MouseEvent) None[source]

Handle mouse press events.

Parameters:

ev (matplotlib.backend_bases.MouseEvent) – Mouse event from matplotlib

_save_image_data(path: Path) None[source]

Save the internal image data to the specified path using imageio.

Parameters:

path (Path) – The file path where the image will be saved

Returns:

None

Return type:

None

_set_default_display_properties() dict[str, Any][source]

Set the default display properties for the image.

Initializes the display properties dictionary with default values including vmin, vmax, colormap (‘hot’), and interpolation (‘none’).

Returns:

Dictionary containing default display properties

Return type:

dict[str, Any]

_set_vmin_vmax() tuple[int, int][source]

Set the initial vmin and vmax values for the image display.

Determines the minimum and maximum values from the image data to establish the initial display range. If no image data is available, defaults to a 16-bit unsigned integer range.

Returns:

A tuple containing (vmin, vmax) for the image display

Return type:

tuple[int, int]

_snap_factor(factor: int) int[source]

Snap the given factor to the nearest allowed scale factor.

Finds the smallest allowed scale factor that is greater than or equal to the provided factor. If no such factor exists, returns the largest allowed factor.

Parameters:

factor (int) – The factor to snap

Returns:

The snapped factor

Return type:

int

can_export_as() bool[source]

Check if the current image can be exported.

Returns:

True if the image can be exported, False otherwise

Return type:

bool

default_file_name() str[source]

Return the default file name for saving the image.

Returns:

Default file name based on the image source label

Return type:

str

derive_metadata_for_child(child_source: DataSource) dict[str, Any][source]

Derive metadata for a child image based on this controller’s metadata.

Parameters:

child_source (DataSource) – Data source describing the derived image.

Returns:

Derived metadata dictionary.

Return type:

dict[str, Any]

distance_unit() DistanceUnit | None[source]

Select a suitable distance unit based on image size and pixel size.

Returns:

Distance unit or None when unavailable.

Return type:

DistanceUnit | None

export_to_path(path: Path) None[source]

Export the current view to the specified path.

Parameters:

path (Path) – The file path where the export will be saved

Returns:

None

Return type:

None

from_workspace(spec: ImageWorkspaceSpec, context: WorkspaceReferenceManager) Self[source]

From Workspace placeholder-

get_export_specs() list[ExportSpec][source]

Get the list of available export specifications for the image.

Returns:

List of export specifications or empty list if no image data exists

Return type:

list[ExportSpec]

get_resolution_level(factor: int) ndarray | None[source]

Get the image data for a specific resolution level.

Parameters:

factor (int) – The resolution factor to retrieve

Returns:

The image data for the specified resolution level or None

Return type:

numpy.ndarray or None

get_save_specs() list[SaveSpec][source]

Get the list of available save specifications for the image.

Returns:

List of save specifications or empty list if no image data exists

Return type:

list[SaveSpec]

initialize_display_data() None[source]

Initialize the display data with the coarsest resolution level.

Sets the initial coarse factor to the maximum allowed scale factor and emits a signal indicating that the display resolution is ready.

metadata_items() list[tuple[str, str, str]][source]

Provide formatted metadata entries for display.

Returns:

List of metadata entries.

Return type:

list[tuple[str, str, str]]

mpl_display_properties() dict[str, Any][source]

Return display properties suitable for Matplotlib imshow/update.

Returns:

Display properties filtered for Matplotlib.

Return type:

dict[str, Any]

on_view_created() None[source]

Perform actions after the view has been created.

Connects the canvas update signal to the view’s update method.

pixel_size_m() tuple[float, float] | None[source]

Pixel size in meters derived from metadata, if available.

Returns:

Tuple of pixel sizes in meters or None.

Return type:

tuple[float, float] | None

request_resolution_level(factor: int) None[source]

Request a specific resolution level for the image.

This method snaps the requested factor to the nearest allowed scale factor, checks if the level is already available or pending, and launches a worker to compute the level if needed.

Parameters:

factor (int) – The requested resolution factor

save_to_path(path: Path) None[source]

Save the image data to the specified path.

Parameters:

path (Path) – The file path where the image will be saved

Returns:

None

Return type:

None

set_display_properties(params: dict[str, Any]) None[source]

Update the display properties with the provided parameters.

Updates the display properties dictionary with new values. For colormap values, converts string colormaps to matplotlib format using Colormap.to_mpl().

Parameters:

params (dict) – Dictionary containing display property updates

set_view(view: ImageWindow) None[source]

Set the view associated with this controller.

Connects the view signals to the appropriate controller methods.

Parameters:

view (radioviz.views.sub_window.SubWindow) – The image window view to associate with this controller

Returns:

None

Return type:

None

to_workspace(include_data: bool) ImageWorkspaceSpec[source]

Convert the current image controller state to a workspace specification.

Creates an ImageWorkspaceSpec containing the controller’s identification, source information, storage details, display parameters, and optionally the image data itself based on the include_data flag.

Parameters:

include_data (bool) – Flag indicating whether to include the image data in the spec

Returns:

ImageWorkspaceSpec containing the controller’s state

Return type:

ImageWorkspaceSpec

property axis_label_mode: str

Current axis label mode.

Returns:

Axis label mode.

Return type:

str

property scalebar_settings: dict[str, Any]

Current scalebar settings dictionary.

Returns:

Scalebar settings.

Return type:

dict[str, Any]

radioviz.controllers.image_window_controller.scale_image(input_image: ndarray, factor: int) tuple[int, ndarray][source]

Scale an image to a specified factor using local mean downsampling.

Parameters:
  • input_image (numpy.ndarray) – The input image to scale

  • factor (int) – The scaling factor

Returns:

Tuple of (factor, scaled_image)

Return type:

tuple[int, numpy.ndarray]