From 96d09996e3d35bf90add127ec56763275a610b4f Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 8 Jun 2019 19:28:58 -0400 Subject: [PATCH] Skip DSM smoothing in 2.5D model with fast-orthophoto --- opendm/dem/commands.py | 18 +++++++++++------- opendm/mesh.py | 5 +++-- stages/odm_meshing.py | 3 ++- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/opendm/dem/commands.py b/opendm/dem/commands.py index 2b00850f..4eb12a52 100644 --- a/opendm/dem/commands.py +++ b/opendm/dem/commands.py @@ -35,7 +35,8 @@ error = None def create_dem(input_point_cloud, dem_type, output_type='max', radiuses=['0.56'], gapfill=True, outdir='', resolution=0.1, max_workers=1, max_tile_size=2048, - verbose=False, decimation=None, keep_unfilled_copy=False): + verbose=False, decimation=None, keep_unfilled_copy=False, + apply_smoothing=True): """ Create DEM from multiple radii, and optionally gapfill """ global error error = None @@ -238,9 +239,12 @@ def create_dem(input_point_cloud, dem_type, output_type='max', radiuses=['0.56'] '-co NUM_THREADS={threads} ' '--config GDAL_CACHEMAX {max_memory}% ' '{tiles_vrt} {geotiff}'.format(**kwargs)) - - post_process(geotiff_path, output_path) - os.remove(geotiff_path) + + if apply_smoothing: + median_smoothing(geotiff_path, output_path) + os.remove(geotiff_path) + else: + os.rename(geotiff_path, output_path) if os.path.exists(geotiff_tmp_path): if not keep_unfilled_copy: @@ -278,14 +282,14 @@ def compute_euclidean_map(geotiff_path, output_path, overwrite=False): return output_path -def post_process(geotiff_path, output_path, smoothing_iterations=1): +def median_smoothing(geotiff_path, output_path, smoothing_iterations=1): """ Apply median smoothing """ start = datetime.now() if not os.path.exists(geotiff_path): raise Exception('File %s does not exist!' % geotiff_path) - log.ODM_INFO('Starting post processing (smoothing)...') + log.ODM_INFO('Starting smoothing...') with rasterio.open(geotiff_path) as img: nodata = img.nodatavals[0] @@ -324,6 +328,6 @@ def post_process(geotiff_path, output_path, smoothing_iterations=1): else: imgout.write(arr.astype(dtype), 1) - log.ODM_INFO('Completed post processing to create %s in %s' % (os.path.relpath(output_path), datetime.now() - start)) + log.ODM_INFO('Completed smoothing to create %s in %s' % (os.path.relpath(output_path), datetime.now() - start)) return output_path \ No newline at end of file diff --git a/opendm/mesh.py b/opendm/mesh.py index cd4b60cd..3f53e9dd 100644 --- a/opendm/mesh.py +++ b/opendm/mesh.py @@ -7,7 +7,7 @@ from opendm import context from scipy import signal, ndimage import numpy as np -def create_25dmesh(inPointCloud, outMesh, dsm_radius=0.07, dsm_resolution=0.05, depth=8, samples=1, maxVertexCount=100000, verbose=False, available_cores=None, method='gridded'): +def create_25dmesh(inPointCloud, outMesh, dsm_radius=0.07, dsm_resolution=0.05, depth=8, samples=1, maxVertexCount=100000, verbose=False, available_cores=None, method='gridded', smooth_dsm=True): # Create DSM from point cloud # Create temporary directory @@ -31,7 +31,8 @@ def create_25dmesh(inPointCloud, outMesh, dsm_radius=0.07, dsm_resolution=0.05, outdir=tmp_directory, resolution=dsm_resolution, verbose=verbose, - max_workers=available_cores + max_workers=available_cores, + apply_smoothing=smooth_dsm ) if method == 'gridded': diff --git a/stages/odm_meshing.py b/stages/odm_meshing.py index ed765375..da0c2091 100644 --- a/stages/odm_meshing.py +++ b/stages/odm_meshing.py @@ -68,7 +68,8 @@ class ODMeshingStage(types.ODM_Stage): samples=self.params.get('samples'), verbose=self.params.get('verbose'), available_cores=args.max_concurrency, - method='poisson' if args.fast_orthophoto else 'gridded') + method='poisson' if args.fast_orthophoto else 'gridded', + smooth_dsm=not args.fast_orthophoto) else: log.ODM_WARNING('Found a valid ODM 2.5D Mesh file in: %s' % tree.odm_25dmesh)