Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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

like image 645
Wobblester Avatar asked Feb 05 '12 23:02

Wobblester


People also ask

What is the flip code for flipping an image only vertically?

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.

How do you mirror an image in Python?

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


3 Answers

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 !

like image 129
wim Avatar answered Oct 15 '22 20:10

wim


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)  
like image 26
Gareth Latty Avatar answered Oct 15 '22 20:10

Gareth Latty


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)

like image 39
jlengrand Avatar answered Oct 15 '22 21:10

jlengrand