Skip to content

Commit

Permalink
Bug fix: for rotating mask images. (#1399)
Browse files Browse the repository at this point in the history
* Bug fix: for rotating mask images.

* Formatted code with black
  • Loading branch information
gokuld authored Apr 15, 2021
1 parent eefd853 commit 823640a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions moviepy/video/fx/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,23 @@ def filter(get_frame, t):
UserWarning,
)

# PIL expects uint8 type data. However a mask image has values in the
# range [0, 1] and is of float type. To handle this we scale it up by
# a factor 'a' for use with PIL and then back again by 'a' afterwards.
if im.dtype == "float64":
# this is a mask image
a = 255.0
else:
a = 1

# call PIL.rotate
return np.array(
Image.fromarray(np.array(im).astype(np.uint8)).rotate(
angle, expand=expand, resample=resample, **kwargs
return (
np.array(
Image.fromarray(np.array(a * im).astype(np.uint8)).rotate(
angle, expand=expand, resample=resample, **kwargs
)
)
/ a
)

return clip.transform(filter, apply_to=["mask"])

0 comments on commit 823640a

Please sign in to comment.