I need to rotate a lot of images in a folder using Python. I found out, it could be done using ndimage.rotate. But I get a problem, as the image is not being rotated: I wait and wait, and it takes so much time…
This is the discussed part of my code:
for image in filelist:
print 'Checking ', os.path.basename(image)
im = misc.imread(image)
geom = im.shape
print geom
if geom[1] > geom[0]:
# Some code to determine the way image should be rotated, which
# calculates angle
print 'Rotating ', os.path.basename(image)
rotated = ndimage.rotate(im, angle, reshape = False)
print 'Rotated ', os.path.basename(image)
misc.imsave(image, rotated)
else:
print os.path.basename(image), ' is OK'
When I run it it works really slow, about 20 sec per image. How to do it faster? I would appreciate any help with it.
And just in case, I am not a professional programmer.
The solution is to use PIL instead of ndimage as deinonychusaur suggested. You might want to look here:
pythonware.com/library/pil/handbook/introduction.htm
It has everything needed to write a program with PIL.