From singer@itl.atr.co.jp Tue Dec 2 14:04:39 1997 From: singer@itl.atr.co.jp (Harald Singer) Date: Tue, 02 Dec 1997 23:04:39 +0900 Subject: [IMAGE-SIG] [Q] PIL problems: install, palette Message-ID: <34841577.42BEEE4@itl.atr.co.jp> Hi, we just tried to install PIL on Linux, HP-UX, OSF1 and SunOS and we ran into several interesting (boring?) problems. Our final goal is to display some nice colourful spectrograms (like in matlab). 1] basic install problems 1a] python: can't resolve symbol 'ImagingCrack' solution: commented out _crack in _imagingmodule.c 1b] the configure script is seriously broken when trying to use libz and and libjpeg that are not in /usr/local/lib and /usr/local/include solution: patched the Makefile by hand 1c] the makefiles are not setup for dealing with libjpeg.so and libz.so solution: patched Setup.in JPEGLIB = -L$(MYSHLIB) -ljpeg 2] on HP-UX9.05, the 'make test' gives completely different results when compiling with gcc and cc. Lena appears but is heavily discoloured when using gcc. With cc, it looks more like a 'photoshop' job. I have the suspicion that the cc version is correct. How can I find out? 3] some examples simply don't run. >>> im = Image.open('/home/singer/data/gaijin.ppm') >>> box = (100, 100, 200, 200) >>> region = im.crop(box) >>> region = region.transpose(Image.ROTATE_180) Traceback (innermost last): File "", line 1, in ? File "/home/singer/lib/python/Imaging/Image.py", line 591, in transpose return self._makeself(im) File "/home/singer/lib/python/Imaging/Image.py", line 219, in _makeself new.palette = self.palette AttributeError: palette I can hack this and then it seems to work. region.palette=None; region.info={} [4] I am reading a .jpg and trying to save as .gif and get this error: IOError: cannot save mode RGB as GIF What am I doing wrong? [5] in Lib/ImageTk.py the line mode = image.palette.mode fails for mode == "P". If I hardcode it to mode = "RGB" it seemed to work (for my special case). class PhotoImage: def __init__(self, mode, size = None, **kw): if hasattr(mode, "mode") and hasattr(mode, "size"): # got an image instead of a mode image = mode mode = image.mode if mode == "P": # palette mapped data image.load() mode = image.palette.mode size = image.size kw["width"], kw["height"] = size else: image = None if mode not in ["1", "L", "RGB", "RGBA"]: if mode == "F": mode = "L" else: mode = "RGB" self.__mode = mode self.__size = size self.__photo = apply(Tkinter.PhotoImage, (), kw) self.image = self.__photo # compatibility if image: self.paste(image) [6] will this still be freeware? I find it slightly disconcerting that the binary version for Windows is more advanced than the source code. Last not least, I was pretty impressed by this software (that's why I spent some time to oompile it on all our architectures). BTW, I found some contributed palette code (around December 96) but it looks like it would seriously break some other code. -- Harald Singer, ATR ITL, tel +81-7749-5-1389 singer@itl.atr.co.jp _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From fredrik@pythonware.com Wed Dec 3 19:44:19 1997 From: fredrik@pythonware.com (Fredrik Lundh) Date: Wed, 3 Dec 1997 20:44:19 +0100 Subject: [IMAGE-SIG] [Q] PIL problems: install, palette Message-ID: <01bd0023$d8976de0$6fadb4c1@fl-pc.image.ivab.se> Harald Singer writes: >we just tried to install PIL on Linux, HP-UX, OSF1 and SunOS and we >ran into several interesting (boring?) problems. Our final goal is to >display some nice colourful spectrograms (like in matlab). > >1] basic install problems >1a] python: can't resolve symbol 'ImagingCrack' > solution: commented out _crack in _imagingmodule.c >1b] the configure script is seriously broken when trying to use libz = and > and libjpeg that are not in /usr/local/lib and /usr/local/include > solution: patched the Makefile by hand >1c] the makefiles are not setup for dealing with libjpeg.so and libz.so > solution: patched Setup.in > JPEGLIB =3D -L$(MYSHLIB) -ljpeg 1a is fixed in the next release; I'm not sure how to handle 1b (I've advertised for autoconf gurus before, with no result). I'll do some- thing about 1c in the next release. >2] on HP-UX9.05, the 'make test' gives completely different results = when=20 >compiling with gcc and cc. Lena appears but is heavily discoloured when >using gcc. With cc, it looks more like a 'photoshop' job. >I have the suspicion that the cc version is correct. How can I find = out? This might be due to a buglet in Paste.c; check the defines at the top of the file, and make sure they look like: #define MULDIV255(a, b, tmp)\ (tmp =3D (int) (a) * (b) + 128, (((tmp >> 8) + tmp) >> 8)) #define BLEND(mask, in1, in2, tmp)\ MULDIV255(in1, 255 - mask, tmp) + MULDIV255(in2, mask, tmp) #define COMPOSE(mask, in1, in2, tmp)\ MULDIV255(in1, 255 - mask, tmp) + in2 >3] some examples simply don't run. >AttributeError: palette fixed in the current codebase; will make it into the next release. >[4] I am reading a .jpg and trying to save as .gif >and get this error: > IOError: cannot save mode RGB as GIF >What am I doing wrong? 0.3a1 and earlier cannot convert from RGB (24-bit) to palette images :-( Will be fixed in 0.3 final (and is also the reason there's no 0.3 final = yet... just haven't had the time to do something about it). >[5] in Lib/ImageTk.py >the line=20 > mode =3D image.palette.mode >fails for mode =3D=3D "P". IIRC, this has also been fixed in the current codebase. >[6] will this still be freeware? I find it slightly disconcerting that >the binary version for Windows is more advanced than the source >code. That's mainly because I haven't had time to move the stuff from the development machine (at home) to a Unix box (at work), and wrap it up in a nice tarball... And yes, PIL will be free also in the future, even if the copyright may be transferred to Secret Labs AB in the next release. But we'll probably release a few commercial add-ons during the next year; there are lots of cool things being worked on over at the labs. Cheers /F fredrik@pythonware.com http://www.pythonware.com _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From khilman@equator.com Fri Dec 5 01:17:04 1997 From: khilman@equator.com (Kevin Hilman) Date: 04 Dec 1997 17:17:04 -0800 Subject: [IMAGE-SIG] Interlaced images? Message-ID: Is there any modules for handling interlaced images? For example calling split() on an image could give you 2 images, one being the top field (even lines) and the other being the bottom field (odd lines) On a related note, by now someone must have written a ImageFile class for handling YUV (or YCbCr) images in 4:2:0 or 4:2:2, right? Thanks. -- Kevin Hilman _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From fredrik@pythonware.com Fri Dec 5 10:49:28 1997 From: fredrik@pythonware.com (Fredrik Lundh) Date: Fri, 5 Dec 1997 11:49:28 +0100 Subject: [IMAGE-SIG] Interlaced images? Message-ID: <01bd016b$75fec040$6fadb4c1@fl-pc.image.ivab.se> >Is there any modules for handling interlaced images? For example >calling split() on an image could give you 2 images, one being >the top field (even lines) and the other being the bottom field (odd >lines) =20 Just use use the transform method: def getfield(im, field=3D0): x, y =3D im.size if field: box =3D (0, 0.5, x, y+0.5) else: box =3D (0, -0.5, x, y-0.5) return im.transform((x, y/2), Image.EXTENT, box) >On a related note, by now someone must have written a ImageFile class >for handling YUV (or YCbCr) images in 4:2:0 or 4:2:2, right? Hmm. You can actually handle the YUV=3D>RGB mapping via a "colour twist" transform, but there's no code in there to handle subsampled video modes. Maybe there's something in the standard "imageop" module that could be used together with tostring/fromstring... if you cannot sort it out yourself, mail me a format description and a sample or two, and I'll see what I can do. Cheers /F fredrik@pythonware.com http://www.pythonware.com _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From gulliver@mic.atr.co.jp Sat Dec 6 14:20:37 1997 From: gulliver@mic.atr.co.jp (Lopez-Gulliver, Roberto) Date: Sat, 6 Dec 1997 23:20:37 +0900 (JST) Subject: [IMAGE-SIG] Problems with *tostring* on PPM images [PILv0.3a1] Message-ID: Hi there, I'm having problems with *tostring* on PPM images [PILv0.3a1]. This used to work OK with PILv0.2b3, can any one out there enlighten me on this? Oopps, I'm in a SGI with IRIX6.2 it this helps at all. This is what I get: gulliver % python Python 1.4 (Mar 11 1997) [C] Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import Image import Image >>> im = Image.open ("image.ppm") im = Image.open ("image.ppm") >>> print im print im >>> data = im.tostring () data = im.tostring () Traceback (innermost last): File "", line 1, in ? File "/home/gulliver/PYTHON/PIL/Image.py", line 244, in tostring self.load() File "/home/gulliver/PYTHON/PIL/ImageFile.py", line 109, in load self.im = Image.core.new(self.mode, self.size) ValueError: Illegal mode >>> print im.mode 'RGB' >>> ???? Any clues/hints? Thanks for any/all help. --Roberto BTW, I have problems tracking what's the latest(best?) version of PIL. I have PILv0.3a1 and PIILv0.2b3 from the starship and python sites respectively. Also the manual/handbook say nothing about *to|fromstring* making its use misterous. Of course, by looking at the source anybody can see what they do but... ----------------------------------------------------------- Roberto Lopez Gulliver ATR Media Integration & Communications Research Labs. 2-2 Hikaridai / Seika-cho, Soraku-gun / Kyoto 619-02, JAPAN tel: +81-774-95-1455 gulliver@mic.atr.co.jp fax: +81-774-95-1408 http://www.mic.atr.co.jp/~gulliver ----------------------------------------------------------- _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From john1@icubed.com Fri Dec 12 13:40:03 1997 From: john1@icubed.com (Shichang Zhao) Date: Fri, 12 Dec 1997 08:40:03 -0500 Subject: No subject Message-ID: <9712121333.AA32312@infobahn.icubed.com> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Platform: Window NT 4.0 Compiler: Microsoft Visual C++ Developer's Studio Version: 5.0, Enterprise Edition Python version: 1.5b1 Source PIL version: 0.3a1 Compilation Error from VC 5.0: C:\Python-1.5b1\Imaging\Tk\tkImaging.c(73) : error C2198: 'Tk_FindPhoto' : too few actual parameters The line that creates this error: photo = Tk_FindPhoto(argv[1]); >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Check Tcl/Tk 8.0 source distribution, I see the function of Tk_FindPhoto is of the following protocol: EXTERN Tk_PhotoHandle Tk_FindPhoto _ANSI_ARGS_((Tcl_Interp *interp char *imageName)); Question: Should I change the function call to be: photo = Tk_FindPhoto(interp, argv[1]); Another thing is: I can not find the Cracker.c file. Is it supposed to have this file, or not? and where can I get it. Shichang Zhao, PSA member. Software Engineer Computer People, Inc. _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From fredrik@pythonware.com Fri Dec 12 14:34:16 1997 From: fredrik@pythonware.com (Fredrik Lundh) Date: Fri, 12 Dec 1997 15:34:16 +0100 Subject: [IMAGE-SIG] Re: findphoto/cracker.c Message-ID: <01bd070b$06088be0$6fadb4c1@fl-pc.image.ivab.se> >Question: > Should I change the function call to be: > photo =3D Tk_FindPhoto(interp, argv[1]); Correct. Sun changed the Tk API in 8.0 final. >Another thing is: I can not find the Cracker.c file. Is it supposed to = have >this file, or not? It's a glitch in the distribution. Just comment away the reference to the ImagingCrack function in _imagingmodule.c. Cheers /F _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From john1@icubed.com Fri Dec 12 14:39:41 1997 From: john1@icubed.com (Shichang Zhao) Date: Fri, 12 Dec 1997 09:39:41 -0500 Subject: [IMAGE-SIG] Re: findphoto/cracker.c Message-ID: <9712121432.AA14630@infobahn.icubed.com> Thanks, /F. A newbie question: for the following code: import Image im = Image.open("lena.ppm") im.show() Why I can not see the image under Windows NT 4.0? or I have to view the image in Tkinter? This relates to the question of: Does Tkinter calls back to Image or Image get a new instance of Tcl Interpretor and display the image? ---------- From: Fredrik Lundh To: Shichang Zhao ; image-sig@python.org Subject: Re: findphoto/cracker.c Date: Friday, December 12, 1997 9:34 AM >Question: > Should I change the function call to be: > photo = Tk_FindPhoto(interp, argv[1]); Correct. Sun changed the Tk API in 8.0 final. >Another thing is: I can not find the Cracker.c file. Is it supposed to have >this file, or not? It's a glitch in the distribution. Just comment away the reference to the ImagingCrack function in _imagingmodule.c. Cheers /F ---------- _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From fredrik@pythonware.com Fri Dec 12 15:24:15 1997 From: fredrik@pythonware.com (Fredrik Lundh) Date: Fri, 12 Dec 1997 16:24:15 +0100 Subject: [IMAGE-SIG] Re: findphoto/cracker.c Message-ID: <01bd0712$01eda840$6fadb4c1@fl-pc.image.ivab.se> > Why I can not see the image under Windows NT 4.0? or > I have to view the image in Tkinter? There's some hackish code in 0.3 that displays the image if 1) you've already initialized Tkinter (by creating a Tk instance), and 2) you've entered the Tkinter mainloop. I don't really like that solution, so I'm probably going to remove it in the next release... However, displaying an image under Tkinter is pretty straight- forward (provided you have linked Tk with the PIL extensions): from Tkinter import * import Image, ImageTk root =3D Tk() photo =3D ImageTk.PhotoImage(Image.open("foo.ppm")) w =3D Label(root, image=3Dphoto) w.pack() mainloop() You'll find more info on the ImageTk module at: http://www.pythonware.com/library/pil/handbook/imagetk.htm Also see the viewer.py and other sample scripts provided with the distribution. Cheers /F _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________ From john1@icubed.com Fri Dec 12 18:26:52 1997 From: john1@icubed.com (Shichang Zhao) Date: Fri, 12 Dec 1997 13:26:52 -0500 Subject: [IMAGE-SIG] Python15/Imaging Message-ID: <9712121819.AA28438@infobahn.icubed.com> Are there any plans regarding a new release of PIL for Python 15. I tried to compile Imaging Version 0.3a with Python 15b2. I can get the DLL, but when I tried to run a demo, I got the following message: c:\Python15\ImgDemo>python viewer.py lena.ppm python viewer.py lena.ppm Traceback (innermost last): File "viewer.py", line 44, in ? UI(root, im).pack() File "viewer.py", line 23, in __init__ self.image = ImageTk.PhotoImage(im) File "C:\Python15\lib\Imaging\ImageTk.py", line 65, in __init__ self.paste(image) File "C:\Python15\lib\Imaging\ImageTk.py", line 81, in paste self.__photo.tk.call("PyImagingPhoto", self.__photo, block.id) TclError: invalid command name "PyImagingPhoto" The following is what I did: 1. modify the tkappinit.c file and add: extern void TkImaging_Init(Tcl_Interp* interp); TkImaging_Init(interp); I added it. 2. See the Unix section. Instead of modifying the Setup file, just add tkImaging.c and tkappinit.c to the project file, and -DWITH_APPINIT to the _tkinter.c compile options. I am not clear which project file I should add these two .c files. So, I tried to add them to Tkinter project file first, and then Imaging project file. Both of them gave me the same error (above). What's the mistake I made? _______________ IMAGE-SIG - SIG on Image Processing with Python send messages to: image-sig@python.org administrivia to: image-sig-request@python.org _______________