如何把.npy格式与PIL image相互转换

来源:互联网 发布:php导出excel表格乱码 编辑:程序博客网 时间:2024/05/21 10:40
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/
原创粉丝点击