3

I'm trying to write an image with Mahotas and finding it strangely difficult.

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.

I'm on OS X and used brew to install freeimage.

luispedro
  • 6,934
  • 4
  • 35
  • 45
Ralphleon
  • 3,968
  • 5
  • 32
  • 34

1 Answers1

5

Author of mahotas here. The error message is not ideal (will fix it), but here's what's happening.

The greyscale image is a floating point image (i.e., img.dtype == numpy.float64) and you cannot save floating point images as PNGs.

Convert to numpy.uint8:

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

and it will work as expected.

luispedro
  • 6,934
  • 4
  • 35
  • 45