Python 3.x 写入和读取图像时的噪音(MNIST)
我一直在研究手写数字识别,我想保存MNIST图像并再次读取,然后转换为数组,以便为CNN提供信息 逻辑是,如果我能够正确地阅读和识别这些图像,我就可以对我的实际输入使用相同的功能 代码1:Python 3.x 写入和读取图像时的噪音(MNIST),python-3.x,python-imaging-library,Python 3.x,Python Imaging Library,我一直在研究手写数字识别,我想保存MNIST图像并再次读取,然后转换为数组,以便为CNN提供信息 逻辑是,如果我能够正确地阅读和识别这些图像,我就可以对我的实际输入使用相同的功能 代码1: def create_images(): for a in range(1): num_test = 7885 image= data.test.images[num_test] plot_image(image) pixels = 25
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")
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
相应的输出:
代码2:
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")
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有什么区别吗?不要使用JPEG。使用PNG或TIFF进行无损图像压缩
噪声是通过JPEG算法的有损压缩添加的。不要使用JPEG。使用PNG或TIFF进行无损图像压缩 噪声是通过JPEG算法的有损压缩添加的