How to flip an image vertically in python ?

Published: April 19, 2019

DMCA.com Protection Status

Examples of how to flip an image vertically in python:

Get a vertically flipped image using pillow

To flip an image vertically a solution is to use the function rotate(), example:

from PIL import Image

im = Image.open("eiffel_tower.jpg")

im = im.rotate(180)

im.save("eiffel_tower_fliped_vertically.jpg")

How to flip an image vertically in python ? How to flip an image vertically in python ?
How to flip an image vertically in python ?

Another solution is tu use flip():

from PIL import Image
from PIL import ImageOps

im = Image.open("eiffel_tower.jpg")

im = ImageOps.flip(im)

im.save("eiffel_tower_fliped_vertically.jpg")

Get a vertically flipped image using numpy

To flip an image vertically with numpy there is flipud, illustration:

import numpy as np 
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

img = mpimg.imread('eiffel_tower.jpg')

img2 = np.flipud(img)
plt.imshow(img2)

plt.savefig("eiffel_tower_fliped_vertically.png", dpi=200)
plt.show()

Note: to save an image with frameless see How to create a figure with no axes ( frameless ) or labels using matplotlib ?

References

Links Site
numpy.flipud numpy doc
Comment sauver une image seule sans les contours ou les labels avec matplotlib ? science-emergence article
Image Module illow.readthedocs.io
ImageOps Module pillow.readthedocs.io
Flopped image wikipedia
Flipped image wikipedia
Flip An Image docs.gimp.org
PIL - Images not rotating stackoverflow
Image rotation in Pillow stackoverflow
pixabay pixabay