提交 85532c56 编写于 作者: 异萌's avatar 异萌

Add new file

图片处理的一个方法
里面定义了一个方法load_image(file)
传入参数为file
这里引用了PIL包,python image library python图片库
最后返回处理好的image数组,
上级 c899b99a
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
def load_image(file):
# 以灰度图的方式读取待测图片
img = Image.open(file).convert('L')
# 预处理
# 调整图像大小
img = img.resize((28,28),Image.ANTIALIAS)
plt.imshow(img)
img.show()
img = np.array(img).reshape(1,1,28,28).astype('float32')
# 归一化处理
#img = img / 255
return img
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册