简体   繁体   中英

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. 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) . 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM