Mosaic
Overview
The mosaic module provides scalable, coordinate-aligned image-merging architectures designed to consolidate multiple discrete satellite imagery tiles into a single georeferenced master mosaic. In regional or country-scale remote sensing, a single satellite pass rarely covers the entire target study area. Analyses instead require combining multiple overlapping image swaths or structural tiles.
This module resolves these spatial divisions by calculating structural bounding extents, establishing unified coordinate spaces, and mapping independent pixel grids into a seamless, unified mosaic tensor. The resulting file preserves full metadata transparency, enabling immediate downstream feature engineering across the expanded study area.
[Input Raster Files Path List]
(e.g., tile_01.tif, tile_02.tif)
│
▼
┌──────────────────────┐
│ MosaicCalculator │
└───────────┬───────────┘
│
▼
┌──────────────────────┐
│ rasterio.merge Core │
└───────────┬───────────┘
│
┌───────────────────────┴───────────────────────┐
▼ ▼
[Spatial Extent Union] [Grid Overlap Resolution]
Calculates absolute geographic bounding box Evaluates pixel decision rule:
via coordinate transform tracking. $output(x, y) = I_{k^*}(x, y)$
│ │
└───────────────┬───────────────┘
│
▼
┌───────────────────────┐
│ File Output Lifecycle │
└───────────┬───────────┘
│
┌────────────────────────┴────────────────────────┐
▼ ▼
[Fully Georeferenced GeoTIFF] [Visual PNG Preview]
Saved to `self._output` for chaining Auto-named via `Mosaic_` + UUIDComprehensive Class Specification: MosaicCalculator
Scientific and Mathematical Objective
The objective of MosaicCalculator is to combine multiple georeferenced raster layers that share a common Coordinate Reference System (CRS) into a single, continuous, spatial data array. This pipeline standardizes structural pixel boundaries across different satellite tracks and scene footprints, eliminating artificial layout boundaries across large-scale geographic regions.
Algorithmic Processing Mechanics and Coordinate Transformations
Mosaicking multi-spectral imagery requires matching different pixel spaces to an identical spatial grid. The module uses rasterio.merge.merge to perform these non-linear coordinate and tensor alignments.
Affine Georeferencing Framework
Every input GeoTIFF file includes a 2D affine transformation matrix that maps internal pixel coordinates (expressed as a row and column ) to continuous real-world map projection coordinates (such as UTM easting and northing ):
Where:
(spatial resolution in the horizontal direction).
(typically negative for standard north-up geographic configurations, where ).
(evaluate to exactly for traditional north-up alignment).
(absolute spatial -coordinate matching the center of the upper-left pixel).
(absolute spatial -coordinate matching the center of the upper-left pixel).
This matrix lets the transformation engine calculate the exact geographic footprint of every pixel in each input image.
Determining Output Bounds and Pixel Grids
The spatial boundaries of the final mosaic are computed by calculating the geographic union of all input image extents. For a collection of input images where each image defines a bounding box , the global bounding parameters for the output mosaic are calculated as:
By default, the pixel resolution and orientation parameters are copied from the first image in the input file list (). The output affine transform matrix is then constructed using these baseline parameters:
This calculation handles upper-left grid corner positioning in compliance with standard GDAL geographic conventions. The final grid dimensions of the output raster (Width , Height ) are calculated as:
Mapping Pixels onto the Output Grid
For each coordinate cell in the destination array, the merging engine projects the pixel's location back into the coordinate space of the source input image. This inverse projection applies the input image's inverse affine matrix () to the output geographic transform coordinates:
If the calculated source coordinate falls within the valid boundaries of the input image, the engine samples the corresponding pixel value (using nearest-neighbor interpolation by default) and writes it to the destination array.
Handling Overlapping Regions
When multiple input images overlap the same geographic area, the module applies a strict priority rule to determine the final pixel value. Because the core merge execution statement does not specify an alternative composition method, it defaults to the "first" strategy.
Overlap Region Profile
┌──────────────────────────────┐
│ Image Tile 1 (Priority Index)│
│ ┌──────────────────────────┼──────────────┐
│ │ Resolved Output Pixel │ │
│ │ Matches Tile 1 Value │ │
└───┼──────────────────────────┘ │
│ Image Tile 2 (Ignored Overlap Overrides)│
└─────────────────────────────────────────┘The engine evaluates input files in the order they appear in the provided file list. For each output pixel location, it selects the value from the first image in the list that contains valid data (non-nodata values) at those coordinates:
Any data from subsequent overlapping layers is ignored at that specific location.
Modifying Metadata Configurations
Once pixel value mapping is complete, the engine updates the metadata dictionary to reflect the properties of the new dataset:
driver: Enforces"GTiff"(GeoTIFF Specification Standard).height,width: Set to the calculated global grid dimensions ().transform: Updates to the newly calculated output affine transform matrix.crs: Copied from the first input image in the file list. All input datasets should share this identical CRS to prevent reprojection errors or alignment offsets during processing.
Interface Specifications
Constructor Method Input Arguments (__init__)
tif_paths(list[str | Path]): A list of absolute file paths to the source GeoTIFF files to be combined.
Core Processing Interface (process())
Executes the
rasterio.merge.mergefunction across the input file list.Extracts and builds the updated spatial metadata dictionary.
Stores the final combined multi-band pixel array in
self.mosaic_mimgand its metadata configurations inself.mosaic_meta.
Custom File Serialization Method (_export_file)
This module overrides the default file export lifecycle. Instead of exporting only a standard display image, it handles two separate outputs:
Fully Georeferenced GeoTIFF: Serializes the complete multi-spectral array to disk, updating its internal header to include the new coordinate reference system and transform parameters.
Visual PNG Preview: Generates a lightweight browse image to support rapid quality control inspections.
Both output files are automatically named using the class prefix Mosaic_ combined with a unique Universally Unique Identifier (UUID).
Return State (execute())
Returns a Path object pointing to the newly written GeoTIFF file location on disk. This file path is stored directly in self._output, allowing it to be passed directly to downstream calculators for chained processing.
Operational Implementation
from pathlib import Path
from fezrs.tools.mosaic import MosaicCalculator
# Define the list of adjacent, overlapping input imagery tiles
target_tiles = [
Path("./tiles/UTM32N_Scene_01.tif"),
Path("./tiles/UTM32N_Scene_02.tif"),
Path("./tiles/UTM32N_Scene_03.tif")
]
# Initialize the spatial merging engine
mosaic_engine = MosaicCalculator(tif_paths=target_tiles)
# Run the mosaicking pipeline and serialize outputs
georeferenced_mosaic_path = mosaic_engine.execute(
output_path="./exports/regional_mosaics/"
)
print(f"Operational master mosaic successfully saved at: {georeferenced_mosaic_path}")Operational Reference: Advanced Overlap Resolution Methods
While the calculator defaults to the "first" pixel selection strategy, alternative merging methods can be passed directly to the underlying rasterio.merge.merge library to handle overlapping areas. The table below profiles these alternative strategies:
| Strategy | Functional Behavior Profile | Use Cases |
|---|---|---|
"first" (Default) | Retains the pixel value from the first image in the file list that contains valid data at those coordinates. | Standard data combination when tiles share a consistent calibration profile. |
"last" | Overwrites previous layers, using the pixel value from the last valid image in the file list. | Updating an existing base map with newer imagery data. |
"min" | Evaluates overlapping pixels across all layers and keeps the lowest value. | Minimizing transient bright anomalies like cloud cover or glint. |
"max" | Evaluates overlapping pixels across all layers and keeps the highest value. | Highlighting maximum surface extents or urban thermal signatures. |
"mean" | Computes the mathematical average value across all valid overlapping pixels. | Smoothing out temporal differences and reducing random sensor noise. |

