我正在尝试使用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。
我正在尝试使用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。
我是Mahotas的作者。错误信息不太理想(我会修复它),但是以下是发生的情况:
灰度图像是浮点图像(即,img.dtype == numpy.float64
),您不能将浮点图像保存为PNG。
请转换为numpy.uint8
:
mahotas.imsave('test.png', img.astype(numpy.uint8))
它将按预期工作。