Skip to main content

Global and local spectral matching of 2 or more overlapping rasters

Project description

spectralmatch: relative radiometric normalization toolkit for raster mosaics and time series

PyPI version QGIS Plugin Your-License-Badge codecov Open in Cloud Shell 📋 Copy LLM Prompt DOI

Overview

Global and Local Matching

Spectralmatch provides algorithms to perform relative radiometric normalization (RRN) to enhance spectral consistency across raster mosaics and time series. It is built for geoscientific use, with a sensor- and unit-agnostic design, optimized for automation and efficiency on arbitrarily many images and bands, and works well with Very High Resolution Imagery (VHRI) as it does not require pixel co-registration. In addition to matching algorithms, the software supports cloud and vegetation masking, pseudo invariant feature (PIF) based exclusion, seamline network generation, raster merging, and plotting statistics. The toolkit is available as an open-source Python library, command line interface, and QGIS plugin.

Please cite as: Lindiwe, K., Percival, J. E. H., & Perroy, R. (2025). spectralmatch. Zenodo. https://doi.org/10.5281/zenodo.15312878

Features

  • Automated, Efficient, and Scalable: Designed for large-scale workflows with no manual steps, leveraging multiprocessing and Cloud Optimized GeoTIFF support for fast, efficient processing across images, windows, and bands.

  • Resumable Processing: Save image stats and block maps for quicker reprocessing.

  • Integrated Seamline and Cloud Masking: Generate seamlines and detect clouds within the same workflow.

  • Specify Model Images Include all or specified images in the matching solution to bring all images to a central tendency or selected images spectral profile.

  • Consistent Multi-image Analysis: Performs minimal necessary adjustments to achieve inter-image consistency while preserving the original spectral characteristics.

  • Sensor and Unit Agnostic: Supports optical imagery from handheld cameras, drones, crewed aircraft, and satellites for reliable single sensor and multi-sensor analysis, while preserving spectral integrity across all pixel units—including negative values and reflectance.

  • Enhanced Imagery: Helpful when performing mosaics and time series analysis by blending large image collections and normalizing them over time, providing consistent, high-quality data for machine learning and other analytical tasks.

  • Open Source and Collaborative: Free under the MIT License with a modular design that supports community contributions and easy development of new features and workflows. Accessible through a python library, command line interface, and QGIS plugin.


Current Matching Algorithms

Global to local matching

This technique is derived from 'An auto-adapting global-to-local color balancing method for optical imagery mosaic' by Yu et al., 2017 (DOI: 10.1016/j.isprsjprs.2017.08.002). It is particularly useful for very high-resolution imagery (satellite or otherwise) and works in a two phase process. First, this method applies least squares regression to estimate scale and offset parameters that align the histograms of all images toward a shared spectral center. This is achieved by constructing a global model based on the overlapping areas of adjacent images, where the spectral relationships are defined. This global model ensures that each image conforms to a consistent radiometric baseline while preserving overall color fidelity. However, global correction alone cannot capture intra-image variability so a second local adjustment phase is performed. The overlap areas are divided into smaller blocks, and each block’s mean is used to fine-tune the color correction. This block-wise tuning helps maintain local contrast and reduces visible seams, resulting in seamless and spectrally consistent mosaics with minimal distortion.

Histogram matching graph Comparison of three WorldView-3 images from Puʻu Waʻawaʻa, Hawaiʻi before and after processing with global regression and local block adjustment using spectralmatch. The top left shows images before processing, the middle left shows images after process, the bottom left shows images mosaiced before and after processing, and lastly, the right shows the spectral profile of all images.

Assumptions

  • Consistent Spectral Profile: The true spectral response of overlapping areas remains the same throughout the images.

  • Least Squares Modeling: A least squares approach can effectively model and fit all images' spectral profiles.

  • Scale and Offset Adjustment: Applying scale and offset corrections can effectively harmonize images.

  • Minimized Color Differences: The best color correction is achieved when color differences are minimized.

  • Geometric Alignment: Images are assumed to be geometrically aligned with known relative positions via a geotransform. However, they only need to be roughly aligned as pixel co-registration is not required.

  • Global Consistency: Overlapping color differences are consistent across the entire image.

  • Local Adjustments: Block-level color differences result from the global application of adjustments.


Installation

For additional installation instructions see the Installation Methods in the docs.

Installation as a QGIS Plugin

In the QGIS plugin manager, install 'spectralmatch' and find it in the Processing Toolbox.

Installation as a Python Library and CLI

Ensure you have the following system-level prerequisites: Python ≥ 3.10 and ≤ 3.12, pip, PROJ ≥ 9.3, and GDAL ≥ 3.10.2; then use pip to install the library:

conda create -n spectralmatch python=3.12 "gdal>=3.10.2" "proj>=9.3" -c conda-forge
conda activate spectralmatch
pip install spectralmatch

Usage

Example scripts and sample data are provided to verify a successful installation and help you get started quickly in the repository at /docs/examples and downloadable here.

This is an example mosaic workflow using folders for each step:

import os
from spectralmatch import *

working_directory = "/path/to/working/directory"
input_folder = os.path.join(working_directory, "Input")
global_folder = os.path.join(working_directory, "GlobalMatch")
local_folder = os.path.join(working_directory, "LocalMatch")
aligned_folder = os.path.join(working_directory, "Aligned")
clipped_folder = os.path.join(working_directory, "Clipped")

global_regression(
    input_images=input_folder,
    output_images=global_folder,
)

local_block_adjustment(
    input_images=global_folder,
    output_images=local_folder,
)

align_rasters(
    input_images=local_folder,
    output_images=aligned_folder,
    tap=True,
)

voronoi_center_seamline(
    input_images=aligned_folder,
    output_mask=os.path.join(working_directory, "ImageMasks.gpkg"),
    image_field_name="image",
)

mask_rasters(
    input_images=aligned_folder,
    output_images=clipped_folder,
    vector_mask=("include", os.path.join(working_directory, "ImageMasks.gpkg"), "image"),
)

merge_rasters(
    input_images=clipped_folder,
    output_image_path=os.path.join(working_directory, "MergedImage.tif"),
)

Documentation

Documentation is available at spectralmatch.github.io/spectralmatch/.


Contributing Guide

Contributing Guide is available at spectralmatch.github.io/spectralmatch/contributing.


License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spectralmatch-1.0.4.tar.gz (71.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spectralmatch-1.0.4-py3-none-any.whl (68.7 kB view details)

Uploaded Python 3

File details

Details for the file spectralmatch-1.0.4.tar.gz.

File metadata

  • Download URL: spectralmatch-1.0.4.tar.gz
  • Upload date:
  • Size: 71.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spectralmatch-1.0.4.tar.gz
Algorithm Hash digest
SHA256 8b3f6d48f048bcfd4aaba42c44577b7e00eb1902ab1d346afd28f638e01fd046
MD5 ecffe01528b8912740e647681347c07a
BLAKE2b-256 bbe21170c20eb7b2ab1c49970dc8063024941e789693a55120de6ec2e7a57b5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for spectralmatch-1.0.4.tar.gz:

Publisher: publish.yml on spectralmatch/spectralmatch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spectralmatch-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: spectralmatch-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 68.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spectralmatch-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a80e5a8e4c490dfee40b4b68fcedb970a4276252604ad7e3afc9329cec299aa7
MD5 9101ca052400d77b2212fb075d8f52d6
BLAKE2b-256 bc3b284d43e83573741b09a36d467b8b7ca732ca372464490c4ec40db2709312

See more details on using hashes here.

Provenance

The following attestation bundles were made for spectralmatch-1.0.4-py3-none-any.whl:

Publisher: publish.yml on spectralmatch/spectralmatch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page