Skip to content

Commit 0080422

Browse files
authored
feat: add flag --merge-skip-blending to skip expensive blending in splitmerge (#1934)
1 parent 72a7fdd commit 0080422

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

contrib/mergepreview/mergepreview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
'BIGTIFF': 'IF_SAFER',
117117
'BLOCKXSIZE': 512,
118118
'BLOCKYSIZE': 512
119-
})
119+
}, args.merge_skip_blending)
120120

121121

122122
log.ODM_INFO("Wrote %s" % output_file)

opendm/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,18 @@ def config(argv=None, parser=None):
828828
'Options: %(choices)s. Default: '
829829
'%(default)s'))
830830

831+
# TODO ideally the blending should be optimised so we don't need this param to skip it, e.g.
832+
# 1. Only blend in a buffer zone around cutline edges (e.g., 100-200 pixels)
833+
# 2. Skip blending for interior regions that are far from edges
834+
# 3. This would require detecting which blocks intersect cutline boundaries
835+
# We have block-based processing already in place in orthophoto.py, so need logic to determine
836+
# if a block needs blending based on its proximity to cutlines
837+
parser.add_argument('--merge-skip-blending',
838+
action=StoreTrue,
839+
nargs=0,
840+
default=False,
841+
help='During the orthophoto merging, skip expensive blending operation: %(default)s')
842+
831843
parser.add_argument('--force-gps',
832844
action=StoreTrue,
833845
nargs=0,

opendm/orthophoto.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def feather_raster(input_raster, output_raster, blend_distance=20):
265265

266266
return output_raster
267267

268-
def merge(input_ortho_and_ortho_cuts, output_orthophoto, orthophoto_vars={}):
268+
def merge(input_ortho_and_ortho_cuts, output_orthophoto, orthophoto_vars={}, merge_skip_blending=False):
269269
"""
270270
Based on https://github.com/mapbox/rio-merge-rgba/
271271
Merge orthophotos around cutlines using a blend buffer.
@@ -334,6 +334,10 @@ def merge(input_ortho_and_ortho_cuts, output_orthophoto, orthophoto_vars={}):
334334
profile["bigtiff"] = orthophoto_vars.get('BIGTIFF', 'IF_SAFER')
335335
profile.update()
336336

337+
# Log here to avoid logging in each block processed
338+
if merge_skip_blending:
339+
log.ODM_INFO("Skipping second and third pass orthophoto blending, as --merge-skip-blending passed")
340+
337341
# create destination file
338342
with rasterio.open(output_orthophoto, "w", **profile) as dstrast:
339343
dstrast.colorinterp = colorinterp
@@ -372,6 +376,11 @@ def merge(input_ortho_and_ortho_cuts, output_orthophoto, orthophoto_vars={}):
372376
if np.count_nonzero(dstarr[-1]) == blocksize:
373377
break
374378

379+
# Skip expensive blending operations if flag passed
380+
if merge_skip_blending:
381+
dstrast.write(dstarr, window=dst_window)
382+
continue
383+
375384
# Second pass, write all feathered rasters
376385
# blending the edges
377386
for src, _ in sources:

stages/splitmerge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def process(self, args, outputs):
262262
os.remove(tree.odm_orthophoto_tif)
263263

264264
orthophoto_vars = orthophoto.get_orthophoto_vars(args)
265-
orthophoto.merge(all_orthos_and_ortho_cuts, tree.odm_orthophoto_tif, orthophoto_vars)
265+
orthophoto.merge(all_orthos_and_ortho_cuts, tree.odm_orthophoto_tif, orthophoto_vars, args.merge_skip_blending)
266266
orthophoto.post_orthophoto_steps(args, merged_bounds_file, tree.odm_orthophoto_tif, tree.orthophoto_tiles, args.orthophoto_resolution,
267267
reconstruction, tree, False)
268268
elif len(all_orthos_and_ortho_cuts) == 1:

0 commit comments

Comments
 (0)