HOME/Articles/

pil example NumPy2PIL (snippet)

Article Outline

Python pil example 'NumPy2PIL'

Modules used in program:

  • import PIL
  • import numpy

python NumPy2PIL

Python pil example: NumPy2PIL

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)