在这里插入代码片
PIL.Image格式及其与np.array转换
from PIL import Image
a = Image.open('data/001.jpg') # 打开图像
gray = a.convert('L')) # 并转成灰度图像
arr = np.array(gray) # 读取图像到数组中 shape(961, 1280)
a = anpy[0].reshape(1, 64, 64).reshape(64, 64) #shape (64, 64)
a_save = Image.fromarray(np.uint8(a * 255)) # *255是因为数组中的元素非零即一
path = path.split('.')[0] + '.jpg'
a_save .save(path)