Python, Pillow: Flip image
ImageOps.flip()、ImageOps.mirror()
The ImageOps
module of the Python image processing library Pillow(PIL) provides flip()
to flip the image upside down (vertically) and mirror()
to flip the left and right (horizontally).
flip()
: ImageOps Module — Pillow (PIL Fork) 4.4.0.dev0 documentationmirror()
: ImageOps Module — Pillow (PIL Fork) 4.4.0.dev0 documentation
See the following article for installation and basic usage of Pillow(PIL).
Use the rotate()
method of the Image
module to rotate the image.
See the following article for image rotation with OpenCV, NumPy.
Sample code
Load the image and call flip()
or mirror()
.
from PIL import Image, ImageOps
im = Image.open('data/src/lena.jpg')
source: pillow_flip_mirror.py
im_flip = ImageOps.flip(im)
im_flip.save('data/dst/lena_flip.jpg', quality=95)
source: pillow_flip_mirror.py
im_mirror = ImageOps.mirror(im)
im_mirror.save('data/dst/lena_mirror.jpg', quality=95)
source: pillow_flip_mirror.py