[PYTHON IMAGE-SIG] Image docs
Fri, 3 May 1996 02:58:05 +0200
> My interest is in reading a raw stream of bytes in the range 0 - 64
> with 0 being white and 64 black and producing an image on the screen
> using python. I know pbmplus can do this. Is there any modules for
> python 1.3 available that would help?
You could try PIL; although the current release cannot display images
itself (it calls 'xv' to take care of that), it can read 8-bit images
without much ado:
fp = open("image")
# create an image and load data to it
im = Image.new("L", (xsize, ysize))
im._fromstring(fp.read(xsize * ysize))
# adjust polarity (0=black, 255=white)
im = im.point(map(lambda a: 255 - (255 * a / 64), range(256))
# PIL 0.1 allows you to write:
# im = im.point(lambda a: 255 - (255 * a / 64))
# display (via xv; see PIL 0.1 distribution for Tk support)
Better would of course be to write a real file format handler; to do
that, you need to read enough of the file's header to identify the
format, and then setup a "tile list" describing where and how to read
data from the file. PIL takes care of the rest.
Alternatively, I think you could use Jack Jansen's IMG in a similar
> Is there an interface to the svgalib on linux?
Not as far as I know, but it sure would be trivial to add to PIL
(guess I'd better install Linux on my PC first :-)
And for those who wonder, I hope to release PIL 0.1 this weekend.
Contains *lots* of new, intriguing stuff, including Grail support.
IMAGE-SIG - SIG on Image Processing with Python
send messages to: firstname.lastname@example.org
administrivia to: email@example.com