[Image-SIG] Converting from numarray to PIL

Fredrik Lundh fredrik at pythonware.com
Mon Jun 13 07:57:58 CEST 2005

Dylan Moreland wrote:

> I'm working with some large numarrays of astronomical data (1000 by
> 1000 pixels) that I want to quickly transform into grayscale images
> for use in my wxPython app. I've tried drawing them using canvas
> methods in both PIL and wx, scaling the values from their original
> range to [0, 255] for use as the colors, but this is too slow for my
> application.

have you tried

    im.putdata(array, scale, offset)


> I see from
> http://effbot.org/zone/pil-numpy.htm
> That it is possible to directly transform a numarray into an Image,
> but there isn't much documentation about the typecodes involved. How
> would I transform my array into one that, when loaded into PIL,
> displays a range of grays?

map the values to the 0-255 range, turn it into an UnsignedInt8
array, and pass the result to the "array2image" function.  this gives
you a grayscale PIL image (mode "L").


More information about the Image-SIG mailing list