show image in python

mohamed issolah isso.moh at gmail.com
Wed Mar 10 17:03:50 EST 2010


Hey, This is my program

 1 #!/usr/bin/python
  2 import PIL
  3 import numpy
  4 import Image
  5 import ImageOps
  6 import sys
  7
  8 def Matimg(path):
  9         """transforme image en matrice"""
 10         Img = Image.open(str(path))
 11         Img1 = ImageOps.grayscale(Img)
 12         largeur,hauteur = Img1.size
 13         imdata = Img1.getdata()
 14         tab = numpy.array(imdata)
 15         matrix = numpy.reshape(tab,(hauteur,largeur))
 16         return matrix
 17
 18 def Creeimg():
 19         """transforme matrice en image"""
 20         img = Image.new ("L",(8,8))
 21         matrix = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
 22         img.putdata(matrix)
 23         img.show()
 24         img.save(fp="./ana.bmp")
 25
 26 if  __name__== '__main__':
 27     if len(sys.argv) < 2 :
 28         print "Usage: img.py <image>"
 29         sys.exit(0)
 30     path = sys.argv[1]
 31     matrix = Matimg(path)
 32     print matrix
 33     Creeimg()

My probeleme : In line 23 "img.show()" Don't work, normally I show the image
but it's not work, but strangely in line 24 "img.save(fp="./ana.bmp")" it's
work
WHERE IS THE PROBLEME.

I have this error in shell : "(eog:3176): GLib-WARNING **: GError set over
the top of a previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL
before it's set.
The overwriting error message was: Error in getting image file info "


os: ubuntu 9.10

sorry for my english. ;-)

-- 
issolah mohamed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100310/90b1af54/attachment.html>


More information about the Python-list mailing list