美文网首页
PIL引入图像

PIL引入图像

作者: 学号叁拾 | 来源:发表于2019-05-14 20:23 被阅读0次

用PIL引入图像,一直忘怎么写

from PIL import Image#Pil引入图像
import matplotlib.pyplot as plt
import numpy as np
path='/home/lena.jpg'#地址

img=np.array(Image.open(path).convert('L'))#转换成灰度图像,并且转换np数组
img=img.astype("float32")/255#normalis 值在0-1之间,pil图像的值在0-255
print(img)
plt.imshow(img,cmap='gray')
plt.show

PIL与Numpy数组之间互换也是门大学问,下次再看。

相关文章

网友评论

      本文标题:PIL引入图像

      本文链接:https://www.haomeiwen.com/subject/voaeaqtx.html