From 2b74a037803050c51995a0f0b08cfb4986fc94ec Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Sat, 20 Apr 2019 10:56:42 -0400 Subject: [PATCH] Exposed SMRF parameters --- opendm/config.py | 40 ++++++++++++++++++++++++++++++++++++---- opendm/dem/commands.py | 4 ++-- opendm/dem/pdal.py | 8 ++++---- scripts/odm_dem.py | 14 ++++++++------ 4 files changed, 50 insertions(+), 16 deletions(-) diff --git a/opendm/config.py b/opendm/config.py index 530b0377..9d03e3fc 100644 --- a/opendm/config.py +++ b/opendm/config.py @@ -226,7 +226,7 @@ def config(): 'and default value: %(default)s')) parser.add_argument('--mesh-point-weight', - metavar='', + metavar='', default=4, type=float, help=('This floating point value specifies the importance' @@ -279,6 +279,38 @@ def config(): '\nDefault: ' '%(default)s') + parser.add_argument('--smrf-scalar', + metavar='', + type=float, + default=1.25, + help='Simple Morphological Filter elevation scalar parameter. ' + '\nDefault: ' + '%(default)s') + + parser.add_argument('--smrf-slope', + metavar='', + type=float, + default=0.15, + help='Simple Morphological Filter slope parameter (rise over run). ' + '\nDefault: ' + '%(default)s') + + parser.add_argument('--smrf-threshold', + metavar='', + type=float, + default=0.5, + help='Simple Morphological Filter elevation threshold parameter (meters). ' + '\nDefault: ' + '%(default)s') + + parser.add_argument('--smrf-window', + metavar='', + type=float, + default=18.0, + help='Simple Morphological Filter window radius parameter (meters). ' + '\nDefault: ' + '%(default)s') + parser.add_argument('--texturing-data-term', metavar='', default='gmi', @@ -359,14 +391,14 @@ def config(): parser.add_argument('--dtm', action='store_true', default=False, - help='Use this tag to build a DTM (Digital Terrain Model, ground only) using a progressive ' - 'morphological filter. Check the --dem* parameters for fine tuning.') + help='Use this tag to build a DTM (Digital Terrain Model, ground only) using a simple ' + 'morphological filter. Check the --dem* and --smrf* parameters for finer tuning.') parser.add_argument('--dsm', action='store_true', default=False, help='Use this tag to build a DSM (Digital Surface Model, ground + objects) using a progressive ' - 'morphological filter. Check the --dem* parameters for fine tuning.') + 'morphological filter. Check the --dem* parameters for finer tuning.') parser.add_argument('--dem-gapfill-steps', metavar='', diff --git a/opendm/dem/commands.py b/opendm/dem/commands.py index bd75df37..dcd77dc8 100644 --- a/opendm/dem/commands.py +++ b/opendm/dem/commands.py @@ -18,11 +18,11 @@ import threading from . import pdal -def classify(lasFile, slope=0.15, cellsize=1, maxWindowSize=18, verbose=False): +def classify(lasFile, scalar, slope, threshold, window, verbose=False): start = datetime.now() try: - pdal.run_pdaltranslate_smrf(lasFile, lasFile, slope, cellsize, maxWindowSize, verbose) + pdal.run_pdaltranslate_smrf(lasFile, lasFile, scalar, slope, threshold, window, verbose) except: raise Exception("Error creating classified file %s" % fout) diff --git a/opendm/dem/pdal.py b/opendm/dem/pdal.py index a59b6b75..164832a3 100644 --- a/opendm/dem/pdal.py +++ b/opendm/dem/pdal.py @@ -163,7 +163,7 @@ def run_pipeline(json, verbose=False): os.remove(jsonfile) -def run_pdaltranslate_smrf(fin, fout, slope, cellsize, maxWindowSize, verbose=False): +def run_pdaltranslate_smrf(fin, fout, scalar, slope, threshold, window, verbose=False): """ Run PDAL translate """ cmd = [ 'pdal', @@ -171,11 +171,11 @@ def run_pdaltranslate_smrf(fin, fout, slope, cellsize, maxWindowSize, verbose=Fa '-i %s' % fin, '-o %s' % fout, 'smrf', - '--filters.smrf.cell=%s' % cellsize, + '--filters.smrf.scalar=%s' % scalar, '--filters.smrf.slope=%s' % slope, + '--filters.smrf.threshold=%s' % threshold, + '--filters.smrf.window=%s' % window, ] - if maxWindowSize is not None: - cmd.append('--filters.smrf.window=%s' % maxWindowSize) if verbose: print ' '.join(cmd) diff --git a/scripts/odm_dem.py b/scripts/odm_dem.py index dc20b7cf..f4b02b6f 100644 --- a/scripts/odm_dem.py +++ b/scripts/odm_dem.py @@ -43,8 +43,6 @@ class ODMDEMCell(ecto.Cell): log.ODM_INFO('Create DTM: ' + str(args.dtm)) log.ODM_INFO('DEM input file {0} found: {1}'.format(tree.odm_georeferencing_model_laz, str(las_model_found))) - slope, cellsize = (0.15, 1) - # define paths and create working directories odm_dem_root = tree.path('odm_dem') if not io.dir_exists(odm_dem_root): @@ -56,15 +54,19 @@ class ODMDEMCell(ecto.Cell): if not io.file_exists(pc_classify_marker) or rerun_cell: log.ODM_INFO("Classifying {} using Simple Morphological Filter".format(tree.odm_georeferencing_model_laz)) commands.classify(tree.odm_georeferencing_model_laz, - slope, - cellsize, + args.smrf_scalar, + args.smrf_slope, + args.smrf_threshold, + args.smrf_window, verbose=args.verbose ) with open(pc_classify_marker, 'w') as f: f.write('Classify: smrf\n') - f.write('Slope: {}\n'.format(slope)) - f.write('Cellsize: {}\n'.format(cellsize)) + f.write('Scalar: {}\n'.format(args.smrf_scalar)) + f.write('Slope: {}\n'.format(args.smrf_slope)) + f.write('Threshold: {}\n'.format(args.smrf_threshold)) + f.write('Window: {}\n'.format(args.smrf_window)) # Do we need to process anything here? if (args.dsm or args.dtm) and las_model_found: