From 68b2329e159aed9132309b8cc44ab7d0fd8d3dfb Mon Sep 17 00:00:00 2001 From: David Young Date: Fri, 25 Jun 2021 12:41:41 +0800 Subject: [PATCH] Save DSC of original vs. new labels when merging segmentations - Save to file rather than only printing to console - Use logging --- magmap/atlas/edge_seg.py | 17 ++++++++++++----- magmap/settings/config.py | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/magmap/atlas/edge_seg.py b/magmap/atlas/edge_seg.py index 15222e9db..3bf6a90d7 100644 --- a/magmap/atlas/edge_seg.py +++ b/magmap/atlas/edge_seg.py @@ -15,6 +15,8 @@ from magmap.io import df_io, libmag, sitk_io from magmap.stats import vols +_logger = config.logger.getChild(__name__) + def _mirror_imported_labels(labels_img_np, start, mirror_mult, axis): # mirror labels that have been imported and transformed may have had @@ -355,19 +357,24 @@ def edge_aware_segmentation(path_atlas, show=True, atlas=True, suffix=None, labels_sitk_seg = sitk_io.replace_sitk_with_numpy(labels_sitk, labels_seg) # show DSCs for labels - print("Measuring overlap of individual original and watershed labels:") - atlas_refiner.measure_overlap_labels(labels_sitk, labels_sitk_seg) - print("\nMeasuring overlap of combined original and watershed labels:") - atlas_refiner.measure_overlap_labels( + _logger.info( + "\nMeasuring overlap of individual original and watershed labels:") + dsc_lbls_comb = atlas_refiner.measure_overlap_labels( + labels_sitk, labels_sitk_seg) + _logger.info( + "\nMeasuring overlap of combined original and watershed labels:") + dsc_lbls_indiv = atlas_refiner.measure_overlap_labels( atlas_refiner.make_labels_fg(labels_sitk), atlas_refiner.make_labels_fg(labels_sitk_seg)) - print() + _logger.info("") # measure and save whole atlas metrics metrics = { config.AtlasMetrics.SAMPLE: [os.path.basename(mod_path)], config.AtlasMetrics.REGION: config.REGION_ALL, config.AtlasMetrics.CONDITION: "|".join(cond), + config.AtlasMetrics.DSC_LABELS_ORIG_NEW_COMBINED: dsc_lbls_comb, + config.AtlasMetrics.DSC_LABELS_ORIG_NEW_INDIV: dsc_lbls_indiv, } df_metrics_path = libmag.combine_paths( mod_path, config.PATH_ATLAS_IMPORT_METRICS) diff --git a/magmap/settings/config.py b/magmap/settings/config.py index f45b4b286..13de0e3e8 100644 --- a/magmap/settings/config.py +++ b/magmap/settings/config.py @@ -649,6 +649,8 @@ class AtlasMetrics(Enum): DSC_ATLAS_SAMPLE = "DSC_atlas_sample" DSC_ATLAS_SAMPLE_CUR = "DSC_atlas_sample_curated" DSC_SAMPLE_LABELS = "DSC_sample_labels" + DSC_LABELS_ORIG_NEW_COMBINED = "DSC_labels_orig_new_combined" + DSC_LABELS_ORIG_NEW_INDIV = "DSC_labels_orig_new_individual" SIMILARITY_METRIC = "Similarity_metric" LAT_UNLBL_VOL = "Lateral_unlabeled_volume" LAT_UNLBL_PLANES = "Lateral_unlabeled_planes"