Commit cf4fe95d authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

ENH: added option for using light lsgrm.

parent 9626c074
No related merge requests found
Showing with 8 additions and 4 deletions
+8 -4
...@@ -7,11 +7,14 @@ from TimeSeries import s2theia, s2planetary ...@@ -7,11 +7,14 @@ from TimeSeries import s2theia, s2planetary
def run_segmentation(img, threshold, cw, sw , out_seg, def run_segmentation(img, threshold, cw, sw , out_seg,
n_first_iter, margin, roi, n_proc, memory, n_first_iter, margin, roi, n_proc, memory,
remove_graph, force_parallel): remove_graph, force_parallel, light):
if not os.path.exists(os.path.dirname(out_seg)): if not os.path.exists(os.path.dirname(out_seg)):
os.makedirs(os.path.dirname(out_seg)) os.makedirs(os.path.dirname(out_seg))
params = OBIA.segmentation.LSGRMParams(threshold, cw, sw, n_first_iter, margin) params = OBIA.segmentation.LSGRMParams(threshold, cw, sw, n_first_iter, margin)
OBIA.segmentation.lsgrm(img, params, out_seg, n_proc, memory, roi, remove_graph, force_parallel) if light:
OBIA.segmentation.lsgrm_light(img, params, out_seg, n_proc, memory, roi, force_parallel)
else:
OBIA.segmentation.lsgrm(img, params, out_seg, n_proc, memory, roi, remove_graph, force_parallel)
return return
def preprocess_spot67(in_fld, out_fld, dem_fld, geoid_file, skip_ps, compress, def preprocess_spot67(in_fld, out_fld, dem_fld, geoid_file, skip_ps, compress,
...@@ -72,11 +75,12 @@ def main(args): ...@@ -72,11 +75,12 @@ def main(args):
segmt.add_argument("outimg", type=str, help="Path to the output segmentation file (.tif, .shp, .gpkg, .gml).") segmt.add_argument("outimg", type=str, help="Path to the output segmentation file (.tif, .shp, .gpkg, .gml).")
segmt.add_argument("--cw", type=float, default=0.5, help="Color weight in Baatz-Shape criterion.") segmt.add_argument("--cw", type=float, default=0.5, help="Color weight in Baatz-Shape criterion.")
segmt.add_argument("--sw", type=float, default=0.5, help="Spatial weight in Baatz-Shape criterion.") segmt.add_argument("--sw", type=float, default=0.5, help="Spatial weight in Baatz-Shape criterion.")
segmt.add_argument("--n_first_iter", type=int, default=12, help="Number of iterations for parallel tile processing.") segmt.add_argument("--n_first_iter", type=int, default=12, help="Number of iterations for parallel tile processing (no use in light mode).")
segmt.add_argument("--tile_margin", type=int, default=100, help="Margin for tile overlap.") segmt.add_argument("--tile_margin", type=int, default=100, help="Margin for tile overlap.")
segmt.add_argument("--roi", type=str, default=None, help="Vector file containing an ROI.") segmt.add_argument("--roi", type=str, default=None, help="Vector file containing an ROI.")
segmt.add_argument("--n_proc", type=int, help="Number of cores to use.") segmt.add_argument("--n_proc", type=int, help="Number of cores to use.")
segmt.add_argument("--mem_limit", type=int, help="Memory limit in MB.") segmt.add_argument("--mem_limit", type=int, help="Memory limit in MB.")
segmt.add_argument("--use_light_alg", help="Use the sub-obtimal version of the algorithm. Faster but may have artefacts.", action='store_true')
segmt.add_argument("--keep_graph", help="Keep the graph files (.bin) after segmentation.", action='store_true') segmt.add_argument("--keep_graph", help="Keep the graph files (.bin) after segmentation.", action='store_true')
segmt.add_argument("--force_parallel", help="Force the spot6/7 preprocess one-liner parallelization of the process even if the full graph fits in memory.", action='store_true') segmt.add_argument("--force_parallel", help="Force the spot6/7 preprocess one-liner parallelization of the process even if the full graph fits in memory.", action='store_true')
...@@ -107,7 +111,7 @@ def main(args): ...@@ -107,7 +111,7 @@ def main(args):
if arg.cmd == "segment": if arg.cmd == "segment":
run_segmentation(arg.img, arg.threshold, arg.cw, arg.sw, arg.outimg, arg.n_first_iter, arg.tile_margin, run_segmentation(arg.img, arg.threshold, arg.cw, arg.sw, arg.outimg, arg.n_first_iter, arg.tile_margin,
arg.roi, arg.n_proc, arg.mem_limit, not arg.keep_graph, arg.force_parallel) arg.roi, arg.n_proc, arg.mem_limit, not arg.keep_graph, arg.force_parallel, arg.use_light_alg)
if arg.cmd == "preprocess_spot67": if arg.cmd == "preprocess_spot67":
preprocess_spot67(arg.fld, arg.out_fld, arg.dem_fld, arg.geoid, arg.skip_ps, arg.compress, preprocess_spot67(arg.fld, arg.out_fld, arg.dem_fld, arg.geoid, arg.skip_ps, arg.compress,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment