note.nkmk.me

Python, Pillow: Flip image

Posted: 2019-06-25 / Tags: Python, Pillow, Image Processing
Sponsored Link

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).

Please refer to the following post for installation and basic usage of Pillow(PIL).

Use the rotate() method of the Image module to rotate the image.

See the following post 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')

lena

im_flip = ImageOps.flip(im)
im_flip.save('data/dst/lena_flip.jpg', quality=95)

Pillow flip lena

im_mirror = ImageOps.mirror(im)
im_mirror.save('data/dst/lena_mirror.jpg', quality=95)

Pillow mirror lena

Sponsored Link
Share

Related Categories

Related Posts