Jas*_*ram 5 python in-memory stringio scikit-image
我正在使用scikit-image读取图像:
img = skimage.io.imread(filename)
Run Code Online (Sandbox Code Playgroud)
对 进行一些操作后img,我想将它保存到内存文件(a la StringIO)以传递给另一个函数,但它看起来skimage.io.imsave需要文件名,而不是文件句柄。
imsave如果可能的话,我想避免击中磁盘(然后从另一个成像库读取)。有没有一种很好的方法来使用imsave(或其他一些 scikit-image-friendly 功能)StringIO?
更新:2020-05-07
我们现在建议使用该imageio库进行图像读取和写入。此外,在 Python 3 中,StringIO 更改为 BytesIO:
from io import BytesIO
import imageio
buf = BytesIO()
imageio.imwrite(buf, image, format='png')
Run Code Online (Sandbox Code Playgroud)
scikit-image将图像存储为 numpy 数组,因此您可以使用这样的包matplotlib:
from io import BytesIO
import imageio
buf = BytesIO()
imageio.imwrite(buf, image, format='png')
Run Code Online (Sandbox Code Playgroud)
这可能值得作为默认行为添加到skimage.io.imsave,因此如果您愿意,您还可以在https://github.com/scikit-image/scikit-image 上提交问题。
| 归档时间: |
|
| 查看次数: |
2741 次 |
| 最近记录: |