-
skimage.io.imread()
する時に、バックエンドに使うライブラリを指定する事ができる。 - この時、どのライブラリが高速に読み込みを行えるのか比べてみた。
環境や読み込むファイルの性質によって当然変わってくるはずなので、各自の環境で試してみた方が良い。この記事は測定方法の例示のために書いた。
skimage.io.imreadのpluginオプション
以下のように読み込みで使うプラグインを指定できる。
# matplotlibで読み込む
skimage.io.imread(fname='lenna.png', plugin='matplotlib')
# pilで読み込む
skimage.io.imread(fname='lenna.png', plugin='pil')
- 公式サイトのこの辺りに説明が書いてある。
plugin : str, optional
Name of plugin to use. By default, the different plugins are tried (starting with the Python Imaging Library) until a suitable candidate is found. If not given and fname is a tiff file, the tifffile plugin will be used.
- 対応しているプラグインの一覧は、
skimage.io.find_available_plugins()
で調べられる。- http://scikit-image.org/docs/stable/api/skimage.io.html#skimage.io.find_available_plugins
- 実行中の環境にインストールしていないプラグインも出てくるので、必要ならインストールする。
測定
インストールしていないプラグインは除外して以下のように測定した。
import skimage.io
plugins = skimage.io.find_available_plugins()
for name in plugins:
# 除外
if name in ['qt', 'gdal', 'gtk', 'simpleitk', 'fits', 'tifffile']:
continue
print(name)
skimage.io.use_plugin(name)
%timeit skimage.io.imread(fname='lenna.png', plugin=name)
print('---')
参考までに私の環境での測定結果を載せておく。
imread
8.88 ms ± 2.08 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
---
pil
20.1 ms ± 892 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
---
matplotlib
37.8 ms ± 6.65 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
---
imageio
25.1 ms ± 5.67 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)
---