Skip to content

Commit

Permalink
polygon_mask: outline must have color of fill
Browse files Browse the repository at this point in the history
  • Loading branch information
bertsky committed Sep 25, 2019
1 parent 215105a commit 1d82c42
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ocrd_utils/ocrd_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ def crop_image(image, box=None):
# (It should be invalid in PAGE-XML to extend beyond parents.)
if not box:
box = (0, 0, image.width, image.height)
elif box[0] < 0 or box[1] < 0 or box[2] > image.width or box[3] > image.height:
LOG.error('crop coordinates (%s) exceed image (%dx%d)',
str(box), image.width, image.height)
xywh = xywh_from_bbox(*box)
background = ImageStat.Stat(image).median[0]
new_image = Image.new(image.mode, (xywh['w'], xywh['h']),
Expand Down Expand Up @@ -446,7 +449,7 @@ def polygon_mask(image, coordinates):
mask = Image.new('L', image.size, 0)
if isinstance(coordinates, np.ndarray):
coordinates = list(map(tuple, coordinates))
ImageDraw.Draw(mask).polygon(coordinates, outline=1, fill=255)
ImageDraw.Draw(mask).polygon(coordinates, outline=255, fill=255)
return mask

def rotate_coordinates(polygon, angle, orig=np.array([0, 0])):
Expand Down

0 comments on commit 1d82c42

Please sign in to comment.