我在用着scikit 图像 http://scikit-image.org/读取图像:
img = skimage.io.imread(filename)
做了一些操作后img
,我想将其保存到内存中的文件(laStringIO http://docs.python.org/2/library/stringio.html)传递给另一个函数,但看起来像skimage.io.imsave http://scikit-image.org/docs/dev/api/skimage.io.html#imsave需要文件名,而不是文件句柄。
我想避免击中磁盘(imsave
如果可能的话,然后从另一个图像库读取)。有没有一个好的方法来获得imsave
(或其他一些 scikit 图像友好的功能)可以使用StringIO
?
更新:2020-05-07
我们现在建议使用imageio
用于图像读取和写入的库。此外,在 Python 3 中,StringIO 更改为 BytesIO:
from io import BytesIO
import imageio
buf = BytesIO()
imageio.imwrite(buf, image, format='png')
scikit-image
将图像存储为 numpy 数组,因此您可以使用诸如matplotlib
这样做:
import matplotlib.pyplot as plt
from StringIO import StringIO
s = StringIO()
plt.imsave(s, img)
这可能值得添加为默认行为skimage.io.imsave
,所以如果您愿意,您也可以在以下地址提交问题https://github.com/scikit-image/scikit-image https://github.com/scikit-image/scikit-image.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)