importnumpy
importPIL
# Convert Image to array
img=PIL.Image.open("foo.jpg").convert("L")
arr=numpy.array(img)
# Convert array to Image
# 如果要加载npy文件,则执行下面的语句
arr = np.load(路径)
img=PIL.Image.fromarray(arr)
参考网址:https://codeyarns.com/2014/01/16/how-to-convert-between-numpy-array-and-pil-image/