diff --git a/moringa.py b/moringa.py index 840250ff03f0cdfb52a91cb5a1aba1f7b774ab0f..f297185e99d2272e46458a4ebd8cde05ad7f1066 100755 --- a/moringa.py +++ b/moringa.py @@ -7,11 +7,14 @@ from TimeSeries import s2theia, s2planetary def run_segmentation(img, threshold, cw, sw , out_seg, 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)): os.makedirs(os.path.dirname(out_seg)) 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 def preprocess_spot67(in_fld, out_fld, dem_fld, geoid_file, skip_ps, compress, @@ -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("--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("--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("--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("--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("--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): if arg.cmd == "segment": 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": preprocess_spot67(arg.fld, arg.out_fld, arg.dem_fld, arg.geoid, arg.skip_ps, arg.compress,