当前位置 博文首页 > 粽子小黑的博客:PIL Image.convert(‘L‘)转换图像发绿

    粽子小黑的博客:PIL Image.convert(‘L‘)转换图像发绿

    作者:[db:作者] 时间:2021-08-11 12:51

    在这里插入图片描述
    如图,期望图片为右边,而生成为左边。

    本文源码:

    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='grap')
    

    官方文档:https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.imshow.html

    cs
    下一篇:没有了