【发布时间】:2017-11-03 19:55:12
【问题描述】:
我一直在研究手写数字识别,我想保存 MNIST 图像并再次读取它并转换为它的数组以便为 CNN 提供数据。
逻辑是,如果我能够正确读取和识别这些图像..我可以将相同的功能用于我的真实输入。
代码 1:
def create_images():
for a in range(1):
num_test = 7885
image= data.test.images[num_test]
plot_image(image)
pixels = 255 * (1.0 - image)
pixels.resize((28,28))
im = Image.fromarray(pixels.astype(np.uint8), mode='L')
im.save("2.jpeg")
对应的输出:
代码 2:
def ImagetoArray(image):
im = Image.open(image)
tv = list(im.getdata())
# normalize pixels to 0 and 1. 0 is pure white, 1 is pure black.
tva = [(255 - x) * 1.0 / 255.0 for x in tv]
tva = np.asarray(tva)
count=0
#plot_image(tva)
return tva
对应的输出:
虽然我知道噪音似乎可以忽略不计,但图像只有 28X28 像素,噪音可能会干扰。
我想知道噪音是从哪里添加的以及如何克服它? 使用 opencv 有什么不同吗?
【问题讨论】:
标签: python-3.x python-imaging-library