[Image-SIG] Re: Image-SIG digest, Vol 1 #44 - 1 msg

Lopez-Gulliver, Roberto gulliver@mic.atr.co.jp
Thu, 22 Oct 1998 01:22:39 +0900 (JST)


Dear all,

I know the mail enclosed below is pretty old (1996!) but I'm stuck trying
to change my images to array back and forth for speed. Is this still
working or have it changed with my new version PILv03.a3?

Any/all help will be much appreciated.

--desesperado Roberto

---------------------------------------------------------------------

Fredrik Lundh fredrik_lundh@ivab.se
Wed, 3 Apr 1996 13:25:19 +0200 

    Previous message: Going multimedia? 
    Next message: Grail + PIL = true! 
    Messages sorted by: [ date ][ thread ][ subject ][ author ] 



If someone would like to fool around with the Python Imaging Library
and the Numerical extension at the same time, here's a really
minimal interface between these two libraries.

A little more checking should of course be added, to make sure that
the image isn't multiband, and that the array really contains unsigned
8-bit integers, but at least you'll get the idea :-)

        /F

--------------------------------------------------------------------

import Image, Numeric

def ImageToArray(i):
    a = Numeric.array(i._tostring(), "b")
    a.shape = i.size[1], i.size[0]
    return a

def ArrayToImage(a):
    i = Image.new("L", (a.shape[1], a.shape[0]))
    i._fromstring(a.toString())
    return i

# "If you cannot do it in 8 lines of Python, it is probably
#  not worth doing."

--------------------------------------------------------------------