Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 写入和读取图像时的噪音(MNIST)_Python 3.x_Python Imaging Library - Fatal编程技术网

Python 3.x 写入和读取图像时的噪音(MNIST)

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

我一直在研究手写数字识别,我想保存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")
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算法的有损压缩添加的