首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在python中使用ndimage进行旋转

在python中使用ndimage进行旋转
EN

Stack Overflow用户
提问于 2013-01-05 03:01:34
回答 1查看 1.1K关注 0票数 3

我需要使用Python旋转文件夹中的大量图像。我发现,这可以使用ndimage.rotate来完成。但我遇到了一个问题,因为图像没有旋转:我等了又等,花了太多时间……

这是我的代码中讨论过的部分:

代码语言:javascript
复制
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秒。怎样做得更快?如果有任何帮助,我将不胜感激。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-05 06:57:08

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

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

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14163211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档