From a628152d68cf0747b9ecd7181220a1614fb6ceec Mon Sep 17 00:00:00 2001 From: HaleySchuhl Date: Mon, 5 Aug 2024 16:29:55 -0500 Subject: [PATCH] concat a flattened list of unique class labels --- plantcv/annotate/classes.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/plantcv/annotate/classes.py b/plantcv/annotate/classes.py index 60f6004..5711408 100644 --- a/plantcv/annotate/classes.py +++ b/plantcv/annotate/classes.py @@ -286,6 +286,27 @@ def correct_mask(self, bin_img): _debug(visual=final_mask, filename=os.path.join(params.debug_outdir, f"{params.device}_annotation-corrected.png")) + if len(re) > 1: # and count of each label = 1 (count is all "1"s??) + # More than one class label associated with a given object + splitup = [] + # Split on "_" in case something has already been combined + for lbl in re: + list_lbl = lbl[0].split("_") + splitup.append(list_lbl) + + # Flatten list of labels + flat = np.concatenate(splitup) + # Grab each unique label from the list + unique_lbls = np.unique(flat) + # Concat with "_" delimiter + concat_lbl = "_".join(list(unique_lbls)) + # Adding the object + added_obj_labels.append(object_id_count) + analysis_labels.append(concat_lbl) + final_mask = np.where(labeled_mask_all == mask_pixel_value, object_id_count, final_mask) + # Add debug label annotations later + debug_coords.append((x, y)) + debug_labels.append(text) # If there are duplication in labels (e.g. [['total'], ['total']] then add to list) dupes = [x for n, x in enumerate(coord_labels) if x in coord_labels[:n]] # original_index = added_obj_labels.index(mask_pixel_value)