Skip to content

Instantly share code, notes, and snippets.

@daguiam
Last active April 5, 2019 12:18
Show Gist options
  • Save daguiam/3c48b8bd77fc4892d654bad8eb315ce7 to your computer and use it in GitHub Desktop.
Save daguiam/3c48b8bd77fc4892d654bad8eb315ce7 to your computer and use it in GitHub Desktop.
import numpy as np
from PIL import Image
def save_array_as_image(array, filename):
"""Saves a 2D numpy array to an image"""
image = Image.fromarray(array)
image.save(filename)
array = np.random.random((512,512))*255
array = np.uint8(array)
print(array)
save_array_as_image(array, "image.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment