Alternatively, to get a numpy array from an image use:
from PIL import Image
from numpy import array
img = Image.open("input.png")
arr = array(img)
And to get an image from a numpy array, use:
img = Image.fromarray(arr)
img.save("output.png")
sample:
from PIL import Image
import numpy
im = Image.open("sample2.png")
np_im = numpy.array(im)
print np_im.shape
OUTPUT
(200, 400, 3)
np_im = np_im - 18
new_im = Image.fromarray(np_im)
new_im.save("numpy_altered_sample2.png")
im = Image.open("sample2.png")