'How can I flip an image along the vertical axis with python? [closed]

I am trying to flip a picture across its vertical axis in python.



Solution 1:[1]

For something as simple as this, PIL is not really needed - you can do it with numpy fliplr.

import matplotlib.pyplot as plt
import numpy as np

im = np.flipud(plt.imread('so.jpg'))
plt.subplot(2, 1, 1)
plt.imshow(im)
plt.subplot(2, 1, 2)
plt.imshow(np.fliplr(im))
plt.show()

enter image description here

wolf revok cats !

Solution 2:[2]

You have stated you are using PyGraphics - it states that load_image returns a PIL image object.

PyGraphics doesn't appear to offer the functionality of flipping, so just do it with PIL, specifically transpose

from PyGraphics import picture
flipped = picture.load_image("blah.jpg").transpose(Image.FLIP_LEFT_RIGHT)  

Solution 3:[3]

You should look at the PIL for such things :)

http://www.pythonware.com/products/pil/

This may be the simplest way to do what you wan.

Here is a tutorial that will give the code :

http://effbot.org/imagingbook/introduction.htm
(see chapter geometric transforms in the tutorial)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Gareth Latty
Solution 3 Jonathan Root