Saving a Numpy array as an image (instructions)

后端 未结 3 938
囚心锁ツ
囚心锁ツ 2021-02-05 14:16

I found my answer in a previous post: Saving a Numpy array as an image. The only problem being, there isn\'t much instruction on using the PyPNG module.

There are only

3条回答
  •  旧时难觅i
    2021-02-05 14:36

    You might be better off using PIL:

    from PIL import Image
    import numpy as np
    
    data = np.random.random((100,100))
    
    #Rescale to 0-255 and convert to uint8
    rescaled = (255.0 / data.max() * (data - data.min())).astype(np.uint8)
    
    im = Image.fromarray(rescaled)
    im.save('test.png')
    

提交回复
热议问题