我正在尝试用 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。
最佳答案
mahotas 的作者在这里。错误消息并不理想(将修复它),但这是正在发生的事情。
灰度图像是浮点图像(即 img.dtype == numpy.float64
),您不能将浮点图像保存为 PNG。
转换为numpy.uint8
:
mahotas.imsave('test.png', img.astype(numpy.uint8))
它会按预期工作。
关于python - 使用 Mahotas 读写图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8888406/