[Image-SIG] Question from a newbie

Kevin Cazabon KCAZA@cymbolic.com
Thu, 17 Feb 2000 09:41:31 -0800

How about something simpler...

import string, Image, array

file = open(filename, 'r')

text = file.readlines()
text = string.split(text) #defaults to splitting on any white space, returning a list

data = array.array('B', text).tostring()
datasize = (320,240)
im = Image.fromstring('L', datasize, data)

>>> "D. Lopez-De-Ipina" <dl231@eng.cam.ac.uk> 02/17/00 09:18AM >>>

I have just started today having a look to PIL, I need to display an image
composed by a matrix of greyscale values saved to a file. The file
contains one line for each image pixel row and separates each pixel's
greyscale value by an space.

I have been trying for a while to modify the example Scripts/viewer.py to
create a new image using method Image.fromstring. However, I haven't had
much success yet. I know it must have been a very silly and simple mistake
but I can not see it. What I do is the following:

imageFile = open(filename)
data = array.array("i")
for iRow in range(240):
  dataLine = imageFile.readline()   
  for iCol in range(320):
    iPos = string.find(dataLine, " ")
    dataLine = dataLine[iPos+1:]
im = Image.fromstring("L", (320,240), data )

UI(root, im).pack()


If anybody could point out what I have done wrong I would be very



Image-SIG maillist  -  Image-SIG@python.org