From 2190a5dfa0ee592461a7aa68ae6ce2038e216f00 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sun, 23 Feb 2025 19:45:04 +0000 Subject: [PATCH] Improve PNG ortho creation with non-8bit files --- opendm/orthophoto.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/opendm/orthophoto.py b/opendm/orthophoto.py index 319a504c..acf95870 100644 --- a/opendm/orthophoto.py +++ b/opendm/orthophoto.py @@ -62,14 +62,20 @@ def generate_png(orthophoto_file, output_file=None, outsize=None): bandparam = "-b %s -b %s -b %s -a_nodata 0" % (red, green, blue) except: bandparam = "-b 1 -b 2 -b 3 -a_nodata 0" + + scaleparam = "" + dtype = gtif.GetRasterBand(1) + if dtype != gdal.GDT_Byte: + scaleparam = "-ot Byte -scale" + gtif = None osparam = "" if outsize is not None: osparam = "-outsize %s 0" % outsize - system.run('gdal_translate -of png "%s" "%s" %s %s ' - '--config GDAL_CACHEMAX %s%% ' % (orthophoto_file, output_file, osparam, bandparam, get_max_memory())) + system.run('gdal_translate -of png "%s" "%s" %s %s %s ' + '--config GDAL_CACHEMAX %s%% ' % (orthophoto_file, output_file, osparam, bandparam, scaleparam, get_max_memory())) def generate_kmz(orthophoto_file, output_file=None, outsize=None): if output_file is None: