How to convert a PIL Image into a numpy array?

后端 未结 8 2232
不知归路
不知归路 2020-11-22 17:12

Alright, I\'m toying around with converting a PIL image object back and forth to a numpy array so I can do some faster pixel by pixel transformations than PIL\'s Pixel

8条回答
  •  名媛妹妹
    2020-11-22 17:53

    def imshow(img):
        img = img / 2 + 0.5     # unnormalize
        npimg = img.numpy()
        plt.imshow(np.transpose(npimg, (1, 2, 0)))
        plt.show()
    

    You can transform the image into numpy by parsing the image into numpy() function after squishing out the features( unnormalization)

提交回复
热议问题