Skip to content

Instantly share code, notes, and snippets.

@walsvid
Created April 8, 2017 09:30
Show Gist options
  • Save walsvid/e5048001b4ff89b6a7e1aec4b5bb41f1 to your computer and use it in GitHub Desktop.
Save walsvid/e5048001b4ff89b6a7e1aec4b5bb41f1 to your computer and use it in GitHub Desktop.
How to convert between NumPy array and PIL Image
import numpy
import PIL
# Convert Image to array
img = PIL.Image.open("foo.jpg").convert("L")
arr = numpy.array(img)
# Convert array to Image
img = PIL.Image.fromarray(arr)
@Lexyvil
Copy link

Lexyvil commented Feb 10, 2024

Thanks! This helped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment