Why CIFAR-10 images are not displayed properly using matplotlib?

前端 未结 9 856
独厮守ぢ
独厮守ぢ 2021-02-06 12:28

From the training set I took a image(\'img\') of size (3,32,32). I have used plt.imshow(img.T). The image is not clear. Now changes I have to make to image(\'img\') to make it m

9条回答
  •  不思量自难忘°
    2021-02-06 12:50

    try using

    import matplotlib.pyplot as plt
    from scipy.misc import toimage
    plt.imshow(toimage(img))
    

    I am not 100% sure of how the code works, but I think that because the images are stored in floating point numpy arrays, the imshow() function has a difficult time mapping them to the right colors. By typecasting them to image using toimage() you convert them into proper image format that imshow() expects, i.e not an array but an image encoded as .png or .jpg.

    This code works for me every time I want to display images in python.

提交回复
热议问题