我需要使用Python旋转文件夹中的大量图像。我发现,这可以使用ndimage.rotate来完成。但我遇到了一个问题,因为图像没有旋转:我等了又等,花了太多时间……
这是我的代码中讨论过的部分:
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'当我运行它的时候,它的运行速度非常慢,每个图像大约20秒。怎样做得更快?如果有任何帮助,我将不胜感激。
以防万一,我不是一个专业的程序员。
发布于 2013-01-05 06:57:08
解决方案是使用PIL,而不是像deinonychusaur建议的那样使用ndimage。你可能想看看这里: pythonware.com/library/pil/handbook/introduction.htm
它拥有用PIL编写程序所需的一切。
https://stackoverflow.com/questions/14163211
复制相似问题