I have a list of GeoTIFF images. I would like to merge these images together.
However, as my understanding, it will take in turn the file and at overlapping pixels will receive the values from the later files.
What do I need? I need the overlapping pixels to receive average values from all inputs.
Any solution to solve it, even with other packages such as GDAL or rioxarray?
import rasterio
from rasterio.merge import merge
input_files = ['img1.tif', 'img2.tif', 'img3.tif']
output_file = "merged.tif"
src_files_to_mosaic = []
for file in input_files:
src = rasterio.open(file)
src_files_to_mosaic.append(src)
mosaic, out_trans = merge(src_files_to_mosaic)
out_meta = src.meta.copy()
out_meta.update({"driver": "GTiff",
"height": mosaic.shape[1],
"width": mosaic.shape[2],
"transform": out_trans})
with rasterio.open(output_file, "w", **out_meta) as dest:
dest.write(mosaic)