I am trying to flip a picture across its vertical axis in python.
The image is flipped according to the value of flipCode as follows: flipcode = 0 : flip vertically. flipcode > 0 : flip horizontally. flipcode < 0 : flip vertically and horizontally.
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).
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()
wolf revok cats !
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)
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With