按道理讲,只要是numpy格式应该都可以这样show出来,但是只有存储成.npy这种才正确显示
# import os # from PIL import Image # import matplotlib.pyplot as plt # img = Image.open('/home/sensetime/000001_10.png') # plt.figure("Image") # plt.imshow(img) # plt.axis('on') # plt.title('image') # plt.show() import numpy as np import matplotlib.pyplot as plt from collections import Counter from PIL import Image def show_pic(path): pic = np.load(path) x = set(pic.flatten().tolist()) ct = Counter() print('type', type(pic.flatten().tolist())) ct.update(pic.flatten().tolist()) print(ct) print(x) plt.imshow(pic) plt.show() def main(): # path = '/home/sensetime/000001_10.png' img = Image.open('/home/sensetime/000001_10.png') arr = np.array(img) np.save('/home/sensetime/images.npy', arr) show_pic('/home/sensetime/images.npy') if __name__ == '__main__': main()