Re: show image in python

Discussion in 'Python' started by Philip Semanchuk, Mar 11, 2010.

  1. On Mar 10, 2010, at 5:03 PM, mohamed issolah wrote:

    > 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


    Hi issolah,
    I don't know what your problem is but I have a few suggestions --
    1) You say that img.show() doesn't work. How does it fail? Is that
    where you get the GLib warning?
    2) I'm glad you posted your code, but because it has line numbers,
    it's awkward to copy & paste into a local example. Please show your
    code without line numbers.

    I'm unfamiliar with PIL, so this is just a wild guess, but based on
    the GLib error it seems like you haven't initialized something
    properly. Sorry I couldn't be more helpful. Maybe someone who knows
    more will answer.

    Good luck
    Philip
    Philip Semanchuk, Mar 11, 2010
    #1
    1. Advertising

  2. Philip Semanchuk

    News123 Guest

    Philip Semanchuk wrote:
    >
    > On Mar 10, 2010, at 5:03 PM, mohamed issolah wrote:
    >
    >> Hey, This is my program
    >>


    >> 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


    >>
    >> My probeleme : In line 23 "img.show()" Don't work, normally I show the
    >> image


    Image show is implemented rather half heartedly (at least on linux)

    a potential reasons is:
    - you didn not install the correct image viewer tool (You should see an
    error message though". Then you could try to install the tool, that
    python did not find.


    depending on the platform, you might have bugs, that don't allow to view
    more than one image at a time / etc.

    potentially you might be better of by just using
    a hand rolled os.system()
    or subprocess.Popen call


    bye

    N





    >> 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

    >
    > Hi issolah,
    > I don't know what your problem is but I have a few suggestions --
    > 1) You say that img.show() doesn't work. How does it fail? Is that where
    > you get the GLib warning?
    > 2) I'm glad you posted your code, but because it has line numbers, it's
    > awkward to copy & paste into a local example. Please show your code
    > without line numbers.
    >
    > I'm unfamiliar with PIL, so this is just a wild guess, but based on the
    > GLib error it seems like you haven't initialized something properly.
    > Sorry I couldn't be more helpful. Maybe someone who knows more will answer.
    >
    > Good luck
    > Philip
    >
    >
    >
    >
    >
    News123, Mar 12, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt

    TO show or NOT to show

    Matt, May 2, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    379
  2. Joe
    Replies:
    0
    Views:
    661
  3. Disco Octopus

    to show image or to show flash

    Disco Octopus, May 13, 2004, in forum: HTML
    Replies:
    7
    Views:
    2,419
    Toby A Inkster
    May 14, 2004
  4. =?Utf-8?B?am9l?=
    Replies:
    2
    Views:
    3,386
    Winista
    Jul 24, 2006
  5. handersonVA

    clicking small image to show a big image

    handersonVA, Nov 28, 2005, in forum: Javascript
    Replies:
    6
    Views:
    456
    Thomas 'PointedEars' Lahn
    Dec 1, 2005
Loading...

Share This Page