【问题标题】:Trying to open .img file with matplotlib尝试使用 matplotlib 打开 .img 文件
【发布时间】:2020-07-23 19:19:54
【问题描述】:

我正在尝试打开一个 .img。我运行以下代码:

import matplotlib.pyplot as plt
from planetaryimage import PDS3Image
image = ('/Users/alyse/ldem_1024_00n_15n_150_180.img')
plt.imshow(image, cmap='gray')

我收到以下错误:TypeError: Image data of dtype <U46 cannot be converted to float

【问题讨论】:

    标签: python image matplotlib


    【解决方案1】:

    您也可以使用 PIL。安装:pip install pillow

        import numpy as np
        from PIL import Image
        import matplotlib.pyplot as plt
    
        image = Image.open('/Users/alyse/ldem_1024_00n_15n_150_180.img')
        image_gray = image.convert("L") # Where L is option for grayscale
        array_gray = np.asarray(image_gray)
        
        plt.imshow(array_gray, cmap="gray")
        plt.show()
    

    【讨论】:

    • 感谢您的帮助。我仍然收到错误:UnidentifiedImageError: cannot identify image file '/Users/alyse/ldem_1024_00n_15n_150_180.img'
    • 查看这个答案:stackoverflow.com/questions/902761/… 这显示了如何将 np 数组保存为图像
    猜你喜欢
    • 2021-10-28
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    • 2021-02-10
    • 1970-01-01
    • 1970-01-01
    • 2014-03-11
    相关资源
    最近更新 更多