How to flip an image horizontally in python ?

Published: April 19, 2019

DMCA.com Protection Status

Examples of how to flip an image horizontally in python:

Get a vertically flipped image using pillow

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

from PIL import Image
from PIL import ImageOps

im = Image.open("lena.png")

im = ImageOps.mirror(im)

im.save("lena_mirror.png")
im.show()

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

Get a vertically flipped image using numpy

To flip an image horizontally with numpy there is fliplr, illustration:

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

img = mpimg.imread('lena.png')

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

plt.savefig("lena_mirror_matplotlib.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