Answers for "how to store a numpy array as image file"

3

display np array as image

from PIL import Image
import numpy as np

w, h = 512, 512
data = np.zeros((h, w, 3), dtype=np.uint8)
data[0:256, 0:256] = [255, 0, 0] # red patch in upper left
img = Image.fromarray(data, 'RGB')
img.save('my.png')
img.show()
Posted by: Guest on June-08-2020
2

how to write a numpy array to a file in python

numpy.savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='n', 
              header='', footer='', comments='# ', encoding=None)


x = y = z = np.arange(0.0,5.0,1.0)
np.savetxt('test.out', x, delimiter=',')   # X is an array
np.savetxt('test.out', (x,y,z))   # x,y,z equal sized 1D arrays
np.savetxt('test.out', x, fmt='%1.4e')   # use exponential notation
Posted by: Guest on March-15-2021

Code answers related to "how to store a numpy array as image file"

Python Answers by Framework

Browse Popular Code Answers by Language