From 0013a97f78befa52ec7ada6bb163bf6a51ee4a35 Mon Sep 17 00:00:00 2001 From: SVivdich02 Date: Tue, 5 Mar 2024 22:26:09 +0300 Subject: [PATCH] fix comments --- .../preprocessing/init/instances_matrix.py | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/services/preprocessing/init/instances_matrix.py b/src/services/preprocessing/init/instances_matrix.py index 93283c4..2376093 100644 --- a/src/services/preprocessing/init/instances_matrix.py +++ b/src/services/preprocessing/init/instances_matrix.py @@ -116,7 +116,12 @@ def masks_to_image(self, masks): image_labels[mask["segmentation"]] = i + 1 return image_labels - def reduce_detail(self, masks, intersection_to_union_threshold=0.35, intersection_to_mask_threshold=0.6): + def reduce_detail( + self, + masks, + int_to_union_threshold=0.35, + int_to_mask_threshold=0.6, + ): """Reducing the detail of masks by combining several masks into one Parameters @@ -130,11 +135,11 @@ def reduce_detail(self, masks, intersection_to_union_threshold=0.35, intersectio "area" : int the area in pixels of the mask - intersection_to_union_threshold : float + int_to_union_threshold : float two masks whose ratio of the intersection area of the bounding boxes to the union area is greater than or equal this threshold will be merged into one mask - intersection_to_mask_threshold : float + int_to_mask_threshold : float threshold for the ratio of the number of pixels in the intersection of masks to the number of pixels in one mask for example, if half the pixels of a mask belong to the intersection @@ -142,7 +147,7 @@ def reduce_detail(self, masks, intersection_to_union_threshold=0.35, intersectio """ merged_mask = [] - merged_indices = [] #indices in the original masks that were merged + merged_indices = [] # indices in the original masks that were merged for i in range(len(masks)): if i in merged_indices: @@ -167,15 +172,16 @@ def reduce_detail(self, masks, intersection_to_union_threshold=0.35, intersectio IU_ratio = area_bbox_intersection / area_bbox_union if ( - IU_ratio >= intersection_to_union_threshold - or area_intersection / masks[i]["area"] >= intersection_to_mask_threshold - or area_intersection / masks[j]["area"] >= intersection_to_mask_threshold + IU_ratio >= int_to_union_threshold + or area_intersection / masks[i]["area"] >= int_to_mask_threshold + or area_intersection / masks[j]["area"] >= int_to_mask_threshold ): - masks[i] = find_union_mask(masks[i], masks[j]) #the union is placed in the masks[i] + masks[i] = find_union_mask(masks[i], masks[j]) indices_merged_with_i.append(j) if indices_merged_with_i: - merged_mask.append(masks[i]) #the final result of the union is extracted from the masks[i] + # the final result of the union is extracted from the masks[i] + merged_mask.append(masks[i]) merged_indices.append(i) for ind in indices_merged_with_i: @@ -184,7 +190,7 @@ def reduce_detail(self, masks, intersection_to_union_threshold=0.35, intersectio masks_result = [] for ind, mask in enumerate(masks): if ind not in merged_indices: - masks_result.append(mask) #save it unchanged + masks_result.append(mask) # save it unchanged for mask in merged_mask: masks_result.append(mask)