python – 为什么skimage.transform.rotate比PIL的Image.rotate慢得多?
发布时间:2020-12-05 07:00:50 所属栏目:Python 来源:互联网
导读:我正在将一些基于PIL的代码转换为NumPy,但我发现 skimage.transform.rotate函数明显慢于PIL的Image.rotate. 作为一个粗略的比较,使用skimage在~1000×1000像素图像上旋转大约需要2.2秒,而Image.rotate需要大约0.1秒: import timefrom PIL import Imageimport
我正在将一些基于PIL的代码转换为NumPy,但我发现
作为一个粗略的比较,使用skimage在~1000×1000像素图像上旋转大约需要2.2秒,而Image.rotate需要大约0.1秒: import time from PIL import Image import numpy as np from skimage.transform import rotate im = Image.open("some_big_image.png").convert("L") print "Image size: %s" %(im.size,) s = time.time() im.rotate(10,Image.BICUBIC,expand=True) print "Image.rotate: %0.04f" %(time.time() - s,) ima = np.array(im) / 255.0 s = time.time() rotate(ima,10,order=3) # order=3 --> bi-cubic filtering print "skimage.transform.rotate: %0.04f" %(time.time() - s,) 并输出: $py rotate.py Image size: (1275,1650) Image.rotate: 0.1154 skimage.transform.rotate: 2.2310 (这些数字在多次运行中或多或少一致;我不相信这是一个没有运行足够测试的工件) 所以!那是怎么回事?有没有办法加快skimage的旋转? 版本信息: > PIL:1.1.7 值得注意的是: >如果未使用BICUBIC过滤,则im.rotate操作仅需约0.01秒,而设置order = 0以使用最近邻过滤,skimage.rotate需要约0.6秒. 解决方法从 https://github.com/scikit-image/scikit-image安装最新版本.就在几天前,我修复了与此减速相关的错误(参见 https://github.com/scikit-image/scikit-image/commit/d5776656a8217e58cb28d5760439a54e96d15316).我的数字与当前开发版本如下: from PIL import Image import numpy as np from skimage.transform import rotate a = np.zeros((1000,1000),dtype=np.uint8) im = Image.fromarray(a) %timeit im.rotate(10,expand=True) ima = a / 255.0 %timeit rotate(ima,order=1) %timeit rotate(ima,order=3) ## -- Output -- 10 loops,best of 3: 41.3 ms per loop 10 loops,best of 3: 43.6 ms per loop 10 loops,best of 3: 101 ms per loop (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Python中的Classes和Metaclasses详解
- 使用Python通过Azure API搜索Bing
- python – 根据另一列pandas数据框提取列值
- 不同项目的python库如何在同一个包中?
- 为什么在Python中不能统一处理集合?
- python – SqlAlchemy在保存之前将UTC DateTime转换为本地时
- python – 如何覆盖BaseHTTPRequestHandler log_message()方
- python – Pandas Dataframe查找所有列等于的行
- python – Django不调用model clean方法
- Python Popen shell = False导致OSError:[Errno 2]没有这样
推荐文章
站长推荐
- python – 为什么skimage.transform.rotate比PIL
- Python Django:在视图中,最好是为对象添加属性还
- python-2.7 – Sphinx的LaTeX错误:找不到文件`t
- Python max-by函数?
- python – numpy – 将非连续数据转换为适当的连
- django-forms – 如何使用modelformset_factory创
- 创建虚拟环境(Python)中“virtualenv”和“-m ve
- python – 通过Curl向Flask发送JSON-Request [复
- python中引用与复制用法实例分析
- .net – 一旦线程启动,我应该保持对线程的引用吗
热点阅读