realtime package

The realtime package provides modules for fast, low-latency execution of the VISWIR pipeline. It is designed for scenarios where image fusion and detection must be performed in near real-time, such as embedded systems or live video processing.

Warning

The fast mode does not compute quality metrics. It is mainly intended for quickly testing parameters and obtaining a visual result without the overhead of full evaluation.

Submodules

realtime.fast_config module

Configuration utilities optimized for fast execution.

Configuration loader and classes for the fast real-time VISWIR pipeline.

realtime.fast_config.load_fast_config(project_root: Path | None = None) dict[source]

Load the minimal configuration for the fast pipeline.

This function loads:

  • Base fusion parameters from config/fast_config.yaml.

  • YOLO detection parameters from config/yolo_config.json if available, otherwise falls back to default YOLO settings.

Parameters:

project_root (Path or None, optional) – Root directory of the project. If None, it is inferred automatically by traversing up from the current file location.

Returns:

Dictionary containing the following keys:

  • base (dict) – Base fusion parameters loaded from YAML.

  • yolo (dict) – YOLO detection parameters (from JSON or defaults).

  • paths (dict) – Paths used in the configuration:

    • project_root (str)

    • config_dir (str)

Return type:

dict

Notes

  • If yolo_config.json does not exist, default YOLO parameters are used: model path, confidence threshold, IoU threshold, device, and allowed classes.

  • Ensures consistent configuration loading for both fusion and detection.

realtime.fast_detection module

Lightweight detection routines adapted for speed in test contexts.

Real-time object detection module for the fast pipeline.

class realtime.fast_detection.FastDetector(model_path: Path, conf_thres=0.25, iou_thres=0.3, device='cpu', allowed_classes: Sequence[str] | None = None)[source]

Bases: object

Fast object detector using Ultralytics YOLO.

This class wraps a YOLO model for quick inference and visualization. It supports filtering by allowed classes and drawing bounding boxes with labels on images.

Parameters:
  • model_path (Path) – Path to the YOLO model weights.

  • conf_thres (float, default=0.25) – Confidence threshold for predictions.

  • iou_thres (float, default=0.3) – IoU threshold for non-maximum suppression.

  • device (str, default="cpu") – Device to run inference on (“cpu” or “cuda”).

  • allowed_classes (Sequence[str], optional) – List of class names to allow. If None, all classes are allowed.

Raises:
  • RuntimeError – If Ultralytics YOLO is not installed.

  • FileNotFoundError – If the YOLO weights file does not exist.

draw(img_rgb: ndarray, results) ndarray[source]

Draw bounding boxes and labels on an image based on YOLO results.

Parameters:
  • img_rgb (numpy.ndarray) – Input RGB image (float in [0, 1]).

  • results (list) – YOLO detection results containing bounding boxes and class IDs.

Returns:

Image with bounding boxes and labels drawn (float in [0, 1]).

Return type:

numpy.ndarray

Notes

  • Bounding boxes are drawn using skimage.draw.rectangle_perimeter.

  • Labels are drawn using Pillow.

  • Colors are assigned per class (e.g., person=green, others=red).

static draw_label(img_rgb: ndarray, x1, y1, name, color=(0, 255, 0))[source]

Draw a text label on an image at the given coordinates. (Static method)

Parameters:
  • img_rgb (numpy.ndarray) – Input RGB image (float in [0, 1]).

  • x1 (int) – X-coordinate of the label position.

  • y1 (int) – Y-coordinate of the label position.

  • name (str) – Class name to display.

  • color (tuple of int, default=(0, 255, 0)) – RGB color of the text.

Returns:

Image with the label drawn (float in [0, 1]).

Return type:

numpy.ndarray

predict(img_rgb: ndarray)[source]

Run YOLO prediction on an RGB image.

Parameters:

img_rgb (numpy.ndarray) – Input image in RGB format, normalized to [0, 1] or [0, 255].

Returns:

List of YOLO detection results.

Return type:

list

realtime.fast_fusion_runner module

Runner for executing the fusion pipeline, coordinating fast configuration and detection.

Fast/real-time pipeline runner for quick VISWIR execution.

class realtime.fast_fusion_runner.FastFusionPipeline(cfg: dict)[source]

Bases: object

Fast pipeline for VISWIR image fusion with optional YOLO detection.

This class loads configuration parameters, initializes the YOLO detector if required, and provides a run method to fuse visible and SWIR images.

Parameters:

cfg (dict) –

Configuration dictionary containing:

  • base (dict) – Base fusion parameters (facteur_swir, beta, level, apply_gamma, gamma_value).

  • yolo (dict) – YOLO detection parameters (model_path, thresholds, device, allowed_classes).

cfg

Full configuration dictionary.

Type:

dict

detector

YOLO detector instance if detection is enabled, otherwise None.

Type:

FastDetector or None

run_detection

Whether detection is enabled (from config).

Type:

bool

defaults

Default fusion parameters loaded from config.

Type:

dict

run(visible_path: Path, swir_path: Path, override_params: dict | None = None) ndarray[source]

Run the fusion pipeline on a pair of visible and SWIR images.

Parameters:
  • visible_path (Path) – Path to the visible (RGB) image.

  • swir_path (Path) – Path to the SWIR (grayscale) image.

  • override_params (dict, optional) – Dictionary of parameters to override defaults.

Returns:

Fused RGB image as float64 normalized to [0, 1]. If detection is enabled, bounding boxes and labels are drawn.

Return type:

numpy.ndarray

realtime.fast_fusion_runner.read_image_swir(path: Path) ndarray[source]

Read a SWIR (Short-Wave Infrared) image and convert it to float64 in [0, 1].

Parameters:

path (Path) – Path to the SWIR image file.

Returns:

Grayscale image as float64 normalized to [0, 1].

Return type:

numpy.ndarray

realtime.fast_fusion_runner.read_image_visible(path: Path) ndarray[source]

Read a visible (RGB) image and convert it to float64 in [0, 1].

Parameters:

path (Path) – Path to the visible image file.

Returns:

RGB image as float64 normalized to [0, 1].

Return type:

numpy.ndarray

Module contents

The top-level realtime module re-exports selected functions and classes from its submodules for convenience.

realtime package

Modules for the fast VISWIR pipeline: - Minimal configuration loading - Fast detection (YOLO) - Fast fusion runner