fusion package

The fusion package implements the core algorithms and utilities for VISWIR image fusion. It provides modules for:

  • Performing the actual fusion of visible and SWIR images

  • Running object detection on fused images

  • Computing quality metrics

  • Utility functions for preprocessing and support tasks

Subpackages

Submodules

fusion.detection_module module

YOLO-based detection module for evaluating fused images.

Object detection and evaluation (YOLO, precision, recall, F1, IoU) for VISWIR.

fusion.detection_module.iou(box1, box2)[source]

Compute the Intersection over Union (IoU) between two bounding boxes.

Parameters:
  • box1 (list of int) – First bounding box [xmin, ymin, xmax, ymax].

  • box2 (list of int) – Second bounding box [xmin, ymin, xmax, ymax].

Returns:

IoU value between the two bounding boxes.

Return type:

float

fusion.detection_module.parse_voc_annotations(xml_path)[source]

Parse Pascal VOC XML annotations and extract bounding boxes.

Parameters:

xml_path (str or Path) – Path to the Pascal VOC XML annotation file.

Returns:

List of bounding boxes in the format [xmin, ymin, xmax, ymax].

Return type:

list of list of int

fusion.detection_module.prepare_image_for_yolo(image_input, mode='default')[source]

Prepare an image for YOLOv8 prediction.

This function accepts either a file path (str or Path) or a NumPy array. It handles specific preprocessing for different modes: - “swir”: converts single-channel SWIR images into 3-channel pseudo-RGB. - “visible”: ensures correct RGB ↔ BGR conversion.

Parameters:
  • image_input (str, Path, or np.ndarray) – Input image, either as a file path or a NumPy array.

  • mode (str, default="default") – Processing mode. Options: - “swir”: preprocess SWIR images. - “visible”: preprocess visible images. - “default”: no special preprocessing.

Returns:

Preprocessed image in BGR format, dtype=uint8.

Return type:

np.ndarray

Raises:
  • ValueError – If the image cannot be read or has an invalid shape.

  • TypeError – If the input type is unsupported.

fusion.detection_module.run_yolo_and_compute_f1(image, ground_truth_path=None, iou_threshold=0.3, output_dir=None, save_output=False, mode='fusion', image_filename=None)[source]

Run YOLOv8 object detection and compute evaluation metrics (Precision, Recall, F1-score, IoU).

This function loads YOLO configuration from an external JSON file (or creates one with default parameters if missing), performs inference on the input image, compares predictions with ground truth annotations (Pascal VOC format), and computes detection metrics.

Parameters:
  • image (str, Path, or np.ndarray) – Input image, either as a file path or a NumPy array.

  • ground_truth_path (str or Path, optional) – Path to the Pascal VOC XML file containing ground truth annotations.

  • iou_threshold (float, default=0.3) – IoU threshold used to determine true positives.

  • output_dir (str or Path, optional) – Directory where annotated images and XML files will be saved.

  • save_output (bool, default=False) – Whether to save annotated images and XML predictions.

  • mode (str, default="fusion") – Processing mode for image preparation (e.g., “fusion”, “visible”, “swir”).

  • image_filename (str, optional) – Original image filename, used to generate output file names.

Returns:

Dictionary containing detection metrics with the following keys:

  • f1_score (float) – F1-score of the detection.

  • precision (float) – Precision of the detection.

  • recall (float) – Recall of the detection.

  • iou_mean (float) – Mean IoU between predictions and ground truth.

Return type:

dict

Notes

  • YOLO configuration is loaded from config/yolo_config.json. If the file does not exist, it is created with default parameters.

  • Predictions are filtered to include only the allowed classes defined in the configuration.

  • Results can be saved as annotated images and Pascal VOC XML files if save_output=True.

  • Heavy objects (YOLO model, predictions, images) are explicitly deleted to free memory.

fusion.detection_module.save_annotated_float64_image_as_uint16(path, float64_img, vis_img)[source]

Overlay annotations on a float64 image and save the result as uint16.

The function takes a normalized float64 image (values in [0, 1]), overlays annotations from a visualization image, and saves the result as a uint16 image.

Parameters:
  • path (str or Path) – Path where the annotated image will be saved.

  • float64_img (np.ndarray) – Original normalized float64 image (values in [0, 1]).

  • vis_img (np.ndarray) – Visualization image containing annotations.

Raises:

ValueError – If the input image is not a normalized float64 array.

fusion.detection_module.save_predictions_as_voc_xml(result, image_shape, save_path, image_filename)[source]

Save YOLO predictions in Pascal VOC XML format.

Parameters:
  • result (ultralytics.engine.results.Results) – YOLO prediction result object containing bounding boxes and masks.

  • image_shape (tuple of int) – Shape of the image as (height, width, depth).

  • save_path (str or Path) – Path where the XML file will be saved.

  • image_filename (str) – Name of the image file associated with the predictions.

Notes

  • Bounding boxes and class names are extracted from YOLO results.

  • If segmentation masks are available, polygon coordinates are also saved.

  • The output XML follows the Pascal VOC annotation format.

fusion.functions module

Helper functions used across the fusion pipeline.

Direct support functions for VISWIR image processing and manipulation.

fusion.functions.calculate_levels(image)[source]

Dynamically compute the number of pyramid levels.

Parameters:

image (numpy.ndarray) – Input image.

Returns:

Number of pyramid levels.

Return type:

int

fusion.functions.downsample(image, filter=None)[source]

Reduce the resolution of an image by filtering and subsampling.

Parameters:
  • image (numpy.ndarray) – Input image.

  • filter (numpy.ndarray, optional) – Filter to apply before downsampling.

Returns:

Downsampled image.

Return type:

numpy.ndarray

fusion.functions.gaussian_pyramid(image, levels)[source]

Build a Gaussian pyramid from the input image. Use OpenCV.

Parameters:
  • image (numpy.ndarray) – Input image.

  • levels (int) – Number of pyramid levels.

Returns:

List of Gaussian pyramid levels.

Return type:

list of numpy.ndarray

fusion.functions.laplacian_pyramid(image: ndarray[tuple[int, ...], dtype[_ScalarType_co]], levels: int | None = None) list[ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]

Build a Laplacian pyramid with explicit control over filtering and interpolation.

Parameters:
  • image (numpy.ndarray) – Input image.

  • levels (int, optional) – Number of pyramid levels. If None, it is computed automatically based on the smallest image dimension.

Returns:

List of Laplacian pyramid levels.

Return type:

list of numpy.ndarray

fusion.functions.local_std(image, nhood)[source]

Compute the local standard deviation of an image.

Parameters:
  • image (numpy.ndarray) – Input image.

  • nhood (numpy.ndarray) – Neighborhood (window) used for local statistics.

Returns:

Local standard deviation map.

Return type:

numpy.ndarray

fusion.functions.local_visibility(image, size1, sigma1, sigma2)[source]

Compute local visibility of an image.

Parameters:
  • image (numpy.ndarray) – Input image.

  • size1 (int) – Kernel size for Gaussian filtering.

  • sigma1 (float) – Standard deviation for the first Gaussian filter.

  • sigma2 (float) – Standard deviation for the second Gaussian filter.

Returns:

Local visibility map.

Return type:

numpy.ndarray

fusion.functions.my_upsample(image, odd, filter)[source]

Custom upsampling with Gaussian filtering.

Parameters:
  • image (numpy.ndarray) – Input image to upsample.

  • odd (tuple of int) – Adjustment values for odd dimensions.

  • filter (numpy.ndarray) – 1D Gaussian filter.

Returns:

Upsampled and filtered image.

Return type:

numpy.ndarray

fusion.functions.pyramid_filter()[source]

Generate a 1D Gaussian filter for pyramid construction.

Returns:

1D Gaussian filter coefficients.

Return type:

numpy.ndarray

fusion.functions.reconstruct_laplacian_pyramid(pyr)[source]

Reconstruct an image from a Laplacian pyramid.

Parameters:

pyr (list of numpy.ndarray) – Laplacian pyramid (list of images).

Returns:

Reconstructed image.

Return type:

numpy.ndarray

fusion.functions.reconstruct_laplacian_pyramid_2(pyr)[source]

Alternative reconstruction of an image from a Laplacian pyramid.

Parameters:

pyr (list of numpy.ndarray) – Laplacian pyramid.

Returns:

Reconstructed image.

Return type:

numpy.ndarray

fusion.functions.reconstruct_without_laplacian(pyr)[source]

Reconstruct an image from a pyramid without Laplacian levels.

This function performs only upsampling and filtering, without adding Laplacian residuals.

Parameters:

pyr (list of numpy.ndarray) – Pyramid levels.

Returns:

Reconstructed image.

Return type:

numpy.ndarray

Notes

Function used for tests only.

fusion.fusion module

Core fusion algorithms combining visible and SWIR images.

Main fusion functions for VISWIR multi-spectral image fusion.

fusion.fusion.process_image(visible_path, swir_path, facteur_swir, beta, level, apply_gamma, gamma_value, save_output=False, output_dir=None)[source]

Load visible and SWIR images, perform VIS–SWIR fusion, and optionally save results.

Parameters:
  • visible_path (str or Path) – Path to the visible image file.

  • swir_path (str or Path) – Path to the SWIR image file.

  • facteur_swir (float) – Weight factor for the SWIR contribution (between 0 and 1).

  • beta (float) – Exponent applied during inverse mapping to adjust intensity blending.

  • level (int) – Number of pyramid levels used for fusion.

  • apply_gamma (bool) – Whether to apply gamma correction to the fused image.

  • gamma_value (float) – Gamma correction value (used if apply_gamma=True).

  • save_output (bool, default=False) – Whether to save the fused images to disk.

  • output_dir (str or Path, optional) – Directory where results will be saved (if save_output=True).

Returns:

  • I5numpy.ndarray or None

    Intermediate fused image before post-processing.

  • I_outnumpy.ndarray or None

    Final fused image after post-processing.

  • errorstr or None

    Error message if the fusion process fails, otherwise None.

Return type:

tuple

Notes

  • If save_output=True, two images are saved: * *_fused_no_post_processing.tiff * *_fused_with_post_processing.tiff

  • Images are saved as uint16 TIFF files.

  • Returns (None, None, error_message) if an exception occurs.

fusion.fusion.viswir_core_fusion(I1_RGB, I2, facteur_swir, beta, level, apply_gamma, gamma_value)[source]

Perform VIS–SWIR image fusion using Laplacian and Gaussian pyramids.

This function fuses a visible image (VIS) and a SWIR image into a single enhanced image. The fusion process is based on local contrast, entropy, and visibility maps, combined with pyramid decomposition and reconstruction. Post-processing includes gamma correction and Difference of Gaussians (DoG) sharpening.

Parameters:
  • I1_RGB (numpy.ndarray) – Visible image in RGB format, float64 in [0, 1].

  • I2 (numpy.ndarray) – SWIR image, float64 in [0, 1].

  • facteur_swir (float) – Weight factor for the SWIR contribution (between 0 and 1).

  • beta (float) – Exponent applied during inverse mapping to adjust intensity blending.

  • level (int) – Number of pyramid levels used for fusion.

  • apply_gamma (bool) – Whether to apply gamma correction to the fused image.

  • gamma_value (float) – Gamma correction value (used if apply_gamma=True).

Returns:

  • I5numpy.ndarray

    Intermediate fused image before post-processing.

  • I_outnumpy.ndarray

    Final fused image after post-processing (gamma correction, sharpening).

Return type:

tuple of numpy.ndarray

Raises:

ValueError – If weight normalization fails (sum of weights not close to 1).

Notes

  • Local weights are computed from contrast, entropy, and visibility.

  • Fusion is performed in the HSV color space, replacing the V channel.

  • Post-processing enhances sharpness and contrast.

  • Memory is explicitly freed at the end of the function.

fusion.metrics module

Computation of image quality and detection metrics for fused and reference images.

Metrics computation (SSIM, NIQE, etc.) for VISWIR image quality assessment.

fusion.metrics.calculate_brisque(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_correlation(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_entropy(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_entropy_normalized(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_ergas(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_gmsd(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_gmsd_color(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_mad(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_mad_color(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_mean_gradient(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_mean_intensity(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_ms_ssim_pytorch(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_ms_ssim_pytorch_color(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_mse(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_niqe_metric(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_piqe(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_psnr(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_rmse(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_sam(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_snr(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_snr_color(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_snr_color_per_channel(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_spatial_frequency_color(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_spatial_frequency_grey(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_ssim(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_std(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_uqi(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.calculate_vif(*args, **kwargs)[source]

Safe execution wrapper.

fusion.metrics.compute_all_metrics(I_ref=None, I_fused=None)[source]

Compute all registered metrics for a fused image (and optionally a reference image).

Parameters:
  • I_ref (numpy.ndarray, optional) – Reference image (used for full-reference metrics).

  • I_fused (numpy.ndarray) – Fused image.

Returns:

Dictionary mapping metric names to their computed values.

Return type:

dict

Raises:

ValueError – If the fused image is None.

fusion.metrics.register_metric(name, ref_required=False)[source]

Decorator to register a metric function in the appropriate registry.

Parameters:
  • name (str) – Name of the metric.

  • ref_required (bool, default=False) – Whether the metric requires a reference image.

Returns:

Wrapped metric function.

Return type:

function

fusion.metrics.safe(func, name)[source]

Wrap a metric function to ensure safe execution.

Parameters:
  • func (callable) – Metric function to wrap.

  • name (str) – Name of the metric.

Returns:

Wrapped function that returns None if an exception occurs.

Return type:

callable

fusion.utils module

Utility functions for file handling, preprocessing, and pipeline support.

General utility functions, file I/O, and image preparation for the VISWIR project.

fusion.utils.configure_logger(output_dir: str, log_filename: str = 'log.txt') None[source]

Configure the Loguru logger.

  • Writes all logs (DEBUG and above) to a log file.

  • Displays only INFO-level logs and above in the console.

Parameters:
  • output_dir (str) – Directory where the log file will be stored.

  • log_filename (str, default="log.txt") – Name of the log file.

fusion.utils.display_image(title, image)[source]

Display an image using Matplotlib.

Parameters:
  • title (str) – Title of the displayed image.

  • image (numpy.ndarray) – Image to display (grayscale or color).

fusion.utils.ensure_grayscale(img)[source]

Ensure that an image is grayscale.

Parameters:

img (numpy.ndarray) – Input image.

Returns:

Grayscale image.

Return type:

numpy.ndarray

fusion.utils.ensure_range_255(image)[source]

Ensure that an image is in the [0, 255] range.

Parameters:

image (numpy.ndarray) – Input image.

Returns:

Image scaled to [0, 255] if necessary.

Return type:

numpy.ndarray

fusion.utils.from_grey_to_rgb_array(image)[source]

Convert a grayscale image to RGB.

Parameters:

image (numpy.ndarray) – Input image (H, W) or (H, W, 3).

Returns:

RGB image (H, W, 3).

Return type:

numpy.ndarray

Raises:

ValueError – If the image format is unsupported.

fusion.utils.generate_parameters_json(json_path: Path, mode_fixe: bool = False) None[source]

Create a JSON file with default or fixed fusion parameters.

Parameters:
  • json_path (Path) – Path to the JSON file to create or update.

  • mode_fixe (bool, default=False) – If True, generate fixed values. Otherwise, generate exploration ranges.

fusion.utils.generate_parameters_json_return(output_dir: Path) Path[source]

Generate and save a JSON file containing fusion parameters.

Parameters:

output_dir (Path) – Directory where the JSON file will be saved.

Returns:

Path to the generated JSON file.

Return type:

Path

fusion.utils.get_image_shape(image)[source]

Return the shape (H, W, C) of a NumPy image.

Parameters:

image (numpy.ndarray) – Input image.

Returns:

Image shape as (height, width, channels).

Return type:

tuple of int

Raises:
  • TypeError – If the input is not a NumPy array.

  • ValueError – If the image format is unsupported.

fusion.utils.load_image_opencv(path, is_rgb=False, is_swir=False)[source]

Load an image with OpenCV and normalize it according to its data type.

If the image is SWIR, the first channel is extracted if necessary.

Parameters:
  • path (str) – Path to the image file.

  • is_rgb (bool, default=False) – If True, load the image in color (RGB).

  • is_swir (bool, default=False) – If True, apply specific preprocessing for SWIR images.

Returns:

Normalized image as float64 in [0, 1].

Return type:

numpy.ndarray

Raises:

ValueError – If the image cannot be loaded or if the data type is unsupported.

fusion.utils.load_image_ref(path, as_gray=False, normalize=True)[source]

Load a reference image with OpenCV and optionally normalize it.

Parameters:
  • path (str) – Path to the image file.

  • as_gray (bool, default=False) – If True, load the image in grayscale.

  • normalize (bool, default=True) – If True, normalize pixel values to [0, 1].

Returns:

Loaded image as float32.

Return type:

numpy.ndarray

fusion.utils.load_image_ref_skimage(path, as_gray=False, normalize=True)[source]

Load a reference image with skimage and optionally normalize it.

Parameters:
  • path (str) – Path to the image file.

  • as_gray (bool, default=False) – If True, load the image in grayscale.

  • normalize (bool, default=True) – If True, normalize pixel values to [0, 1].

Returns:

Loaded image as float64.

Return type:

numpy.ndarray

fusion.utils.load_image_skimage_core(path, is_swir=False)[source]

Load an image with skimage and normalize it according to its data type.

If the image is SWIR, the first channel is extracted if necessary. A BGR → RGB conversion is applied to correct color ordering.

Parameters:
  • path (str) – Path to the image file.

  • is_swir (bool, default=False) – If True, apply specific preprocessing for SWIR images.

Returns:

Normalized image as float64 in [0, 1].

Return type:

numpy.ndarray

Raises:

ValueError – If the image cannot be loaded or if the data type is unsupported.

fusion.utils.load_parameters_json(json_path: Path) dict[source]

Load and validate fusion parameters from a JSON file.

Parameters:

json_path (Path) – Path to the JSON file.

Returns:

Dictionary of parameters.

Return type:

dict

Raises:

ValueError – If required keys are missing from the JSON file.

fusion.utils.normalize_image(image)[source]

Normalize an image to [0, 1] if necessary.

Parameters:

image (numpy.ndarray) – Input image.

Returns:

Normalized image as float32.

Return type:

numpy.ndarray

fusion.utils.prepare_ground_truth_list(visible_files: List[str], run_detection: bool, ground_truth_path: Path | None, ground_truth_extensions: List[str] = ['*.xml']) List[str | None][source]

Prepare a list of ground truth files aligned with visible images. Supports passing a folder path (auto-scan) or a pre-filtered list of files. :param visible_files: List of visible image file paths. :type visible_files: list of str :param run_detection: Whether detection is enabled. :type run_detection: bool :param ground_truth_path: Path to the ground truth folder, or None if not provided. :type ground_truth_path: Path or None :param ground_truth_extensions: Accepted ground truth file extensions. :type ground_truth_extensions: list of str, default=[”*.xml”]

Returns:

List of ground truth file paths aligned with visible images. If unavailable, returns a list of None values.

Return type:

list of str or None

Raises:

ValueError – If the number of ground truth files does not match the number of visible images.

fusion.utils.prepare_ground_truth_list_vLegacy(visible_files: List[str], run_detection: bool, ground_truth_path: Path | None, ground_truth_extensions: List[str] = ['*.xml']) List[str | None][source]

Legacy version !! Prepare a list of ground truth files aligned with visible images.

Parameters:
  • visible_files (list of str) – List of visible image file paths.

  • run_detection (bool) – Whether detection is enabled.

  • ground_truth_path (Path or None) – Path to the ground truth folder, or None if not provided.

  • ground_truth_extensions (list of str, default=["*.xml"]) – Accepted ground truth file extensions.

Returns:

List of ground truth file paths aligned with visible images. If unavailable, returns a list of None values.

Return type:

list of str or None

Raises:

ValueError – If the number of ground truth files does not match the number of visible images.

fusion.utils.preprocess_images_for_metrics(img1, img2)[source]

Preprocess two images for metric computation.

Ensures both are grayscale and resized to the same shape.

Parameters:
  • img1 (numpy.ndarray) – First image.

  • img2 (numpy.ndarray) – Second image.

Returns:

Preprocessed images (img1, img2).

Return type:

tuple of numpy.ndarray

fusion.utils.print_image_info(image)[source]

Print information about an image.

Displays type, shape, dtype, value range, and color mode.

Parameters:

image (numpy.ndarray) – Input image.

fusion.utils.safe_float(val)[source]

Safely convert a value to float.

Parameters:

val (torch.Tensor, numpy.generic, or float) – Input value.

Returns:

Converted float value.

Return type:

float

fusion.utils.save_float64_image_as_uint16(path, img_float64)[source]

Save a float64 image (normalized [0, 1]) as uint16.

Parameters:
  • path (str or Path) – Path where the image will be saved.

  • img_float64 (numpy.ndarray) – Input image, float64 in [0, 1].

fusion.utils.save_image(filename, image)[source]

Save an image using OpenCV.

The image is saved in the folder intermediate_steps/ as an 8-bit file.

Parameters:
  • filename (str) – Name of the output file.

  • image (numpy.ndarray) – Image to save (float in [0, 1]).

fusion.utils.str_to_bool_strict(s)[source]

Convert a string to a strict boolean value.

Parameters:

s (str) – Input string (“true” or “false”, case-insensitive).

Returns:

Converted boolean value.

Return type:

bool

Raises:

ValueError – If the input string is not “true” or “false”.

fusion.utils.to_float32(img)[source]

Convert an image to float32, normalizing if necessary.

Parameters:

img (numpy.ndarray) – Input image.

Returns:

Image as float32.

Return type:

numpy.ndarray

fusion.utils.to_grayscale_array_OLD(image)[source]

Convert an image to grayscale (legacy version).

Parameters:

image (numpy.ndarray or PIL.Image) – Input image.

Returns:

Grayscale image.

Return type:

numpy.ndarray

fusion.utils.to_grayscale_array_cv2(image)[source]

Convert an image to grayscale using OpenCV.

Parameters:

image (numpy.ndarray) – Input image.

Returns:

Grayscale image.

Return type:

numpy.ndarray

Raises:
  • TypeError – If the input is not a NumPy array.

  • ValueError – If the image format is unsupported.

fusion.utils.to_grayscale_array_manual(image)[source]

Convert an image to grayscale using manual weighted RGB conversion.

Parameters:

image (numpy.ndarray or PIL.Image) – Input image.

Returns:

Grayscale image.

Return type:

numpy.ndarray

fusion.utils.to_grayscale_array_skimage(image)[source]

Convert a color image to grayscale using skimage.

Parameters:

image (numpy.ndarray) – Input image (2D or 3D).

Returns:

Grayscale image.

Return type:

numpy.ndarray

Raises:
  • TypeError – If the input is not a NumPy array.

  • ValueError – If the image format is unsupported.

fusion.utils.to_rgb_array(image)[source]

Convert an input image to an RGB NumPy array.

Parameters:

image (numpy.ndarray or PIL.Image) – Input image.

Returns:

RGB image as a NumPy array.

Return type:

numpy.ndarray

fusion.utils.visualize_pyramid(pyramid, title_prefix='Pyramid Level')[source]

Display each level of a pyramid using Matplotlib.

Parameters:
  • pyramid (list of numpy.ndarray) – List of pyramid levels (images).

  • title_prefix (str, default="Pyramid Level") – Prefix for the displayed titles.

fusion.utils.wait_if_paused(flag_path='pause.flag', sleep_time=5)[source]

Pause execution if a pause flag file exists.

The function checks for the existence of a pause.flag file. If present, execution is paused until the file is removed.

Parameters:
  • flag_path (str, default="pause.flag") – Path to the pause flag file.

  • sleep_time (int, default=5) – Time (in seconds) to wait before checking again.

Module contents

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

fusion package

Modules related to image fusion and quality assessment: - Fusion algorithms - Detection modules - Metrics and utilities