[英]Python - Numpy RGB pixel array to image
I have an array of pixels 我有一个像素数组
np.shape(pred2)
Out[35]: (3000, 3, 32, 32)
It has 3000 images, 3 values rgb and is 32*32 in size for each image. 它有3000个图像,3个值rgb,每个图像的大小为32 * 32。 I want to create an image from this. 我想从中创建一个图像。
Here is what I have so far: 这是我到目前为止:
img = Image.new( 'RGB', (32,32), "black") # create a new black image
pixels = img.putdata(pred2[1,:])
Can anyone give me a hand here as to what I am doing wrong? 任何人都可以帮我解决一下我做错了什么吗?
Images are shape (h, w, 3)
, not (3, h, w)
. 图像是形状(h, w, 3)
,而不是(3, h, w)
。 You need to permute your axes accordingly. 您需要相应地置换轴。 Depending on whether you care about width vs height, it appears you can just do: 根据您是否关心宽度与高度,看起来您可以这样做:
im = pred2[1].T
scipy.misc.imsave('the_image_file.png', im)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.