3

我正在尝试使用 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。

4

1 回答 1

5

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

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

转换为numpy.uint8

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

它会按预期工作。

于 2012-01-18T14:36:23.910 回答