Skip to content

Commit a86c01f

Browse files
committed
feat: duplicate mask removal
1 parent 52d566a commit a86c01f

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

decimer_segmentation/complete_structure.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,31 @@ def complete_structure_mask(
324324
image_repeat,
325325
exclusion_repeat,
326326
)
327-
# Stack mask arrays to give the desired output format
327+
# Filter duplicates and stack mask arrays to give the desired output format
328+
expanded_split_mask_arrays = filter_duplicate_masks(expanded_split_mask_arrays)
328329
mask_array = np.stack(expanded_split_mask_arrays, -1)
329330
return mask_array
330331
else:
331332
print("No masks found.")
332333
return mask_array
334+
335+
336+
def filter_duplicate_masks(array_list: List[np.array]) -> List[np.array]:
337+
"""
338+
This function takes a list of arrays and returns a list of unique arrays.
339+
340+
Args:
341+
array_list (List[np.array]): Masks
342+
343+
Returns:
344+
List[np.array]: Unique masks
345+
"""
346+
seen = set()
347+
unique_list = []
348+
for arr in array_list:
349+
# Convert the array to a hashable tuple
350+
arr_tuple = tuple(arr.ravel())
351+
if arr_tuple not in seen:
352+
seen.add(arr_tuple)
353+
unique_list.append(arr)
354+
return unique_list

0 commit comments

Comments
 (0)