Skip to content

Commit

Permalink
Save DSC of original vs. new labels when merging segmentations
Browse files Browse the repository at this point in the history
- Save to file rather than only printing to console
- Use logging
  • Loading branch information
yoda-vid committed Jun 29, 2021
1 parent 45aa13d commit 68b2329
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions magmap/atlas/edge_seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions magmap/settings/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 68b2329

Please sign in to comment.