如图,期望图片为右边,而生成为左边。
本文源码:
import matplotlib.pyplot as plt
from PIL import Image
imgs_path = 'imgs\\'
fig_name = 'O4.jpg'
img = Image.open(imgs_path+fig_name)
img = img.resize(size = (224,224))
img = img.convert('L')
# img.show()
plt.figure()
plt.imshow(img)
plt.axis('on')
plt.show()
# plt.savefig('new\\'+fig_name)
plt.close()
若使用img.show()没问题,但是用plt.imshow(img)就会变绿。
因此使用plt.imshow(img,cmap='gray')
官方文档:https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.imshow.html