Skip to content

Commit e420c69

Browse files
author
Robert Sachunsky
committed
clip: enlarge non-text masks by coords instead of maximum filter
1 parent 932dd94 commit e420c69

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ocrd_cis/ocropy/clip.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,14 @@ def process(self):
137137
# in relative coordinates for mask/cropping
138138
polygons = [coordinates_of_segment(region, page_image, page_coords)
139139
for region in regions]
140-
masks = [pil2array(polygon_mask(page_image, polygon)).astype(np.uint8)
141-
for polygon in polygons]
142-
for i, mask in enumerate(masks[num_texts:], num_texts):
140+
for i, polygon in enumerate(polygons[num_texts:], num_texts):
143141
# for non-text regions, extend mask by 3 pixels in each direction
144142
# to ensure they do not leak components accidentally
145143
# (accounts for bad cropping of such regions in GT):
146-
masks[i] = filters.maximum_filter(mask, 7)
144+
polygon = Polygon(polygon).buffer(3).exterior.coords[:-1] # keep open
145+
polygons[i] = polygon
146+
masks = [pil2array(polygon_mask(page_image, polygon)).astype(np.uint8)
147+
for polygon in polygons]
147148
for i, region in enumerate(regions):
148149
if i >= num_texts:
149150
break # keep non-text regions unchanged

0 commit comments

Comments
 (0)