我需要使用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秒。如何更快地做到呢?我将不胜感激。

以防万一,我不是专业程序员。

最佳答案

解决方案是使用PIL代替ndimage,如deinonychusaur所建议。您可能要看这里:
pythonware.com/library/pil/handbook/introduction.htm

它具有使用PIL编写程序所需的一切。

07-24 09:47
查看更多