[PYTHON MATRIX-SIG] ANNOUNCE: A minimal Matrix<->PIL interface
Fredrik Lundh
fredrik_lundh@ivab.se
Wed, 3 Apr 1996 13:25:19 +0200
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."
--------------------------------------------------------------------
The current PIL distribution can be found at:
http://www.python.org/sigs/image-sig/Imaging-0.0.tar.gz
http://www.python.org/sigs/image-sig/Imaging-0.1-handbook-draft.ps.gz
Release 0.1 of the library will be available real soon now (it would
be nice if at least someone had any comments on the current release,
though :-)
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================