Numpy.array to PNG file and vice versa

I have a 2d numpy.array object of a dtype=uint16 object representing a grayscale image. How to save it in a PNG file, and then read it back, get the same array?

+5
source share
1 answer

scikit-image makes this pretty easy:

 from skimage.io import imread, imsave import numpy as np x = np.ones((100, 100), dtype=np.uint16) imsave('test.png', x) y = imread('test.png') (x == y).all() # True 
+3
source

Source: https://habr.com/ru/post/1201232/


All Articles