用ndimage在python中旋转

时间:2013-01-04 19:01:34

标签: python rotation scipy

我需要使用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秒。怎么做得更快?我很感激任何帮助。

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

1 个答案:

答案 0 :(得分:-2)

解决方案是使用PIL而不是像deinonychusaur建议的ndimage。你可能想看看这里: pythonware.com/library/pil/handbook/introduction.htm

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