📅 2014-Jan-16 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ numpy, pil ⬩ 📚 Archive
This example illustrates converting a 3-channel RGB PIL Image to 3D NumPy array and back:
import numpy
import PIL
# Convert PIL Image to NumPy array
= PIL.Image.open("foo.jpg")
img = numpy.array(img)
arr
# Convert array to Image
= PIL.Image.fromarray(arr) img
Tried with: Python 2.7.3 and Ubuntu 12.04