小编Ida*_*n.c的帖子

如何从 numpy float32 数组创建图像?

我有一个numpy.ndarray数组,其中包含float32. 图像尺寸应为 226×226。我试图用来PIL.Image创建图像,但出现错误。我读了PIL.Image.fromarray需要的对象和方式,以及浮法我要打电话fromarray'F'我试过。

这就是我试图做的:

from PIL import Image
img = Image.fromarray(slice56, mode='F')
#type(slice56) = <type 'numpy.ndarray'>
#slice56 = array([ 0.,  0.,  0., ...,  0.,  0.,  0.], dtype=float32)
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.6/site-packages/PIL/Image.py", line 1860, in fromarray
    return frombuffer(mode, size, obj, "raw", mode, 0, 1)
  File "/usr/lib64/python2.6/site-packages/PIL/Image.py", line 1805, in frombuffer
    return apply(fromstring, (mode, size, data, decoder_name, args))
  File "/usr/lib64/python2.6/site-packages/PIL/Image.py", …
Run Code Online (Sandbox Code Playgroud)

python numpy python-imaging-library

7
推荐指数
1
解决办法
2万
查看次数

标签 统计

numpy ×1

python ×1

python-imaging-library ×1