From 1aaf8ebb47760af376ac91fb9021f25dc9a9e1a3 Mon Sep 17 00:00:00 2001
From: Constantin Pape <constantin.pape@iwr.uni-heidelberg.de>
Date: Thu, 3 Oct 2019 09:48:54 +0200
Subject: [PATCH] Fix issues in region attributes

---
 scripts/attributes/region_attributes.py | 17 ++++++-----------
 scripts/attributes/util.py              |  3 +--
 update_patch.py                         |  1 +
 3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/scripts/attributes/region_attributes.py b/scripts/attributes/region_attributes.py
index 2965797..b5f6916 100644
--- a/scripts/attributes/region_attributes.py
+++ b/scripts/attributes/region_attributes.py
@@ -11,7 +11,6 @@ def write_region_table(label_ids, label_list, semantic_mapping_list, out_path):
     assert len(label_list) == len(semantic_mapping_list)
     n_labels = len(label_ids)
     assert all(len(labels) == n_labels for labels in label_list)
-
     col_names = ['label_id'] + [name for mapping in semantic_mapping_list
                                 for name in mapping.keys()]
     n_cols = len(col_names)
@@ -49,16 +48,13 @@ def muscle_attributes(muscle_path, key_muscle,
     # we count everything that has at least 25 % overlap as muscle
     overlap_threshold = .25
     muscle_labels = normalize_overlap_dict(muscle_labels)
-    label_ids = [k for k in sorted(muscle_labels.keys())]
-    muscle_labels = np.array([foreground_id if muscle_labels[label_id].get(foreground_id, 0) > overlap_threshold
-                              else 0 for label_id in label_ids])
+    label_ids = np.array([k for k in sorted(muscle_labels.keys())])
+    overlap_values = np.array([muscle_labels[label_id].get(foreground_id, 0.) for label_id in label_ids])
+    overlap_labels = label_ids[overlap_values > overlap_threshold]
 
-    # print()
-    # print()
-    # print(np.sum(muscle_labels == foreground_id))
-    # print(muscle_labels.size)
-    # print()
-    # print()
+    n_labels = int(label_ids.max()) + 1
+    muscle_labels = np.zeros(n_labels, dtype='uint8')
+    muscle_labels[overlap_labels] = foreground_id
 
     semantic_muscle = {'muscle': [foreground_id]}
     return muscle_labels, semantic_muscle
@@ -86,7 +82,6 @@ def region_attributes(seg_path, region_out,
         ids = f['semantic_mapping'][:]
     semantics_to_carved_ids = {name: idx.tolist()
                                for name, idx in zip(names, ids)}
-
     label_list = [carved_labels]
     semantic_mapping_list = [semantics_to_carved_ids]
 
diff --git a/scripts/attributes/util.py b/scripts/attributes/util.py
index 70024b9..c34cf32 100644
--- a/scripts/attributes/util.py
+++ b/scripts/attributes/util.py
@@ -53,8 +53,7 @@ def node_labels(seg_path, seg_key,
         data = ds_out[:]
     else:
         n_chunks = ds_out.number_of_chunks
-        out_path = ds_out.path
-        data = [ndist.deserializeOverlapChunk(out_path, (chunk_id,))[0]
+        data = [ndist.deserializeOverlapChunk(out_path, out_key, (chunk_id,))[0]
                 for chunk_id in range(n_chunks)]
         data = {label_id: overlaps
                 for chunk_data in data
diff --git a/update_patch.py b/update_patch.py
index 5340967..23716e9 100755
--- a/update_patch.py
+++ b/update_patch.py
@@ -155,6 +155,7 @@ def update_patch(update_seg_names, update_table_names,
     update_tables(folder, new_folder, table_updates,
                   target=target, max_jobs=max_jobs)
 
+    print("All updates were successfull. Making bdv file and adding version tag")
     make_bdv_server_file(new_folder, os.path.join(new_folder, 'misc', 'bdv_server.txt'),
                          relative_paths=True)
     add_version(new_tag)
-- 
GitLab