From cgohlke at uci.edu Fri Mar 2 15:57:54 2012 From: cgohlke at uci.edu (Christoph Gohlke) Date: Fri, 02 Mar 2012 06:57:54 -0800 Subject: [Image-SIG] Problem installing PIL In-Reply-To: References: Message-ID: <4F50DFF2.7070600@uci.edu> On 2/26/2012 5:41 AM, David Craig wrote: > Hi, I recently installed basemap and python imaging library on my > laptop. I have an i686 machine with fedora 16 on it. I just tried some > test plots and basemap seems to work fine but according to the > documentation to use the bluemarble(), etopo(), shadedrelief() and > warpimage() instance methods I need PIL. SO I installed it via yum, > > $ sudo yum install python-imaging.i686 > > however only the bluemarble method works. If I try any of the others I > get the following error. > > AttributeError Traceback (most recent call last) > /usr/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in > execfile(fname, *where) > 173 else: > 174 filename = fname > --> 175 __builtin__.execfile(filename, *where) > > /home/davcra/Desktop/python_scripts/blue_marble.py in () > 10 > 11 > ---> 12 m.shadedrelief() > 13 plt.show() > > AttributeError: 'Basemap' object has no attribute 'shadedrelief' > > Anyone know what I did wrong???? > Thanks > David > > There's a reply to your question on the matplotlib-users list: Christoph From rowen at uw.edu Mon Mar 5 20:52:06 2012 From: rowen at uw.edu (Russell E. Owen) Date: Mon, 05 Mar 2012 11:52:06 -0800 Subject: [Image-SIG] How do you install PIL? References: <5B130E73-2B05-4BBE-8BC0-FD72CCE61399@mac.com> Message-ID: In article <5B130E73-2B05-4BBE-8BC0-FD72CCE61399 at mac.com>, Barry Barnett wrote: > Hi. I'm trying to install pyTivo on my Mac and it says it needs the PIL for > publish photos on my TIvo. Which version do I download and how do I install > it? I'm running a Macbook Pro with Intel core i7 processor. Thanks. There is a binary installer fpr PIL available here: but it is only compatible with python.org's 32-bit Python 2.7 (the one that is backward compatible back to Mac OS X 10.3, not the one that is 10.6-or-later). Other options: - Build it from source (not a lot of fun, but quite doable) - Use python from some other source, such as fink, MacPorts or Enthought. I suspect most or all of those have a PIL available, but check first! -- Russell From alec.taylor6 at gmail.com Wed Mar 14 11:25:48 2012 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Wed, 14 Mar 2012 21:25:48 +1100 Subject: [Image-SIG] PIL fails to install in virtualenv of one volume Message-ID: For some reason I cannot get PIL to install in a virtualenv on my F: drive, but it works fine on my C: drive. ######### F:\Users\Alec Taylor\Projects>virtualenv env_PIL && env_PIL\Scripts\activate New python executable in env_PIL\Scripts\python.exe Installing setuptools................done. Installing pip....................done. (env_PIL) F:\Users\Alec Taylor\Projects>pip install PIL Output: http://pastebin.com/VNR6rjLh [Failure] ######### So I thought it might've erred due to spaces in the path, since this worked: ######### C:\workingdir>virtualenv env_PIL && env_PIL\Scripts\activate New python executable in env_PIL\Scripts\python.exe Installing setuptools................done. Installing pip....................done. (env_PIL) C:\workingdir>pip install PIL Output: http://pastebin.com/D1exTTCU [Success] ######### But when trying with spaces in the path on the C: it worked fine: ######### C:\workingdir>mkdir "dir space\a" && cd "dir space\a" C:\workingdir\dir space\a>virtualenv env_PIL && env_PIL\Scripts\activate New python executable in env_PIL\Scripts\python.exe Installing setuptools................done. Installing pip....................done. (env_PIL) C:\workingdir\dir space\a>pip install PIL Output: http://pastebin.com/8iZpEkum [Success] ######### Also, PIL is the only thing which can't install in a virtualenv on the other volume, other things which need to link+compile; such as pycrypto, install without issue. Why isn't PIL installing in any virtualenv on my other drive? Thanks for all suggestions, Alec Taylor PS: In the meantime I will build all my virtualenvs on my C: From praveenchitneedi at gmail.com Wed Mar 14 16:35:30 2012 From: praveenchitneedi at gmail.com (praveen krishna) Date: Wed, 14 Mar 2012 16:35:30 +0100 Subject: [Image-SIG] Unable to install Pil in windows7 Message-ID: Hi, I tried to install pil in windows but it is not getting installed and generating following errors which are attached to this mailing list .I have installed Python 2.7 and I tried to perform registy by following the script in this link http://effbot.org/zone/python-register.htm but is giving error *** Unable to register! *** You probably have another Python installation! can u please help me in sorting this and to install pil in my system to run web2py application . -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: error generated for installing pil.jpg Type: image/jpeg Size: 104819 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: error generated for installing pil 01.jpg Type: image/jpeg Size: 76590 bytes Desc: not available URL: From glez_b at comunidad.unam.mx Fri Mar 16 19:52:19 2012 From: glez_b at comunidad.unam.mx (Boris Vladimir Comi) Date: Fri, 16 Mar 2012 18:52:19 +0000 Subject: [Image-SIG] Help for to do a script Message-ID: Hello, I am writing to request your help in the realization of a script. I am new to this and I'm just learning the wonderful world of python and this has made me a little difficult. Briefly I commented what I intend to do: I detect a class of atmospheric phenomena known as Mesoscale Convective Systems (MCS). To accomplish this, I have a database of satellites by 2004, every half hour. These data were downloaded from the server: unidata2.ssec.wisc.edu and data format is: 200404271515.goes12ir (Area Format) The first thing to do is detect a convective system in the satellite data, using the following characteristics: MCS Criteria Minimum Size: Continuous cold cloud shield (TIR <219 K and Must Have an area> 34000 km ?) Duration: Definition of Minimum Size Must Be A Period of Exceed or ? 3h Initiation: Time When the Minimum Size is met Maximum Extention: Time when the continuous cloud shield (TIR <219 K) is at its maximum size Termination: When the Time Minimun Size is not satisfied where: Temperature Infrarred is TIR To achieve this, first I created a script in python to identify a MCS in my database (script in attached) The script is run from a linux terminal ($ python TIR.py), to run it I get the following error: File "/home/mcidasv/JYTHON/TIR.py", line 22 count = count + 1; ^ SyntaxError: invalid syntax If anyone can help me with this script or any idea you suggest to improve it, I would greatly appreciate. Boris Vladimir Comi Gonzalez Universidad Nacional Aut?noma de M?xico Grupo de Tormentas Convecivas -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: TIR.py Type: text/x-python Size: 848 bytes Desc: not available URL: From donn.ingle at gmail.com Sat Mar 17 11:11:44 2012 From: donn.ingle at gmail.com (donn) Date: Sat, 17 Mar 2012 12:11:44 +0200 Subject: [Image-SIG] Help for to do a script In-Reply-To: References: Message-ID: <4F646360.90607@gmail.com> On 16/03/2012 20:52, Boris Vladimir Comi wrote: > if (data[0][i][j]> 199.5 and (data[0][i][j]< 200.5 > count = count + 1; Looks like the if command does not close properly. It needs a brackets and a colon. Also, you don't need to use semi-colons, at all. HTH /d From chris.barker at noaa.gov Mon Mar 19 22:53:08 2012 From: chris.barker at noaa.gov (Chris Barker) Date: Mon, 19 Mar 2012 14:53:08 -0700 Subject: [Image-SIG] Help for to do a script In-Reply-To: References: Message-ID: 1) please don't multi-post like this -- this is really a "tutor" question. i.e. your problem is very basic python On Fri, Mar 16, 2012 at 11:52 AM, Boris Vladimir Comi wrote: > I detect a class of atmospheric phenomena known as Mesoscale Convective > Systems (MCS). To accomplish this, I have a database of satellites by 2004, > every half hour. These data were downloaded from the server: > unidata2.ssec.wisc.edu and data format is: 200404271515.goes12ir (Area > Format) For this kind of work, you probably: 1) don't want to use Jython, unless there is a Java libary that will do most of the work that you want to use 2) do want to use numpy/scipy -- and likely the ndimage package: http://numpy.scipy.org/ http://www.scipy.org/SciPyPackages/Ndimage > File "/home/mcidasv/JYTHON/TIR.py", line 22 > ??? count = count + 1; debuggin hint -- when the error is not obvious, ALWAYS look at the proceeding line(s) of code: for j in xrange(ad.getElements()): if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5 count = count + 1; the "if" needs two more end-parentheses, and a colon. Also -- don't use semi-colons at the end of line -- they will just confuse you. Get a good Python-aware editor -- it will help catch these really simple kinds of syntax errors for you. Good luck, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R ? ? ? ? ? ?(206) 526-6959?? voice 7600 Sand Point Way NE ??(206) 526-6329?? fax Seattle, WA ?98115 ? ? ??(206) 526-6317?? main reception Chris.Barker at noaa.gov From barnes.leo at gmail.com Tue Mar 27 15:59:37 2012 From: barnes.leo at gmail.com (Leo Barnes) Date: Tue, 27 Mar 2012 15:59:37 +0200 Subject: [Image-SIG] GIF bug Message-ID: Hi! I have found a bug in how PIL handles animated GIFs. The GIF in question contains several frames, where each new frame only overwrites parts of the previous frame. Unless I explicitly ask PIL to load/show each frame, PIL completely skips previous frames which means that the extracted image will contain uninitialized data. Steps to reproduce: Image: http://dl.dropbox.com/u/14498565/image0006.gif #Will show uninitialized data from PIL import Image i = Image.open("image0006.gif") i.seek(1) j = i.convert("RGBA") j.show() #Seems to fix problem with uninitialized data by forcing PIL to load the previous frame #(Works most of the time, but does not seem completely reliable. The image buffer is probably uninitialized and #simply reused which can work if lucky.) from PIL import Image i = Image.open("image0006.gif") i.load() i.seek(1) j = i.convert("RGBA") j.show() Best regards, //Leo From cannon.el at gmail.com Wed Mar 14 18:22:49 2012 From: cannon.el at gmail.com (Edward Cannon) Date: Wed, 14 Mar 2012 10:22:49 -0700 Subject: [Image-SIG] Unable to install Pil in windows7 In-Reply-To: References: Message-ID: Do you have a 64 bit Python and 32 bit PIL? That can be a problem. On Mar 14, 2012, at 8:35 AM, praveen krishna wrote: > Hi, > I tried to install pil in windows but it is not getting installed and generating following errors which are attached to this mailing list .I have installed Python 2.7 and I tried to perform registy by following the script in this link http://effbot.org/zone/python-register.htm but is giving error > *** Unable to register! > *** You probably have another Python installation! > > > can u please help me in sorting this and to install pil in my system to run web2py application . > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Fri Mar 16 19:58:44 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 16 Mar 2012 14:58:44 -0400 Subject: [Image-SIG] [Tutor] Help for to do a script In-Reply-To: References: Message-ID: On Fri, Mar 16, 2012 at 2:52 PM, Boris Vladimir Comi wrote: > Hello, I am writing to request your help in the realization of a script. I > am new to this and I'm just learning the wonderful world of python and this > has made me a little difficult. > > Briefly I commented what I intend to do: > > I detect a class of atmospheric phenomena known as Mesoscale Convective > Systems (MCS). To accomplish this, I have a database of satellites by 2004, > every half hour. These data were downloaded from the server: > unidata2.ssec.wisc.edu and data format is: 200404271515.goes12ir (Area > Format) > > The first thing to do is detect a convective system in the satellite data, > using the following characteristics: > > MCS Criteria > > Minimum Size: Continuous cold cloud shield (TIR <219 K and Must Have an > area> 34000 km ?) > > Duration: Definition of Minimum Size Must Be A Period of Exceed or ? 3h > > Initiation: Time When the Minimum Size is met > > Maximum Extention: Time when the continuous cloud shield (TIR <219 K) is at > its maximum size > > Termination: When the Time Minimun Size is not satisfied > > where: Temperature Infrarred is TIR > > To achieve this, first I created a script in python to identify a MCS in my > database (script in attached) > > The script is run from a linux terminal ($ python TIR.py), to run it I get > the following error: > > > File "/home/mcidasv/JYTHON/TIR.py", line 22 > ??? count = count + 1; > ??????? ^ > SyntaxError: invalid syntax > > If anyone can help me with this script or any idea you suggest to improve > it, I would greatly appreciate. > > > > Boris Vladimir Comi Gonzalez > Universidad Nacional Aut?noma de M?xico > Grupo de Tormentas Convecivas > > _______________________________________________ > Tutor maillist ?- ?Tutor at python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > Here is your code: for i in xrange(ad.getLines()): for j in xrange(ad.getElements()): if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5 count = count + 1; print "For file",name," count = ",count Notice that this line is broken: if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5 change it to this and try running again: if (data[0][i][j] > 199.5) and (data[0][i][j] < 200.5) -- Joel Goldstick From joel.goldstick at gmail.com Fri Mar 16 19:59:45 2012 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 16 Mar 2012 14:59:45 -0400 Subject: [Image-SIG] [Tutor] Help for to do a script In-Reply-To: References: Message-ID: On Fri, Mar 16, 2012 at 2:58 PM, Joel Goldstick wrote: > On Fri, Mar 16, 2012 at 2:52 PM, Boris Vladimir Comi > wrote: >> Hello, I am writing to request your help in the realization of a script. I >> am new to this and I'm just learning the wonderful world of python and this >> has made me a little difficult. >> >> Briefly I commented what I intend to do: >> >> I detect a class of atmospheric phenomena known as Mesoscale Convective >> Systems (MCS). To accomplish this, I have a database of satellites by 2004, >> every half hour. These data were downloaded from the server: >> unidata2.ssec.wisc.edu and data format is: 200404271515.goes12ir (Area >> Format) >> >> The first thing to do is detect a convective system in the satellite data, >> using the following characteristics: >> >> MCS Criteria >> >> Minimum Size: Continuous cold cloud shield (TIR <219 K and Must Have an >> area> 34000 km ?) >> >> Duration: Definition of Minimum Size Must Be A Period of Exceed or ? 3h >> >> Initiation: Time When the Minimum Size is met >> >> Maximum Extention: Time when the continuous cloud shield (TIR <219 K) is at >> its maximum size >> >> Termination: When the Time Minimun Size is not satisfied >> >> where: Temperature Infrarred is TIR >> >> To achieve this, first I created a script in python to identify a MCS in my >> database (script in attached) >> >> The script is run from a linux terminal ($ python TIR.py), to run it I get >> the following error: >> >> >> File "/home/mcidasv/JYTHON/TIR.py", line 22 >> ??? count = count + 1; >> ??????? ^ >> SyntaxError: invalid syntax >> >> If anyone can help me with this script or any idea you suggest to improve >> it, I would greatly appreciate. >> >> >> >> Boris Vladimir Comi Gonzalez >> Universidad Nacional Aut?noma de M?xico >> Grupo de Tormentas Convecivas >> >> _______________________________________________ >> Tutor maillist ?- ?Tutor at python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > Here is your code: > > ? ? for i in xrange(ad.getLines()): > ? ? ? ? ?for j in xrange(ad.getElements()): > ? ? ? ? ? ? ?if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5 > ? ? ? ? ? ? ? ? ?count = count + 1; > ? ? ?print "For file",name," count = ",count > > Notice that this line is broken: > > ? ? ? ? ? ? ?if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5 > > change it to this and try running again: > > ? ? ? ? ? ? ?if (data[0][i][j] > 199.5) and (data[0][i][j] < 200.5): > > > -- > Joel Goldstick Sorry, also put : at end of if statements -- Joel Goldstick From wrybread at gmail.com Fri Mar 16 20:05:02 2012 From: wrybread at gmail.com (Alec Bennett) Date: Fri, 16 Mar 2012 12:05:02 -0700 Subject: [Image-SIG] Help for to do a script In-Reply-To: References: Message-ID: There's a lot wrong with it. I don't have the modules so I can't test, but you need to chnage these two lines: if (data[0][i][j] > 199.5 and (data[0][i][j] < 200.5 count = count + 1; To something like: if data[0][i][j] > 199.5 and data[0][i][j] < 200.5: count = count + 1; That's about very basic Python syntax, not the Image module, fyi. Also, cross-posting to multiple email lists is considered very bad form. On Fri, Mar 16, 2012 at 11:52 AM, Boris Vladimir Comi < glez_b at comunidad.unam.mx> wrote: > Hello, I am writing to request your help in the realization of a script. > I am new to this and I'm just learning the wonderful world of python and > this has made me a little difficult. > > Briefly I commented what I intend to do: > > I detect a class of atmospheric phenomena known as Mesoscale Convective > Systems (MCS). To accomplish this, I have a database of satellites by 2004, > every half hour. These data were downloaded from the server: > unidata2.ssec.wisc.edu and data format is: 200404271515.goes12ir (Area > Format) > > The first thing to do is detect a convective system in the satellite data, > using the following characteristics: > > *MCS Criteria* > > *Minimum Size*: Continuous cold cloud shield (TIR <219 K and Must Have an > area> 34000 km ?) > > *Duration*: Definition of Minimum Size Must Be A Period of Exceed or ? 3h > > *Initiation*: Time When the Minimum Size is met > * > Maximum Extention*: Time when the continuous cloud shield (TIR <219 K) is > at its maximum size > > *Termination:* When the Time Minimun Size is not satisfied > > where: Temperature Infrarred is TIR > > To achieve this, first I created a script in python to identify a MCS in my > database (script in attached) > > The script is run from a linux terminal ($ python TIR.py), to run it I get the > following error: > > > *File "/home/mcidasv/JYTHON/TIR.py", line 22 > count = count + 1; > ^ > SyntaxError: invalid syntax* > > If anyone can help me with this script or any idea you suggest to improve > it, I would greatly appreciate. > > > > ****Boris Vladimir Comi Gonzalez > Universidad Nacional Aut?noma de M?xico > Grupo de Tormentas Convecivas > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From regebro at gmail.com Fri Mar 16 20:14:59 2012 From: regebro at gmail.com (Lennart Regebro) Date: Fri, 16 Mar 2012 20:14:59 +0100 Subject: [Image-SIG] [Python-porting] Help for to do a script In-Reply-To: References: Message-ID: This mailing list is about porting from Python 2 to Python 3. For help with specific programming errors I recommend stackoverflow.com. ps. the error you made is probably on the row before On Fri, Mar 16, 2012 at 19:52, Boris Vladimir Comi wrote: > Hello, I am writing to request your help in the realization of a script. I > am new to this and I'm just learning the wonderful world of python and this > has made me a little difficult. > > Briefly I commented what I intend to do: > > I detect a class of atmospheric phenomena known as Mesoscale Convective > Systems (MCS). To accomplish this, I have a database of satellites by 2004, > every half hour. These data were downloaded from the server: > unidata2.ssec.wisc.edu and data format is: 200404271515.goes12ir (Area > Format) > > The first thing to do is detect a convective system in the satellite data, > using the following characteristics: > > MCS Criteria > > Minimum Size: Continuous cold cloud shield (TIR <219 K and Must Have an > area> 34000 km ?) > > Duration: Definition of Minimum Size Must Be A Period of Exceed or ? 3h > > Initiation: Time When the Minimum Size is met > > Maximum Extention: Time when the continuous cloud shield (TIR <219 K) is at > its maximum size > > Termination: When the Time Minimun Size is not satisfied > > where: Temperature Infrarred is TIR > > To achieve this, first I created a script in python to identify a MCS in my > database (script in attached) > > The script is run from a linux terminal ($ python TIR.py), to run it I get > the following error: > > > File "/home/mcidasv/JYTHON/TIR.py", line 22 > ??? count = count + 1; > ??????? ^ > SyntaxError: invalid syntax > > If anyone can help me with this script or any idea you suggest to improve > it, I would greatly appreciate. > > > > Boris Vladimir Comi Gonzalez > Universidad Nacional Aut?noma de M?xico > Grupo de Tormentas Convecivas > > _______________________________________________ > Python-porting mailing list > Python-porting at python.org > http://mail.python.org/mailman/listinfo/python-porting > From glez_b at comunidad.unam.mx Fri Mar 16 22:46:19 2012 From: glez_b at comunidad.unam.mx (Boris Vladimir Comi) Date: Fri, 16 Mar 2012 21:46:19 +0000 Subject: [Image-SIG] Help whith script Message-ID: Hello, corrected the code and it runs correctly. I run the script through a program called McIDAS-V. I guess when i run the script (TIR.py) as follows: / home / mcidasv / McIDAS-V-System / runMcV-islfile scm.py refers to the module AreaFile. My database is composed of monthly and is the Following: 200406010000.goes10ir 200406010000.goes10vis 200406010000.goes10wv 200406010000.goes12ir 200406010000.goes12vis 200406010000.goes12wv Each has 3 channels: ir(infrarred), vis (visible), wv(water vapor) with four variables: raw, radiance, brightness and temperature . I actually only interested in data format .goes12ir and variable temperature. How I can make that filter data and where in the code could add that filter ? After filtering the database, how could calculate the area of ??the cloud shield whose temperature is <219 K (see purple line in attached)? Note: when I deploy a data(200406010000.goes12ir) in the McIDAS-V, I get a satellite image that represents different values ??of brightness temperatures associated with the cloud that appears in the satellite image (see image in attached) Boris Vladimir Comi Gonzalez Universidad Nacional Aut?noma de M?xico Grupo de Tormentas Convecivas -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: TIR.py Type: text/x-python Size: 829 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: IMAGE-IR.jpg Type: image/jpeg Size: 333189 bytes Desc: not available URL: From david at d-austin.net Wed Mar 21 01:33:48 2012 From: david at d-austin.net (David Austin) Date: Wed, 21 Mar 2012 11:33:48 +1100 Subject: [Image-SIG] BUG: convert to greyscale errors Message-ID: Hi all, I've found an incorrect dependency upon neighbouring pixels in conversion to greyscale. Running this simple script (against attached images): import Image im1 = Image.open('a.png') im2 = Image.open('b.png') pt = (301, 72) print "Before", im1.getpixel(pt), im2.getpixel(pt) im1 = im1.convert("P") im2 = im2.convert("P") print "After", im1.getpixel(pt), im2.getpixel(pt) Gives: Before (63, 73, 50) (63, 73, 50) After 60 59 i.e. before conversion the RGB values are identical, after the greyscale values are not. Regards, David -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: a.png Type: image/png Size: 198097 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: b.png Type: image/png Size: 198078 bytes Desc: not available URL: From b.canatan at student.rug.nl Mon Mar 26 01:20:19 2012 From: b.canatan at student.rug.nl (B.Canatan) Date: Mon, 26 Mar 2012 01:20:19 +0200 Subject: [Image-SIG] PIL on Python 2.7? Message-ID: <7610a32e8be1b.4f6fc453@rug.nl> ?Hi all, Will PIL work on Python 2.7 (on a Linux machine)? Sincerely, Baris -------------- next part -------------- An HTML attachment was scrubbed... URL: From olt at bogosoft.com Wed Mar 28 07:57:14 2012 From: olt at bogosoft.com (Oliver Tonnhofer) Date: Wed, 28 Mar 2012 07:57:14 +0200 Subject: [Image-SIG] BUG: convert to greyscale errors In-Reply-To: References: Message-ID: <6F6E7F5A-64E2-4048-A2AB-8B42380BEAE3@bogosoft.com> Hi, On 21.03.2012, at 01:33, David Austin wrote: > I've found an incorrect dependency upon neighbouring pixels in conversion to > greyscale. Running this simple script (against attached images): > > import Image > im1 = Image.open('a.png') > im2 = Image.open('b.png') > pt = (301, 72) > print "Before", im1.getpixel(pt), im2.getpixel(pt) > im1 = im1.convert("P") > im2 = im2.convert("P") This will convert the image to a paletted image. > Before (63, 73, 50) (63, 73, 50) > After 60 59 And this is not the gray-value but an index to the color palette. This palette will look different if the images differ. From gdr at garethrees.org Sat Mar 31 18:22:59 2012 From: gdr at garethrees.org (Gareth Rees) Date: Sat, 31 Mar 2012 17:22:59 +0100 Subject: [Image-SIG] BUG: PNG files with zTXt chunk can't be read incrementally Message-ID: <9E4707CF-339D-4C99-A0C9-3C7F56C18981@garethrees.org> SUMMARY A PNG file containing a compressed text (zTXt) chunk prior to the first IDAT chunk cannot reliably be read by feeding it in chunks to an ImageFile.Parser object. STEPS TO REPRODUCE Create a PNG image with a zTXt chunk prior to the first IDAT chunk: from PngImagePlugin import _MAGIC, putchunk import struct, zlib with open('bug2.png', 'wb') as f: f.write(_MAGIC) putchunk(f, 'IHDR', struct.pack('>IIBBBBB', 1, 1, 1, 0, 0, 0, 0)) putchunk(f, 'zTXt', 'key\0\0' + zlib.compress('value')) putchunk(f, 'IDAT', zlib.compress(struct.pack('>BB', 0, 0))) putchunk(f, 'IEND', '') The image (and its zTXt chunk) loads correctly via Image.open: >>> Image.open('bug2.png') >>> _.info {'key': 'value'} But if you feed a chunk of this image to an ImageFile.Parser then you can get a ValueError: >>> ImageFile.Parser().feed(open('bug.png', 'rb').read(41)) Traceback (most recent call last): File "", line 1, in File "ImageFile.py", line 402, in feed im = Image.open(fp) File "Image.py", line 1965, in open return factory(fp, filename) File "ImageFile.py", line 91, in __init__ self._open() File "PngImagePlugin.py", line 331, in _open s = self.png.call(cid, pos, len) File "PngImagePlugin.py", line 115, in call return getattr(self, "chunk_" + cid)(pos, len) File "PngImagePlugin.py", line 291, in chunk_zTXt k, v = string.split(s, "\0", 1) ValueError: need more than 1 value to unpack or a zlib.error: >>> ImageFile.Parser().feed(open('bug.png', 'rb').read(50)) Traceback (most recent call last): File "", line 1, in File "ImageFile.py", line 402, in feed im = Image.open(fp) File "Image.py", line 1965, in open return factory(fp, filename) File "ImageFile.py", line 91, in __init__ self._open() File "PngImagePlugin.py", line 331, in _open s = self.png.call(cid, pos, len) File "PngImagePlugin.py", line 115, in call return getattr(self, "chunk_" + cid)(pos, len) File "PngImagePlugin.py", line 296, in chunk_zTXt self.im_info[k] = self.im_text[k] = zlib.decompress(v[1:]) zlib.error: Error -5 while decompressing data: incomplete or truncated stream HISTORY This bug was previously reported by Eddie Bishop in June 2011 ANALYSIS The immediate cause of the error is that PngStream.chunk_zTXt in PngImagePlugin.py gets called with an incomplete chunk. The method looks like this: def chunk_zTXt(self, pos, len): s = ImageFile._safe_read(self.fp, len) k, v = string.split(s, "\0", 1) comp_method = ord(v[0]) if comp_method != 0: raise SyntaxError("Unknown compression method %s in zTXt chunk" % comp_method) import zlib self.im_info[k] = self.im_text[k] = zlib.decompress(v[1:]) return s When feeding the data to the parser, the _safe_read may return a short chunk (fewer than len bytes), and so either the call to string.split may fail (because the chunk ended mid-key), or else the call to zlib.decompress may fail. WORKAROUND I think the simplest workaround is for chunk_zTXt to abort if the read is short. The IOError will be caught by ImageFile.Parser.feed. def chunk_zTXt(self, pos, length): s = ImageFile._safe_read(self.fp, length) if len(s) != length: raise IOError # rest of function unchanged (Note that I've had to change the argument name "len" to "length" to avoid shadowing the built-in.) RELATED BUGS I have not attempted to make test cases for any of the other chunk types, but from reading the code it looks as if tRNS, gAMA, and pHYs chunks could also fail in similar ways if there is a short read. (tEXt chunks appear to be safe, but I think that's by luck rather than good planning.) These related bugs could all be worked around in the same way (that is, by raising an IOError in the event of a short read). If you need me to make test cases, let me know. -- Gareth Rees