python - 使用 scikit-image 读取图像缓冲区

标签 python numpy io buffer scikit-image

我已经有一个图像的内存文件。我想使用 skimage 的 io.imread (或等效的)来读取图像。但是,skimage.io.imread() 采用文件而不是缓冲区

示例缓冲区:

 <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 02 02 02 03 02 02 02 03 03 03 03 04 06 04 04 04 04 04 08 06 06 05 ... >

skimage.io.imread() 只会产生一个 numpy 数组。

最佳答案

尝试将缓冲区转换为 StringIO,然后使用 skimage.io.imread() 读取它

import cStringIO

img_stringIO = cStringIO.StringIO(buf)
img = skimage.io.imread(img_stringIO)

您也可以将其解读为:

from PIL import Image
img = Image.open(img_stringIO)

关于python - 使用 scikit-image 读取图像缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39046106/

相关文章:

c - 当我只需要一个输入时,为什么 getchar() 需要两个输入?

Python json.loads ValueError,需要分隔符

Pandas:什么是 dtype = <U64,如何将其转换为字符串?

java - 分解文件并用java重写它

python - Google Protocol Buffers、HDF5、NumPy 比较(传输数据)

python - 重载 python 类中的 [] 运算符以引用 numpy.array 数据成员

java - ServerSocket 同时不会中断图像数据输入流

python - 从 FTP 文件夹下载所有文件时出现 "Permission denied"错误

python - 'from modulename import function/variable' 是否将整个模块放入 sys 模块字典中?

python - 如何从 channel 名称或 url 检索 channel ID