[Image-SIG] Question from a newbie

D. Lopez-De-Ipina dl231@eng.cam.ac.uk
Thu, 17 Feb 2000 17:18:54 +0000 (GMT)


Hi,

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, " ")
    data.append(int(dataLine[:iPos]))
    dataLine = dataLine[iPos+1:]
im = Image.fromstring("L", (320,240), data )

imageFile.close()
    
UI(root, im).pack()

root.mainloop()

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

Regards,

Diego