利用PIL中的Image
from PIL import Image
#其中x是要保存的图片,numpy类型
x = x.astype("uint8") #将其类型转化为uint8
img = Image.fromarray(x)
img = img.convert("L") #“L”灰度图像,“RGB”图像
img.save("./x.bmp") #要保存的路径
利用matplotlib中的pyplot
import matplotlib.pyplot as plt
plt.figure(1)
plt.imshow(change_map, cmap='gray')
plt.savefig('test_image/change_map1.jpg')
plt.show()
利用cv2
import cv2
out = cv2.imread('./1.bmp')
cv2.imwrite('out.jpg', out)
cv2.imshow('result', out)
cv2.waitKey(0)
cv2.destroyAllWindows()