From e9afa236c0d1e7d92b4a16b24c51c6d03c1b6f71 Mon Sep 17 00:00:00 2001 From: Miquel Espinosa Date: Thu, 20 Jun 2024 09:28:38 +0100 Subject: [PATCH] Fix bug binary_mask_to_polygon when multiple contours of disjoint areas are found Fix a small bug inside the funciton binary_mask_to_polygon in pycocoreatortools.py The bug happened when multiple contours of disjoint areas were found. We cannot do np.subtract on multiple arrays of different sizes. --- pycococreatortools/pycococreatortools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pycococreatortools/pycococreatortools.py b/pycococreatortools/pycococreatortools.py index aa6515c..ded5459 100755 --- a/pycococreatortools/pycococreatortools.py +++ b/pycococreatortools/pycococreatortools.py @@ -45,8 +45,9 @@ def binary_mask_to_polygon(binary_mask, tolerance=0): # pad mask to close contours of shapes which start and end at an edge padded_binary_mask = np.pad(binary_mask, pad_width=1, mode='constant', constant_values=0) contours = measure.find_contours(padded_binary_mask, 0.5) - contours = np.subtract(contours, 1) + for contour in contours: + contour = np.subtract(contour, 1) contour = close_contour(contour) contour = measure.approximate_polygon(contour, tolerance) if len(contour) < 3: