image_from_polygon: add fill=none option
@@ -486,7 +486,8 @@ def image_from_polygon(image, polygon, fill='background', transparency=False):
of relative coordinates into the image, fill everything
outside the polygon hull to a color according to ``fill``:
- - if ``background`` (the default),
+ - if ``none`` then do not touch the colour channels at all,
+ - else if ``background`` (the default),
then use the median color of the image;
- otherwise use the given color, e.g. ``'white'`` or (255,255,255).
@@ -499,6 +500,9 @@ def image_from_polygon(image, polygon, fill='background', transparency=False):
Return a new PIL.Image.
"""
+ if fill == 'none' or fill is None:
+ new_image = image.copy()
+ else:
mask = polygon_mask(image, polygon)
if fill == 'background':
background = ImageStat.Stat(image, mask=mask)
