I have an image in NumPy array format and I want save it to my disk. I used this code:
from PIL import Image
....
Image.fromarray(img).save('res.png')
But it saved as 8-bit. How can I make it save as 16-bit?
To save the Numpy array as a local image, use the save() function and pass the image filename with the directory where to save it. This will save the Numpy array as a jpeg image.
Try this: Make sure your image is in Grayscale mode. Choose File > Save As. Select png format and save the file.
imwrite() saves the image file to the specified path. The first parameter is the path where you want to save the file, and the second parameter is the image to be saved.
Images are an easier way to represent the working model. In Machine Learning, Python uses the image data in the format of Height, Width, Channel format. i.e. Images are converted into Numpy Array in Height, Width, Channel format.
I believe the answer at https://stackoverflow.com/a/25814423/727533 may be what you're looking for. It describes using PyPNG to output a NumPy array as a PNG.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With