Skip to content

Commit 5bb255b

Browse files
authored
🐛 Fix Contours with Holes (#956)
Fix a bug in `dict_to_store_semantic_segmentor` where it fails to handle holes properly. The problem was, that the code was not associating the holes with the correct parent contour.
1 parent 3fa051f commit 5bb255b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tiatoolbox/utils/misc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ def process_contours(
12251225
12261226
"""
12271227
annotations_list: list[Annotation] = []
1228-
outer_contours: list[np.ndarray] = []
1228+
outer_contours: dict[int, np.ndarray] = {}
12291229
holes_dict: dict[int, list[np.ndarray]] = {}
12301230

12311231
for i, layer_ in enumerate(contours):
@@ -1235,7 +1235,7 @@ def process_contours(
12351235
# save one points as a line, otherwise save the Polygon
12361236
if len(layer_) > 2: # noqa: PLR2004
12371237
if int(hierarchy[0][i][3]) == -1: # Outer contour
1238-
outer_contours.append(scaled_coords[0])
1238+
outer_contours[i] = scaled_coords[0]
12391239
else: # Hole
12401240
parent_idx: int = int(hierarchy[0][i][3])
12411241
if parent_idx not in holes_dict:
@@ -1274,7 +1274,7 @@ def process_contours(
12741274
]
12751275
)
12761276

1277-
for idx, outer in enumerate(outer_contours):
1277+
for idx, outer in outer_contours.items():
12781278
holes: list[np.ndarray] = holes_dict.get(idx, [])
12791279
if len(holes) != 0:
12801280
feature_geom = feature2geometry(

0 commit comments

Comments
 (0)