【问题标题】:Skimage.io.read imread a PIL ObjectSkimage.io.read 读取一个 PIL 对象
【发布时间】:2020-12-06 19:34:41
【问题描述】:

所以我正在使用 skimage 进行一些图像预处理(我对它很陌生)。我有一个PIL Image 对象,想用skimage.io.imread() 转换为skimage 图像。我知道我可以只保存图像然后在该文件上运行imread,但我想知道是否有一种方法可以从代码本身读取PIL Image 对象。我尝试在 PIL Image 对象本身上运行imread,但最终出现错误。

OSError: Cannot understand given URI: <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=192....

任何人都知道我可以如何在 skimage 中解决这个问题。

【问题讨论】:

    标签: python numpy python-imaging-library scikit-image


    【解决方案1】:

    Scikit-Image 将图像存储为 Numpy 数组,因此您只需从 PIL 图像创建一个 Numpy 数组:

    ImageForScikit = np.array(YourPILImage)
    

    【讨论】:

      【解决方案2】:

      您可以查看与函数imread 相关的imageio documentation,以在代码中包含属性格式和代码如下,以防图像格式为PNG:imageio.imread(filename, format = 'PNG')

      【讨论】:

        猜你喜欢
        • 2013-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-10
        • 2011-06-19
        • 2020-12-05
        • 1970-01-01
        相关资源
        最近更新 更多