使用Mahotas读写图像

3

我正在尝试使用Mahotas写入图像,但发现这很困难。

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

the error I'm gettings is:

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

我使用的是OS X系统,并且使用brew安装了freeimage。

1个回答

5

我是Mahotas的作者。错误信息不太理想(我会修复它),但是以下是发生的情况:

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

请转换为numpy.uint8

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

它将按预期工作。


np == numpy,以防有人混淆 ;) - Ralphleon
谢谢。我已经相应地改进了答案。 - luispedro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接