I have a 2d numpy.array
object of dtype=uint16
representing a grayscale image. How do I save it to a PNG file and then read it back, obtaining the same array?
numpy.array to PNG file and back
Asked Answered
Is this what is described in the pyPng Code Examples? –
Rainer
I think PNG>np is given, but the other way around only shows a 3d array and I can't figure out how to make it work with a 2d array. Also as I'm starting off with a numpy.array, I need that example first to try it out. in short, it isn't trivial from the examples... –
Alethiaaletta
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
But this has a drawback of accessing disk and back. Can it be done in memory? –
Vedavedalia
© 2022 - 2024 — McMap. All rights reserved.