[gdal-dev] Help with band pixel functions

Adriana Parra adrianaparra at nevada.unr.edu
Mon Jun 24 19:38:41 PDT 2019


I have been trying to mosaic two images that partially overlap using band
pixel functions in Python. My images contain unsigned integers (uint8) and
the no data value is 255. I considered using the nanmean function so that I
would get average values in overlapping areas of the two images and
maintain the original value of the non-overlapping areas, but for some
reason the NAN values are being interpreted as zero, resulting in half of
the original value in non-overlapping areas.  I would really appreciate any
feedback. I am using GDAL 3.1.0 and python 3.6. Bellow is the code I used
and I am sending attached the input files.
gdalbuildvrt  mosaic1.vrt -input_file_list  input_files.txt -srcnodata "255"

 import numpy as np
def average(in_ar, out_ar, xoff, yoff, xsize, ysize,
raster_xsize,raster_ysize, buf_radius, gt, **kwargs):
    np.round_(np.clip(np.nanmean(in_ar, axis = 0, dtype = 'uint8'),0,255),
              out = out_ar)

gdal_translate --config GDAL_VRT_ENABLE_PYTHON YES mosaic1.vrt mosaic1.tif

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20190624/e4e3d50e/attachment.html>

More information about the gdal-dev mailing list