【问题标题】:Reading and writing images with Mahotas使用 Mahotas 读取和写入图像
【发布时间】:2012-02-11 21:21:18
【问题描述】:

我正在尝试使用 Mahotas 编写图像,但发现它非常困难。

img = mahotas.imread('foo.png', True)
mahotas.imsave('bar.png', img)

我得到的错误是:

ValueError: mahotas.freeimage: cannot write arrays of given type and shape.

我在 OS X 上并使用 brew 安装 freeimage。

【问题讨论】:

    标签: python image-processing mahotas


    【解决方案1】:

    这里是 mahotas 的作者。错误消息并不理想(将修复它),但这是正在发生的事情。

    灰度图像是浮点图像(即img.dtype == numpy.float64),您不能将浮点图像保存为 PNG。

    转换为numpy.uint8:

    mahotas.imsave('test.png', img.astype(numpy.uint8))
    

    它会按预期工作。

    【讨论】:

    • np == numpy 以防万一有人感到困惑 ;)
    • 德克萨斯州。我相应地改进了答案。
    猜你喜欢
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 2010-10-13
    • 2019-09-17
    • 1970-01-01
    相关资源
    最近更新 更多