From kta719 at mail.usask.ca Wed Aug 6 17:45:36 2008 From: kta719 at mail.usask.ca (Kristofor Amundson) Date: Wed, 06 Aug 2008 09:45:36 -0600 (CST) Subject: [Image-SIG] Multi-threading and PIL Message-ID: <474877.1218037539065.JavaMail.kta719@mail.usask.ca> Hi, I am writing a Python script that is performing lots of pixel-based image comparisons and I'm using PIL's PixelAccess object to do this. In order to improve my performance I've attempted to multi-thread the pixel access using Python's threading module. My problem is that I see little to no improvement in my performance with the threading, even when I process the images on a machine with 8 CPU's. In fact, it only seems to utilize one CPU. Is this due to the GIL? I am wondering if there is a way for me to properly thread this to improve my performance. Thank you very much. Kristofor Amundson From frederic.mantegazza at gbiloba.org Wed Aug 6 19:17:49 2008 From: frederic.mantegazza at gbiloba.org (=?iso-8859-15?q?Fr=E9d=E9ric?=) Date: Wed, 6 Aug 2008 19:17:49 +0200 Subject: [Image-SIG] Multi-threading and PIL In-Reply-To: <474877.1218037539065.JavaMail.kta719@mail.usask.ca> References: <474877.1218037539065.JavaMail.kta719@mail.usask.ca> Message-ID: <200808061917.49590.frederic.mantegazza@gbiloba.org> On mercredi 06 ao?t 2008, Kristofor Amundson wrote: > I am writing a Python script that is performing lots of pixel-based > image comparisons and I'm using PIL's PixelAccess object to do this. In > order to improve my performance I've attempted to multi-thread the > pixel access using Python's threading module. > > My problem is that I see little to no improvement in my performance > with the threading, even when I process the images on a machine with 8 > CPU's. In fact, it only seems to utilize one CPU. Is this due to the > GIL? I am wondering if there is a way for me to properly thread this to > improve my performance. Due to the global lock in python, threads can't be executed concurrently; you need to switch to processes. Someone proposed me to use the 'processing' module: http://pyprocessing.berlios.de which will be in standard in future python versions. I didn't make tests yet, but this section seems interesting, and very simple to use: http://pyprocessing.berlios.de/doc/pool-objects.html Hope this help. -- Fr?d?ric http://www.gbiloba.org From spe.stani.be at gmail.com Wed Aug 6 19:49:31 2008 From: spe.stani.be at gmail.com (Stani) Date: Wed, 06 Aug 2008 19:49:31 +0200 Subject: [Image-SIG] Multi-threading and PIL In-Reply-To: <474877.1218037539065.JavaMail.kta719@mail.usask.ca> References: <474877.1218037539065.JavaMail.kta719@mail.usask.ca> Message-ID: <1218044971.8832.11.camel@blue> Op woensdag 06-08-2008 om 09:45 uur [tijdzone -0600], schreef Kristofor Amundson: > My problem is that I see little to no improvement in my performance > with the threading, even when I process the images on a machine with 8 > CPU's. In fact, it only seems to utilize one CPU. Is this due to the > GIL? Probably so. > I am wondering if there is a way for me to properly thread this to > improve my performance. I use mostly subprocess pools to increase multi-core performance, but of course this might be not evident to implement depending on the specifics of your software. That is the only way to take advantage of multi-core CPU (or of course stackless python). To speed up your existing code, you might also give psyco a try (which is again in active development), profile your code and rewrite some parts in cython or wait for PyPy to mature. Stani From haase at msg.ucsf.edu Wed Aug 6 21:01:46 2008 From: haase at msg.ucsf.edu (Sebastian Haase) Date: Wed, 6 Aug 2008 21:01:46 +0200 Subject: [Image-SIG] Multi-threading and PIL In-Reply-To: <1218044971.8832.11.camel@blue> References: <474877.1218037539065.JavaMail.kta719@mail.usask.ca> <1218044971.8832.11.camel@blue> Message-ID: For pixel-by-pixel stuff you would probably be much (!) faster using numpy. - Sebastian Haase On Wed, Aug 6, 2008 at 7:49 PM, Stani wrote: > Op woensdag 06-08-2008 om 09:45 uur [tijdzone -0600], schreef Kristofor > Amundson: > >> My problem is that I see little to no improvement in my performance >> with the threading, even when I process the images on a machine with 8 >> CPU's. In fact, it only seems to utilize one CPU. Is this due to the >> GIL? > Probably so. > >> I am wondering if there is a way for me to properly thread this to >> improve my performance. > I use mostly subprocess pools to increase multi-core performance, but of > course this might be not evident to implement depending on the specifics > of your software. That is the only way to take advantage of multi-core > CPU (or of course stackless python). > > To speed up your existing code, you might also give psyco a try (which > is again in active development), profile your code and rewrite some > parts in cython or wait for PyPy to mature. > > Stani > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From kevin at cazabon.com Thu Aug 7 04:12:29 2008 From: kevin at cazabon.com (Kevin Cazabon) Date: Thu, 7 Aug 2008 04:12:29 +0200 Subject: [Image-SIG] Multi-threading and PIL In-Reply-To: References: <474877.1218037539065.JavaMail.kta719@mail.usask.ca> <1218044971.8832.11.camel@blue> Message-ID: A couple years ago I did some work on enabling multi-threading in the PIL core library, with the help of Fredrik and others. We successfully implemented it by releasing the GIL prior to starting many of the larger routines/functions in the C library, and re- acquiring it before handing back to the wrappers. I can't remember exactly which functions we did this to in total, but it definitely included the Image.resize code and so forth. On my dual-processor machine, I saw almost double performance on multi-threaded resizing operations - proving it worked. However, we never touched the pixel access sections. You could look at the resize code in the C module and use the same method to try it with the functions you use most. The trick is just figuring out the right places to release and recapture the GIL. Kevin. On 06 Aug 2008, at 21:01, Sebastian Haase wrote: > For pixel-by-pixel stuff you would probably be much (!) faster using > numpy. > > - Sebastian Haase > > > On Wed, Aug 6, 2008 at 7:49 PM, Stani wrote: >> Op woensdag 06-08-2008 om 09:45 uur [tijdzone -0600], schreef >> Kristofor >> Amundson: >> >>> My problem is that I see little to no improvement in my performance >>> with the threading, even when I process the images on a machine >>> with 8 >>> CPU's. In fact, it only seems to utilize one CPU. Is this due to the >>> GIL? >> Probably so. >> >>> I am wondering if there is a way for me to properly thread this to >>> improve my performance. >> I use mostly subprocess pools to increase multi-core performance, >> but of >> course this might be not evident to implement depending on the >> specifics >> of your software. That is the only way to take advantage of multi- >> core >> CPU (or of course stackless python). >> >> To speed up your existing code, you might also give psyco a try >> (which >> is again in active development), profile your code and rewrite some >> parts in cython or wait for PyPy to mature. >> >> Stani >> >> _______________________________________________ >> Image-SIG maillist - Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig >> > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From jtk at yahoo.com Sat Aug 9 15:51:00 2008 From: jtk at yahoo.com (Jeff Kowalczyk) Date: Sat, 09 Aug 2008 09:51:00 -0400 Subject: [Image-SIG] Proper Package for PIL References: <200711081630.13325.srichter@cosmos.phy.tufts.edu> Message-ID: Stephan Richter wrote: > I am a Zope 3 developer and we have moved all our code into PyPI projects. > Some of our packages require PIL. Unfortunately, we cannot list PIL as a > dependency, since its distributions are not uploaded to PyPI and the download > URL does not provide access the adequate links. > > For us, having a valid package/egg for PIL at the right location is very > important. I would love to contribute proper packaging and eggification to > PIL. (In fact, the Zope 3 community already has a proper, Tk-free egg for PIL > at http://download.zope.org/distribution/PILwoTk-1.1.6.3.tar.gz.) Reviving this thread, as Django-1.0 will ship in September with an optional PIL dependency. Plone has long had a hard dependency on PIL. Both Django and Plone work fine with PILwoTk, so if a similarly packaged PIL were uploaded to PyPI, it would be helpful for users and packagers of these frameworks. Thanks, Jeff From zhangchipr at gmail.com Mon Aug 11 07:08:20 2008 From: zhangchipr at gmail.com (zhang chi) Date: Mon, 11 Aug 2008 13:08:20 +0800 Subject: [Image-SIG] how to use pil for a jpeg 90 compression? Message-ID: <90c482ab0808102208h73ebffe9id46a03eb4ff262@mail.gmail.com> hi I have 30 picture, and I wanna use PIL to compress them to jpeg 90. Is there a function that can do that in PIL? -------------- next part -------------- An HTML attachment was scrubbed... URL: From fakhriworld at gmail.com Mon Aug 11 09:27:41 2008 From: fakhriworld at gmail.com (Talat Fakhri) Date: Mon, 11 Aug 2008 15:27:41 +0800 Subject: [Image-SIG] Image to Matrix to Image. Message-ID: <17379b940808110027n3efcad16gb808eda38038b312@mail.gmail.com> Hi, I am a newbie here. I would like to know if there is any function which converts Images to Matrix(RGB or greyscale etc) and another function which converts the matrix into Image file? Thanks. PS: I have dug in mail archives and PIL, but could not conclusively find the solution. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Mon Aug 11 20:58:15 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Aug 2008 20:58:15 +0200 Subject: [Image-SIG] Multi-threading and PIL In-Reply-To: References: <474877.1218037539065.JavaMail.kta719@mail.usask.ca> <1218044971.8832.11.camel@blue> Message-ID: Kevin Cazabon wrote: > A couple years ago I did some work on enabling multi-threading in the > PIL core library, with the help of Fredrik and others. We successfully > implemented it by releasing the GIL prior to starting many of the larger > routines/functions in the C library, and re-acquiring it before handing > back to the wrappers. I can't remember exactly which functions we did > this to in total, but it definitely included the Image.resize code and > so forth. On my dual-processor machine, I saw almost double performance > on multi-threaded resizing operations - proving it worked. However, we > never touched the pixel access sections. > > You could look at the resize code in the C module and use the same > method to try it with the functions you use most. The trick is just > figuring out the right places to release and recapture the GIL. The fact that the OP uses pixel access pretty much implies that most of the processing time in his program is spent on the Python level, which means that the GIL is the culprit here. Releasing and reacquiring the lock would most likely take a lot more time than just fetching the pixel. To fully get around the GIL for cases like this, you have to use processing or similar libraries. For some cases, the simple thread/subprocess approach outlined here: http://effbot.org/zone/wide-finder.htm can work (see the addenda section for examples using the processing and pprocess libraries). Depending on the access/crunching ratio, psyco might also help: http://psyco.sourceforge.net/ From fredrik at pythonware.com Mon Aug 11 21:03:12 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Aug 2008 21:03:12 +0200 Subject: [Image-SIG] Image to Matrix to Image. In-Reply-To: <17379b940808110027n3efcad16gb808eda38038b312@mail.gmail.com> References: <17379b940808110027n3efcad16gb808eda38038b312@mail.gmail.com> Message-ID: Talat Fakhri wrote: > I am a newbie here. I would like to know if there is any function which > converts Images to Matrix(RGB or greyscale etc) and another function > which converts the matrix into Image file? "matrix" as in? If you just want to work with the image data as Python sequence, use getdata/putdata, or pixel access objects: >>> im = Image.open("image.jpg") >>> pix = im.load() >>> pix[0, 0] (226, 162, 125) >>> pix[0, 0] = (0, 0, 0) From fredrik at pythonware.com Mon Aug 11 21:00:01 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 11 Aug 2008 21:00:01 +0200 Subject: [Image-SIG] how to use pil for a jpeg 90 compression? In-Reply-To: <90c482ab0808102208h73ebffe9id46a03eb4ff262@mail.gmail.com> References: <90c482ab0808102208h73ebffe9id46a03eb4ff262@mail.gmail.com> Message-ID: zhang chi wrote: > I have 30 picture, and I wanna use PIL to compress them to jpeg 90. > Is there a function that can do that in PIL? What does "30" and "90" refer to? From karsten.hiddemann at mathematik.uni-dortmund.de Mon Aug 11 21:09:47 2008 From: karsten.hiddemann at mathematik.uni-dortmund.de (Karsten Hiddemann) Date: Mon, 11 Aug 2008 21:09:47 +0200 Subject: [Image-SIG] how to use pil for a jpeg 90 compression? In-Reply-To: References: <90c482ab0808102208h73ebffe9id46a03eb4ff262@mail.gmail.com> Message-ID: <48A08E7B.6010408@mathematik.uni-dortmund.de> Fredrik Lundh schrieb: > zhang chi wrote: > >> I have 30 picture, and I wanna use PIL to compress them to jpeg 90. Is >> there a function that can do that in PIL? > > What does "30" and "90" refer to? I'd think that he refers to the "Quality" or "Compression Level" as most image manipulation programs call it. From Chris.Barker at noaa.gov Mon Aug 11 22:07:22 2008 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Mon, 11 Aug 2008 13:07:22 -0700 Subject: [Image-SIG] Image to Matrix to Image. In-Reply-To: References: <17379b940808110027n3efcad16gb808eda38038b312@mail.gmail.com> Message-ID: <48A09BFA.9040002@noaa.gov> Fredrik Lundh wrote: > "matrix" as in? > > If you just want to work with the image data as Python sequence, use > getdata/putdata, or pixel access objects: > > >>> im = Image.open("image.jpg") > >>> pix = im.load() > >>> pix[0, 0] > (226, 162, 125) > >>> pix[0, 0] = (0, 0, 0) or convert to numpy arrays: # Added ?fromarray? function, which takes an object implementing the NumPy array interface and creates a PIL Image from it. (from Travis Oliphant). # Added NumPy array interface support (__array_interface__) to the Image class (based on code by Travis Oliphant). This allows you to easily convert between PIL image memories and NumPy arrays: import numpy, Image i = Image.open('lena.jpg') a = numpy.asarray(i) # a is readonly i = Image.fromarray(a) -- 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 jwt at onjapan.net Mon Aug 11 23:23:35 2008 From: jwt at onjapan.net (Jim Tittsler) Date: Tue, 12 Aug 2008 09:23:35 +1200 Subject: [Image-SIG] how to use pil for a jpeg 90 compression? In-Reply-To: <48A08E7B.6010408@mathematik.uni-dortmund.de> References: <90c482ab0808102208h73ebffe9id46a03eb4ff262@mail.gmail.com> <48A08E7B.6010408@mathematik.uni-dortmund.de> Message-ID: <4FAFEC5C-DA4A-42F5-9C82-15DF94FAAE1D@onjapan.net> On Aug 12, 2008, at 07:09, Karsten Hiddemann wrote: > Fredrik Lundh schrieb: >> zhang chi wrote: >>> I have 30 picture, and I wanna use PIL to compress them to jpeg >>> 90. Is there a function that can do that in PIL? >> What does "30" and "90" refer to? > > I'd think that he refers to the "Quality" or "Compression Level" as > most image manipulation programs call it. The save() method accepts a quality=90 keyword argument. -- Jim Tittsler http://www.OnJapan.net/ GPG: 0x01159DB6 Python Starship http://Starship.Python.net/crew/jwt/ Mailman IRC irc://irc.freenode.net/#mailman From fredrik at pythonware.com Tue Aug 12 12:27:27 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 12 Aug 2008 12:27:27 +0200 Subject: [Image-SIG] how to use pil for a jpeg 90 compression? In-Reply-To: <48A08E7B.6010408@mathematik.uni-dortmund.de> References: <90c482ab0808102208h73ebffe9id46a03eb4ff262@mail.gmail.com> <48A08E7B.6010408@mathematik.uni-dortmund.de> Message-ID: Karsten Hiddemann skrev: >>> I have 30 picture, and I wanna use PIL to compress them to jpeg 90. >>> Is there a function that can do that in PIL? >> >> What does "30" and "90" refer to? > > I'd think that he refers to the "Quality" or "Compression Level" as most > image manipulation programs call it. Yeah, but changing the "quality" from 30 to 90 for an existing file makes very little sense. Once the information is lost, it's lost. From mail at karsten.name Tue Aug 12 12:28:56 2008 From: mail at karsten.name (Karsten Hiddemann) Date: Tue, 12 Aug 2008 12:28:56 +0200 Subject: [Image-SIG] how to use pil for a jpeg 90 compression? In-Reply-To: References: <90c482ab0808102208h73ebffe9id46a03eb4ff262@mail.gmail.com> <48A08E7B.6010408@mathematik.uni-dortmund.de> Message-ID: <48A165E8.5080708@karsten.name> Fredrik Lundh schrieb: > Karsten Hiddemann skrev: > >>>> I have 30 picture, and I wanna use PIL to compress them to jpeg 90. >>>> Is there a function that can do that in PIL? >>> >>> What does "30" and "90" refer to? >> >> I'd think that he refers to the "Quality" or "Compression Level" as >> most image manipulation programs call it. > > Yeah, but changing the "quality" from 30 to 90 for an existing file > makes very little sense. Once the information is lost, it's lost. 30 images to be converted to jpeg with a quality setting of 90, but I might be completely wrong about this, too. ;) I think the question is answered unless the OP writes again. From Sebastian at SSpaeth.de Wed Aug 13 11:50:43 2008 From: Sebastian at SSpaeth.de (Sebastian Spaeth) Date: Wed, 13 Aug 2008 11:50:43 +0200 Subject: [Image-SIG] PNG transparency not recognized Message-ID: <20080813095042.GE17861@sspaeth.de> Hi all, extensive googling didn't help, so here I go. I produce PNG files with lot's of transparency. These are run through various PNG optimizers (pngnq, pngcrush). When I try to open them, they are im.mode='RGB', ie all the transparency is gone. This is the same in PIL 1.1.5 and 1.1.6. Example PNG here: http://sspaeth.de/pyblosxom/caption_6_33_22.png Try to open that in Gimp and you'll see the transparent background. Open in PIL and there's no transparency. Or have I overlooked something? Thanks in advance, spaetz From fredrik at pythonware.com Wed Aug 13 13:35:07 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Aug 2008 13:35:07 +0200 Subject: [Image-SIG] PNG transparency not recognized In-Reply-To: <20080813095042.GE17861@sspaeth.de> References: <20080813095042.GE17861@sspaeth.de> Message-ID: Sebastian Spaeth wrote: > extensive googling didn't help, so here I go. I produce PNG files with lot's of transparency. These are run through various PNG optimizers (pngnq, pngcrush). > > When I try to open them, they are im.mode='RGB', ie all the transparency is gone. This is the same in PIL 1.1.5 and 1.1.6. > > Example PNG here: http://sspaeth.de/pyblosxom/caption_6_33_22.png > Try to open that in Gimp and you'll see the transparent background. Open in PIL and there's no transparency. Or have I overlooked something? PIL doesn't support images using a "transparency color index", but many file codecs does at least add the color to the info dictionary, usually under the "transparency" key. For some reason, the PNG codec doesn't do this for RGB images. I've attached a simple patch that fixes the reader; with this in place, you can get the background color as im.info["transparency"]: >>> from PIL import Image >>> im = Image.open('caption_6_33_22.png') >>> im.info {'transparency': (248, 248, 248)} Index: PIL/PngImagePlugin.py =================================================================== --- PIL/PngImagePlugin.py (revision 3404) +++ PIL/PngImagePlugin.py (working copy) @@ -220,6 +220,8 @@ self.im_info["transparency"] = i elif self.im_mode == "L": self.im_info["transparency"] = i16(s) + elif self.im_mode == "RGB": + self.im_info["transparency"] = i16(s), i16(s[2:]), i16(s[4:]) return s def chunk_gAMA(self, pos, len): From fakhriworld at gmail.com Tue Aug 12 11:43:58 2008 From: fakhriworld at gmail.com (Talat Fakhri) Date: Tue, 12 Aug 2008 17:43:58 +0800 Subject: [Image-SIG] Image to Matrix to Image. In-Reply-To: References: <17379b940808110027n3efcad16gb808eda38038b312@mail.gmail.com> Message-ID: <17379b940808120243yb92684ew5ee0612b440b5d60@mail.gmail.com> Thanks. This is what I was looking for. So , after changing the pixel [0,0], how do we save the modified image? On Tue, Aug 12, 2008 at 3:03 AM, Fredrik Lundh wrote: > Talat Fakhri wrote: > > I am a newbie here. I would like to know if there is any function which >> converts Images to Matrix(RGB or greyscale etc) and another function which >> converts the matrix into Image file? >> > > "matrix" as in? > > If you just want to work with the image data as Python sequence, use > getdata/putdata, or pixel access objects: > > >>> im = Image.open("image.jpg") > >>> pix = im.load() > >>> pix[0, 0] > (226, 162, 125) > >>> pix[0, 0] = (0, 0, 0) > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -- Talat, Chief Executive Officer. "Breathing Life Into Concepts." AT Evolvimatix. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Wed Aug 13 17:14:27 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 13 Aug 2008 17:14:27 +0200 Subject: [Image-SIG] Image to Matrix to Image. In-Reply-To: <17379b940808120243yb92684ew5ee0612b440b5d60@mail.gmail.com> References: <17379b940808110027n3efcad16gb808eda38038b312@mail.gmail.com> <17379b940808120243yb92684ew5ee0612b440b5d60@mail.gmail.com> Message-ID: Talat Fakhri wrote: > Thanks. This is what I was looking for. So , after changing the pixel > [0,0], how do we save the modified image? the same way as you'd save any PIL image: http://effbot.org/tag/PIL.Image.Image.save you have read the tutorial, right? http://effbot.org/imagingbook/introduction.htm#reading-and-writing-images From Sebastian at SSpaeth.de Wed Aug 13 20:16:14 2008 From: Sebastian at SSpaeth.de (Sebastian Spaeth) Date: Wed, 13 Aug 2008 20:16:14 +0200 Subject: [Image-SIG] PNG transparency not recognized In-Reply-To: References: <20080813095042.GE17861@sspaeth.de> Message-ID: <48A324EE.6080806@SSpaeth.de> Fredrik Lundh wrote: > PIL doesn't support images using a "transparency color index", but many > file codecs does at least add the color to the info dictionary, usually > under the "transparency" key. Thanks for the quick reply, this clarifies and helps a lot. Using the transparency key is fine and solved my issues. Looking forward to finding this patch in the next main release. Much appreciated! Sebastian From george.f.rice at gmail.com Sat Aug 16 05:05:29 2008 From: george.f.rice at gmail.com (George Rice) Date: Fri, 15 Aug 2008 22:05:29 -0500 Subject: [Image-SIG] Screen Capture in Linux and Windows Message-ID: <33edbc410808152005s779c2090ofdbc857da352b27d@mail.gmail.com> I need to capture and then manipulate screen images from Python, under both (Gnome) Linux and Windows XP / Vista. PIL captures only Windows screen images; ImageMagick (for example) captures only Linux screen images. I cannot find a library or command line utility that can capture and manipulate screen images on both platforms. If I use PIL only on Windows and ImageMagick only on Linux, I'll have to write the manipulation code twice. Ugly. Or, I could require ImageMagick only on Linux, but do all manipulation in PIL for both platforms (or vice versa) - but ImageMagick is a pretty heavy utility only to capture a screen image. Or, I could dust off my C coding skills and try to implement a patch for PIL to give it Linux screen capture capability. This would be more useful to more people, but would dramatically affect my schedule. Am I missing an option or cross-platform library / utility in my research? Is anyone already adding Linux screen capture to PIL in an upcoming release? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashishbitsgoa at gmail.com Mon Aug 18 11:25:46 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Mon, 18 Aug 2008 14:55:46 +0530 Subject: [Image-SIG] Fwd: problem in converting pixel data to image file In-Reply-To: References: Message-ID: Hi all, I have a problem in converting the pixel data (read from a string and written to a file using fromstring command in PIL ). The file handle of this file is called buffer. Now, when I tried to open the file as an image file but it didnt work. Then I read the documentation of PIL and found this written about fromstring function "Note that this function decodes pixel data, not entire images. If you have an entire image in a string, wrap it in a *StringIO *object, and use *open *to load it." so i wrote the following code.... file = StringIO.StringIO(buffer) img = Image.open(file) img.save(file, 'JPEG') *Error:* img = Image.open(file) File "/home/rahhal/python/lib/python2.4/site-packages/PIL/Image.py", line 1745, in open raise IOError("cannot identify image file") IOError: cannot identify image file Can any one please help in solving my problem?? -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashishbitsgoa at gmail.com Mon Aug 18 11:38:57 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Mon, 18 Aug 2008 15:08:57 +0530 Subject: [Image-SIG] converting between different RGB color spaces Message-ID: Hi all, I want to convert files stored in RGB [8:8:8] format to RGB [4:4:4], RGB[12:12:12] etc.,i.e, basically i want to store images in RGB mode with 4,12 etc bit per band instead of the standard 8 bits. For this, I think i will require *im.convert(mode, matrix) *. But unfortunately i couldn't find much reading material about it in the PIL handbook. Plz guide me in the right direction -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashishbitsgoa at gmail.com Mon Aug 18 12:33:08 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Mon, 18 Aug 2008 16:03:08 +0530 Subject: [Image-SIG] RGB[8:8:8] to RGB[4:4:4] and RGB[12:12:12] Message-ID: Hey all, I am newbie to image processing using python I have a problem in converting between different RGB color spaces.I have a jpeg file in rgb mode. The rgb data by default is in RGB[8:8:8] mode...i.e, 8 bits(1 byte) per band(r,g,b). I need to convert it into RGB[4:4:4] format by getting the rgb information of each pixel in the image and converting the ascii values obtained for the R,G and B bands into binary form and then clip the least significant 4 bits from this binary no. to form a 4 bit binary value and then convert this back to ascii and and save the new information back to the image file. Untill now, I have been able obtain the pixel information of my image file using : >* >>> im = Image.open("image.jpg") *>* >>> pix = im.load() *>* >>> pix[0, 0] *>* (226, 162, 125) * 1.Now, how do i convert this ascii data to binary? 2.how do i mask last 4 bits ( least significant bits )? 3.also, I need to convert the same image to RGB[12:12:12] mode,for which i need to zero pad with 4 zeroes the binary RGB[8:8:8] data. How do I do this? -------------- next part -------------- An HTML attachment was scrubbed... URL: From cannon.el at gmail.com Mon Aug 18 18:52:39 2008 From: cannon.el at gmail.com (Laura & Edward Cannon) Date: Mon, 18 Aug 2008 09:52:39 -0700 Subject: [Image-SIG] RGB[8:8:8] to RGB[4:4:4] and RGB[12:12:12] In-Reply-To: References: Message-ID: color spaces first off the data you got is not character data, it is python integers, to get only 4 bits of significance try something like int(floor(x/8.0)). padding could be accomplished by multiplication by 8. The answers to these would still be python integers, which would still need to be encoded in the proper format, their might be a slick way to do it, but look at the documentation for the ord() function. 2008/8/18 Ashish Sethi : > Hey all, > > I am newbie to image processing using python > > I have a problem in converting between different RGB color spaces.I have a > jpeg file in rgb mode. > The rgb data by default is in RGB[8:8:8] mode...i.e, 8 bits(1 byte) per > band(r,g,b). > I need to convert it into RGB[4:4:4] format by getting the rgb information > of each pixel in the image > and converting the ascii values obtained for the R,G and B bands into binary > form and then clip the least significant 4 bits > from this binary no. to form a 4 bit binary value and then convert this back > to ascii and and save the new information back > to the image file. Untill now, I have been able obtain the pixel information > of my image file using : >> >>> im = Image.open("image.jpg") >> >>> pix = im.load() >> >>> pix[0, 0] >> (226, 162, 125) > 1.Now, how do i convert this ascii data to binary? > 2.how do i mask last 4 bits ( least significant bits )? > 3.also, I need to convert the same image to RGB[12:12:12] mode,for which i > need to zero pad with 4 zeroes the > binary RGB[8:8:8] data. How do I do this? > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > From fredrik at pythonware.com Mon Aug 18 19:22:58 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 18 Aug 2008 19:22:58 +0200 Subject: [Image-SIG] Fwd: problem in converting pixel data to image file In-Reply-To: References: Message-ID: Ashish Sethi wrote: > I have a problem in converting the pixel data (read from a string and > written to a file using fromstring command in PIL ). > The file handle of this file is called buffer. Now, when I tried to open > the file as an image file but it didnt work. > Then I read the documentation of PIL and found this written about > fromstring function > "Note that this function decodes pixel data, not entire images. If you > have an entire image in a string, wrap it in a *StringIO *object, and use > *open *to load it." > so i wrote the following code.... > > file = StringIO.StringIO(buffer) > img = Image.open(file) > img.save(file, 'JPEG') > > *Error:* > img = Image.open(file) > File "/home/rahhal/python/lib/python2.4/site-packages/PIL/Image.py", line > 1745, in open > raise IOError("cannot identify image file") > IOError: cannot identify image file > > Can any one please help in solving my problem?? What's "pixel data" here? Image.open expects the file to contain an image in a known image interchange format (e.g. JPEG, PNG, etc). If you have raw data, you might be able to use frombuffer or fromstring. From fredrik at pythonware.com Tue Aug 19 11:45:13 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Aug 2008 11:45:13 +0200 Subject: [Image-SIG] PIL on Mac OS X 10.5 Message-ID: just for the archives: Matt Kangas recently posted a workaround showing how to use the pythonmac.org PIL build with the original OS X Python: http://www.p16blog.com/p16/2008/05/appengine-installing-pil-on-os-x-1053.html (not a mac user myself, so I cannot verify that this works. comments and clarifications from the resident mac experts are welcome.) From ashishbitsgoa at gmail.com Tue Aug 19 13:01:03 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Tue, 19 Aug 2008 16:31:03 +0530 Subject: [Image-SIG] Writting ppm files?? Message-ID: Hi all,. I am working with PPM/PGM/PBM file formats which have the basic format :- P2 # feep.pgm 3 3 255 0 0 0 0 0 0 0 0 0 0 0 0 9 24 15 10 27 18 0 0 0 9 24 15 10 27 18 where line1= type of file(p1=PBM,p2=PGM,p3=PPM), line2=comment, line3=dimension of the image (x and y length),line4=maximum value of color( here 15 means 4 bit R,G,B data) NOW, uptil now, I have written the following code:- import Image im="C:\\Documents and Settings\\ashishs trainee\\Desktop\\lena.ppm" i=Image.open(im) x=list(i.getdata()) z=len(x) xbar=[] count=0 while (count References: Message-ID: Ashish Sethi wrote: > I am working with PPM/PGM/PBM file formats > which have the basic format :- looks like you could save yourself a lot of time and effort by first checking if you can install: http://www.pythonware.com/products/pil/ From ashishbitsgoa at gmail.com Tue Aug 19 13:25:28 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Tue, 19 Aug 2008 16:55:28 +0530 Subject: [Image-SIG] Writting ppm files?? In-Reply-To: References: Message-ID: i have...and am using it as well as u could see in my code...but the thing is PIL doesnt allows me to write image files in hybrid RGB formats like RGB 4:4:4 and 12:12:12...so i have to adopt a different approach On 8/19/08, Fredrik Lundh wrote: > Ashish Sethi wrote: > > > I am working with PPM/PGM/PBM file formats > > which have the basic format :- > > > > looks like you could save yourself a lot of time and effort by first > checking if you can install: > > http://www.pythonware.com/products/pil/ > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From fredrik at pythonware.com Tue Aug 19 13:28:07 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 19 Aug 2008 13:28:07 +0200 Subject: [Image-SIG] Writting ppm files?? In-Reply-To: References: Message-ID: Fredrik Lundh wrote: > looks like you could save yourself a lot of time and effort by first > checking if you can install: > > http://www.pythonware.com/products/pil/ sorry, thought you'd posted this to c.l.python, and didn't see the "import" statement at first. >> I am working with PPM/PGM/PBM file formats >> which have the basic format :- > where line1= type of file(p1=PBM,p2=PGM,p3=PPM), line2=comment, > line3=dimension of the image (x and y length),line4=maximum value of > color( here 15 means 4 bit R,G,B data) not really -- the 15 means that the images contain data in the range 0-15. that fits in 4 bits, but since it's a text format, it isn't stored in 4 bits. far from it. why are you using PPM text files? does the application your using really require that, or is this just something you thought would make things easier? if you're only interested in making sure that all RGB values in an image fits inside the 0-15 range, you can simply do: im = Image.open(infile) im = im.point(lambda x: x/16) im.save(outfile) if you insist on writing this out as a text file, replace the "save" with a simple loop that uses the im.load() accessor. something like this should work: pix = im.load() out = open(outfile, "w") print >>out, "P2" print >>out, "%d %d" % im.size print >>out, "15" for y in range(im.size[1]): for x in range(im.size[0]): r, g, b = pix[x, y] print >>out, r, g, b, print >>out out.close() tweak as necessary. From ashishbitsgoa at gmail.com Tue Aug 19 13:55:44 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Tue, 19 Aug 2008 17:25:44 +0530 Subject: [Image-SIG] Writting ppm files?? In-Reply-To: References: Message-ID: well...I tried both ur suggestions but didnt give the desired results 1. First method gave me an all black image (i.e all x/16=0) 2. This method doesnt give me an image file as an outfile Can u suggest how to work around this On 8/19/08, Fredrik Lundh wrote: > Fredrik Lundh wrote: > > > looks like you could save yourself a lot of time and effort by first > > checking if you can install: > > > > http://www.pythonware.com/products/pil/ > > sorry, thought you'd posted this to c.l.python, and didn't see the "import" > statement at first. > > > > > > I am working with PPM/PGM/PBM file formats > > > which have the basic format :- > > > > > > > > where line1= type of file(p1=PBM,p2=PGM,p3=PPM), line2=comment, > > line3=dimension of the image (x and y length),line4=maximum value of > > color( here 15 means 4 bit R,G,B data) > > not really -- the 15 means that the images contain data in the range 0-15. > that fits in 4 bits, but since it's a text format, it isn't stored in 4 > bits. far from it. > > why are you using PPM text files? does the application your using really > require that, or is this just something you thought would make things > easier? > > if you're only interested in making sure that all RGB values in an image > fits inside the 0-15 range, you can simply do: > > im = Image.open(infile) > im = im.point(lambda x: x/16) > im.save(outfile) > > if you insist on writing this out as a text file, replace the "save" with a > simple loop that uses the im.load() accessor. something like this should > work: > > pix = im.load() > > out = open(outfile, "w") > print >>out, "P2" > print >>out, "%d %d" % im.size > print >>out, "15" > for y in range(im.size[1]): > for x in range(im.size[0]): > r, g, b = pix[x, y] > print >>out, r, g, b, > print >>out > out.close() > > tweak as necessary. > > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From ashishbitsgoa at gmail.com Wed Aug 20 07:04:30 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Wed, 20 Aug 2008 10:34:30 +0530 Subject: [Image-SIG] problem in converting pixel data to image file In-Reply-To: References: <1219164143.13698.45.camel@lieryan-laptop> Message-ID: Thanks for ur reply, But the thing is I was under the impression that in a ppm image the maximum or the min color value that any of the R,G and B components can take...i.e. if instead of 255 in the file below, if I give 16 then automatically it would imply my color space has changed to RGB 4:4:4 as all the color components now would be in the range 0-16 (i.e 4 bit binary...and let me clarify...i am repeatedly talking about binary from time to time as I use the color information in binary to clip/zero pad them to change the color space from rgb888 to rgb444 or rgb121212.That is it, not that i wish to save my files in binary format. After doing the above manipulation i convert them back to decimal nos. and save them to the ppm files.) So here i am: 1. I took the image data of a ppm file in rgb888 color space..eg say-(255,255,255) 2. I converted this data to binary and did manipulations on it and then converted them back to decimal form...eg say-(15,15,15) 3. I have now a list full of such tuples of 3 member r,g,b information. The help now require is to create a ppm(p3) file using this list with the correct header and dimensions. Also, is it required to register this file as an image file or something, coz I have plenty of such ppm files in my system which pil doesnt recognise as image files. And the ones that it does recognize as image files have garbage data (apart from the header part) when opened in a text editor. Looking forward to your reply On 8/19/08, Lie Ryan wrote: > On Tue, 2008-08-19 at 15:31 +0530, Ashish Sethi wrote: > > Hey frnds, > > thanks for replying to me earlier query. > > I have been able to solve most of my problems and have 1 more and much > > straightforward problem. I am working with PPM/PGM/PBM file formats > > which have the basic format :- > > > > P2 > > # feep.pgm > > 3 3 > > 255 > > 0 0 0 0 0 0 0 0 0 > > 0 0 0 9 24 15 10 27 18 > > 0 0 0 9 24 15 10 27 18 > > where line1= type of file(p1=PBM,p2=PGM,p3=PPM), line2=comment, > > line3=dimension of the image (x and y length),line4=maximum value of > > color( here 15 means 4 bit R,G,B data) > > NOW, uptil now, I have written the following code:- > > PNM (the collective name for PBM, PGM, and PPM is a relatively little > known format that is designed for simplicity in mind (but it obviously > not designed for space-saving), but you should know that there is also > the fourth-format PAM (Portable Arbitrary Map), which goes by P7 > (http://netpbm.sourceforge.net/doc/pam.html ). PBM is used for 2-bit > image, PGM for 8-bit image, and PPM for 24-bit image, that's quite > restrictive, but PAM is designed so the data can be any-bit image (in > fact it may be used not only for images, but any data that may be > represented as row and collumns). Since you want an image that is > represented in a quite unusual bit-depth (4-bit and 12-bit), P7 is the > perfect format for you. > > > import Image > > im="C:\\Documents and Settings\\ashishs trainee\\Desktop\\lena.ppm" > > i=Image.open(im) > > x=list(i.getdata()) > > z=len(x) > > xbar=[] > > count=0 > > > > while (count > q=[] > > co=0 > > while(co<3): > > y=x[count] > > q.append(convert_r8_2_r4(y[co])) > > co+=1 > > xbar.append(q) > > count+=1 > > > > A bit of advice: you should choose a better names instead of x, y, q, > co, z, xbar. And you should think in Python, i.e. using for-loop's > capability to loop over list directly. > > > > > Here, x is a list of all 3 member tuples of R,G,B data of each and > > every pixel. > > Here and a few lines after this may be used for your PAM header. > DEPTH 3 > > > The tuples in x have RGB values in the range 0-255..i.e > > 8 bit binary. > > # 4-bit/color > MAXVAL 16 > # 8-bit/color > MAXVAL 256 > # 12-bit/color > MAXVAL 4096 > > > Using the function convert_r8_2_r4() I was able to > > convert these values in the range 0-16...i.e 4 bit binary by clipping > > the least significant 4 bits. By doing this I was able to create xbar > > which is in the same format as x...i.e list of 3 member tuples of > > R,G,B data. Now my problem is how do i create another image of the > > same dimensions as the original in the same format as original using > > this xbar list. > > use something like this: > # untested > def listtopambody(image, depth, width, height, maxval): > def tobinary1(sample): > ''' Convert an integer to 1-byte binary ''' > assert sample < 256 > return chr(int(sample)) > def tobinary2(sample): > ''' Convert an integer to 2-byte binary (Big Endian) ''' > assert sample < 65536 > high, low = divmod(int(sample), 256) > return chr(high) + chr(low) > > assert maxval <= 65535 # PAM limitation > > # calculate number of bytes per sample > # and select the appropriate function > tobinary = tobinary1 if maxval < 256 else tobinary2 > > # Generate the body > pam_body = '' > for pixel in image: > for sample in pixel: > pam_body += tobinary(sample) > return pam_body > # w, h, maxval = ... > pam_body = listtopambody(im.getdata(), 3, w, h, maxval) > pam = pam_header + pam_body > > > > > > > Plz help > > > > > > On 8/18/08, Fredrik Lundh wrote: > > > > > > Ashish Sethi wrote: > > > > > > > > > > I have a problem in converting the pixel data (read from a string and written to a file using fromstring command in PIL ). > > > > The file handle of this file is called buffer. Now, when I tried to open the file as an image file but it didnt work. > > > > Then I read the documentation of PIL and found this written about fromstring function > > > > "Note that this function decodes pixel data, not entire images. If you > > > > have an entire image in a string, wrap it in a *StringIO *object, and use > > > > *open *to load it." > > > > so i wrote the following code.... > > > > file = StringIO.StringIO(buffer) > > > > img = Image.open(file) > > > > img.save(file, 'JPEG') > > > > > > > > *Error:* > > > > img = Image.open(file) > > > > File "/home/rahhal/python/lib/python2.4/site-packages/PIL/Image.py", line > > > > 1745, in open > > > > raise IOError("cannot identify image file") > > > > IOError: cannot identify image file > > > > Can any one please help in solving my problem?? > > > > > > > > > > What's "pixel data" here? Image.open expects the file to contain an image in a known image interchange format (e.g. JPEG, PNG, etc). If you have raw data, you might be able to use frombuffer or fromstring. > > > > > > > > > > > > _______________________________________________ > > > Image-SIG maillist - Image-SIG at python.org > > > http://mail.python.org/mailman/listinfo/image-sig > > > > > From fredrik at pythonware.com Wed Aug 20 08:09:54 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Aug 2008 08:09:54 +0200 Subject: [Image-SIG] problem in converting pixel data to image file In-Reply-To: References: <1219164143.13698.45.camel@lieryan-laptop> Message-ID: Ashish Sethi wrote: > But the thing is I was under the impression that in a ppm image the > maximum or the min color value that any of the R,G and B components > can take...i.e. if instead of 255 in the file below, if I give 16 then > automatically it would imply my color space has changed to RGB 4:4:4 > as all the color components now would be in the range 0-16 (i.e 4 bit > binary...and let me clarify... 4-bit binary can hold 0-15 per component, not 0-16. 4-bit is also a measurement of the number of bits required to store the data on file; a text file that uses 9 bytes per pixel isn't the same thing as a 4-bit binary file. A PPM text file is not a 4-bit file. Since you insist on creating 4-bit text files, I'm beginning to suspect that you're confusing internal storage with external storage. i am repeatedly talking about binary > from time to time as I use the color information in binary to > clip/zero pad them to change the color space from rgb888 to rgb444 or > rgb121212.That is it, not that i wish to save my files in binary > format. After doing the above manipulation i convert them back to > decimal nos. and save them to the ppm files.) who's going to use those PPM files? > Also, is it required to register this file as an image file or > something, coz I have plenty of such ppm files in my system which pil > doesnt recognise as image files. And the ones that it does recognize > as image files have garbage data (apart from the header part) when > opened in a text editor. that "garbage" is binary data and contains the image data. are you telling me that you haven't seen binary data before? I'm beginning to feel that this leads nowhere at all; if you want us to be able to help, please specify 1) what kind of images you plan to convert 2) what the intended use for the "4-bit" text files is 3) what application you're planning to use for the next step (that is, who's going to read the 4-bit files?) From ashishbitsgoa at gmail.com Wed Aug 20 08:44:55 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Wed, 20 Aug 2008 12:14:55 +0530 Subject: [Image-SIG] problem in converting pixel data to image file In-Reply-To: References: <1219164143.13698.45.camel@lieryan-laptop> Message-ID: thanks for the reply, I am a noob in python and image processing and really appreciate your patience with me and sorry about the 0-16 bit crap about the garbage data...if that is binary data then shouldn't ppm(p3) image contain information in ascii (only p6 data contains binary). Does this mean pil accepts only p6 and not p3 files?? About the use of these files, well i am creating a tool to convert a veriety of color spaces. Now i'll be really blunt and tell u the complete detail of the work...no matter how stupid it makes me look (as if i am not already looking it!!!) IF there is a file in ppm format like P3 3 3 15 0 0 0 10 10 10 2 2 2 1 1 1 12 12 12 4 4 4 4 4 4 11 11 11 9 9 9 Then isnt this file in RGB 4:4:4 color space as the maximum value that any of the color components can take is 15 (binary 4 bit) What my job is to read a ppm(p3) file in RGB 8:8:8 color space where values are in 0-255 range and change these values to 0-16 range as i explained earlier. This much i have acheived...now i need to create another ppm(p3) image using thes new values (a list 3 member tuples). Now please explain if their is something wrong in my understanding and if not please help me in creating the new ppm file On 8/20/08, Fredrik Lundh wrote: > Ashish Sethi wrote: > > > But the thing is I was under the impression that in a ppm image the > > maximum or the min color value that any of the R,G and B components > > can take...i.e. if instead of 255 in the file below, if I give 16 then > > automatically it would imply my color space has changed to RGB 4:4:4 > > as all the color components now would be in the range 0-16 (i.e 4 bit > > binary...and let me clarify... > > > > 4-bit binary can hold 0-15 per component, not 0-16. > > 4-bit is also a measurement of the number of bits required to store the data > on file; a text file that uses 9 bytes per pixel isn't the same thing as a > 4-bit binary file. A PPM text file is not a 4-bit file. > > Since you insist on creating 4-bit text files, I'm beginning to suspect that > you're confusing internal storage with external storage. > > i am repeatedly talking about binary > > from time to time as I use the color information in binary to > > clip/zero pad them to change the color space from rgb888 to rgb444 or > > rgb121212.That is it, not that i wish to save my files in binary > > format. After doing the above manipulation i convert them back to > > decimal nos. and save them to the ppm files.) > > > > who's going to use those PPM files? > > > Also, is it required to register this file as an image file or > > something, coz I have plenty of such ppm files in my system which pil > > doesnt recognise as image files. And the ones that it does recognize > > as image files have garbage data (apart from the header part) when > > opened in a text editor. > > > > that "garbage" is binary data and contains the image data. are you telling > me that you haven't seen binary data before? > > I'm beginning to feel that this leads nowhere at all; if you want us to be > able to help, please specify > > 1) what kind of images you plan to convert > 2) what the intended use for the "4-bit" text files is > 3) what application you're planning to use for the next step (that is, > who's going to read the 4-bit files?) > > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From adam.n.fraser at gmail.com Mon Aug 18 23:00:38 2008 From: adam.n.fraser at gmail.com (Adam Fraser) Date: Mon, 18 Aug 2008 17:00:38 -0400 Subject: [Image-SIG] bug with Image.crop Message-ID: Hello, I've never submitted a bug before, but it seems that Image.crop doesn't work in some cases where the crop box contains pixels outside the extents of the image. By "doesn't work" I mean that strange artifacts occur in the newly cropped image... sometimes appear to be a repetition of elements in the original, other times they are ambiguous like short while lines, or specks. im.crop(-30,-30,30,30) doesn't work im.crop(-30,-30,31,31) doesn't work im.crop(-30,-30,32,32) works im.crop(-300,-300,30,30) works Most crop calls seemed to work and the space outside of the image was filled with black pixels, but as I've shown, a few examples cause trouble. The images being opened included jpg, png, and another proprietary format for which I had written my own parser. I'm using PIL Image 1.1.6 and python 2.5.1 Thanks! -Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: From ASLAng at ntu.edu.sg Tue Aug 19 10:26:51 2008 From: ASLAng at ntu.edu.sg (Ang Ah Giat, Linda) Date: Tue, 19 Aug 2008 16:26:51 +0800 Subject: [Image-SIG] Python Imaging Library (PIL) Message-ID: <7CD06E15ADF4104A9F2E4DC2DE678F8906C3111B@EXCHANGE21.staff.main.ntu.edu.sg> Hi, I try to install plone into my zope, it complaint that "PortalTransforms Problem importing module image_to_png : No module named PIL.Image". So I download the Python Imaging Library 1.1.6 Source Kit (all platforms) from http://www.pythonware.com/products/pil/ I did the follow steps as in the README file $ gunzip Imaging-1.1.6.tar.gz $ tar xvf Imaging-1.1.6.tar $ cd Imaging-1.1.6 $ python setup.py install I go a lot funny stuff on the screen and end with "error: command 'gcc' failed with exit status 1" Anywhere that I can get the Python Imaging Library for Ububtu version 7.10? Best Regards, Linda Ang 4G Research Lab N4-B3b-13 Tel: 6514 8349 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ersenkavak at gmail.com Tue Aug 19 14:46:27 2008 From: ersenkavak at gmail.com (ersen kavak) Date: Tue, 19 Aug 2008 14:46:27 +0200 Subject: [Image-SIG] Changing text direction with draw.text() Message-ID: Dear all; I am a new Python user. I am enjoying the imaging capabilities of python currently. I am using PIL module. However, in spite of my long searches over forums, books and the internet I could not manage to print a text in vertical direction onto an image. I am guessing that this should be possible, but... Any suggestions are very wellcome ? Best Regards -- Ersen Kavak Karolinska Universitetssjukhuset Solna CCK, R8:05 171 76 Stockholm Lab: +46851770585 Mobile: +46707875729 -------------- next part -------------- An HTML attachment was scrubbed... URL: From ashish.asgekar at gmail.com Wed Aug 20 06:31:24 2008 From: ashish.asgekar at gmail.com (Ashish Asgekar) Date: Wed, 20 Aug 2008 10:01:24 +0530 Subject: [Image-SIG] PIL - 1.1.6, Centroid Message-ID: <59dee0170808192131o3f1feaafk2745887bebf4e77b@mail.gmail.com> Hello I was looking for Centroid function in Python and downloaded PIL-1.1.6. I learnt that Centroid function is available as Crack Code. However, when I search for CrackCode, I find it is not available anymore from PythonWare. My questions are: 1) Is CrackCode available in PIL-1.1.6 in some other form? 2) Can I compute Centroid of an image using some other existing function? Thank you. -- ashish -- ----------------------------------------------------------------------------- Dr. Ashish Asgekar Physics Group, BITS Pilani-Goa Campus, Zuarinagar, Goa. India 403 726 www.bits-goa.ac.in/Departments/Physics/Faculty.htm ----------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From waldemar.osuch at gmail.com Wed Aug 20 19:00:13 2008 From: waldemar.osuch at gmail.com (Waldemar Osuch) Date: Wed, 20 Aug 2008 11:00:13 -0600 Subject: [Image-SIG] Python Imaging Library (PIL) In-Reply-To: <7CD06E15ADF4104A9F2E4DC2DE678F8906C3111B@EXCHANGE21.staff.main.ntu.edu.sg> References: <7CD06E15ADF4104A9F2E4DC2DE678F8906C3111B@EXCHANGE21.staff.main.ntu.edu.sg> Message-ID: <6fae95540808201000j2f983111j489f10623d90cca3@mail.gmail.com> 2008/8/19 Ang Ah Giat, Linda : > Hi, > > I try to install plone into my zope, it complaint that "PortalTransforms > Problem importing module image_to_png : No module named PIL.Image". So I > download the Python Imaging Library 1.1.6 Source Kit (all platforms) from > http://www.pythonware.com/products/pil/ > > I did the follow steps as in the README file > $ gunzip Imaging-1.1.6.tar.gz > $ tar xvf Imaging-1.1.6.tar > $ cd Imaging-1.1.6 > $ python setup.py install > I go a lot funny stuff on the screen and end with "error: command 'gcc' > failed with exit status 1" > Anywhere that I can get the Python Imaging Library for Ububtu version 7.10? I would try this first: sudo apt-get install python-imaging before trying to compile my own version From fredrik at pythonware.com Wed Aug 20 19:01:47 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Aug 2008 19:01:47 +0200 Subject: [Image-SIG] Python Imaging Library (PIL) In-Reply-To: <7CD06E15ADF4104A9F2E4DC2DE678F8906C3111B@EXCHANGE21.staff.main.ntu.edu.sg> References: <7CD06E15ADF4104A9F2E4DC2DE678F8906C3111B@EXCHANGE21.staff.main.ntu.edu.sg> Message-ID: Ang Ah Giat, Linda wrote: > I try to install plone into my zope, it complaint that "PortalTransforms > Problem importing module image_to_png : No module named PIL.Image". So I > download the _*Python Imaging Library 1.1.6 Source Kit*_ > (all platforms) from > _http://www.pythonware.com/products/pil/_ > > I did the follow steps as in the README file > *$ gunzip Imaging-1.1.6.tar.gz* > * $ tar xvf Imaging-1.1.6.tar* > * $ cd Imaging-1.1.6* > * $ python setup.py install* > I go a lot funny stuff on the screen and end with "error: command 'gcc' > failed with exit status 1" looks like you ignored the requirements section. but PIL is available from the Ubuntu repositories; the following command should do the trick: $ sudo apt-get install python-imaging From fredrik at pythonware.com Wed Aug 20 19:37:59 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 20 Aug 2008 19:37:59 +0200 Subject: [Image-SIG] problem in converting pixel data to image file In-Reply-To: References: <1219164143.13698.45.camel@lieryan-laptop> Message-ID: Ashish Sethi wrote: > IF there is a file in ppm format like > > P3 > 3 3 > 15 > 0 0 0 10 10 10 2 2 2 > 1 1 1 12 12 12 4 4 4 > 4 4 4 11 11 11 9 9 9 > > Then isnt this file in RGB 4:4:4 color space as the maximum value that > any of the color components can take is 15 (binary 4 bit) Given that it uses 2-3 bytes per component (16-24 bits), I wouldn't call it a 4-bit image. PPM text files may have a maximum value, but they don't have a bit size. The data in the file will fit in a 4-bit file, though. > What my job is to read a ppm(p3) file in RGB 8:8:8 color space where > values are in 0-255 range and change these values to 0-16 range as i > explained earlier. > This much i have acheived...now i need to create another ppm(p3) image > using thes new values (a list 3 member tuples). > Now please explain if their is something wrong in my understanding and > if not please help me in creating the new ppm file I posted code for writing PPM text files earlier. From cannon.el at gmail.com Thu Aug 21 03:45:04 2008 From: cannon.el at gmail.com (Laura & Edward Cannon) Date: Wed, 20 Aug 2008 18:45:04 -0700 Subject: [Image-SIG] Changing text direction with draw.text() In-Reply-To: References: Message-ID: you could either make the text horizontal and rotate it using im.rotate or if that is not what you want you could get something like T H I S by looping through the string and drawing each letter separately. something like x = 100 y=100 for c in "your text here": d.draw((x,y), c ...) #d is a draw instance y = y + 20 2008/8/19 ersen kavak : > Dear all; > I am a new Python user. I am enjoying the imaging capabilities of python > currently. > I am using PIL module. However, in spite of my long searches over forums, > books and the internet I could not manage to print a text in vertical > direction onto an image. > I am guessing that this should be possible, but... > Any suggestions are very wellcome ? > > Best Regards > > -- > Ersen Kavak > Karolinska Universitetssjukhuset Solna > CCK, R8:05 > 171 76 Stockholm > Lab: +46851770585 > Mobile: +46707875729 > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > From ashishbitsgoa at gmail.com Thu Aug 21 08:06:56 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Thu, 21 Aug 2008 11:36:56 +0530 Subject: [Image-SIG] problem in converting pixel data to image file In-Reply-To: References: <1219164143.13698.45.camel@lieryan-laptop> Message-ID: hey frnds Thanks for your help and support. My task is almost complete but i still face a few last problems : 1. The file being saved in ppm format using PIL is p6 type...i need to know is there a way that i can use PIL to save ppm images in p3 format 2. Also, the file being created has the header - P6 128 128 255 I need to change the 255 to 15...so that (15,15,15) becomes white and so on And to answer the obvious question that how do i know the job is almost complete, the image that i get right now is almost plain black (because my r,g,b values r in 0-15 range wheras max values is 255). But when i add 100 to each component r,g,b of each pixel, I get an image which is faintly reminiscent of my original image in rgb 8:8:8 color space Plz Help From HAWRYLA at novachem.com Wed Aug 20 20:06:06 2008 From: HAWRYLA at novachem.com (Andrew Hawryluk) Date: Wed, 20 Aug 2008 12:06:06 -0600 Subject: [Image-SIG] PIL - 1.1.6, Centroid In-Reply-To: <59dee0170808192131o3f1feaafk2745887bebf4e77b@mail.gmail.com> Message-ID: <48C01AE7354EC240A26F19CEB995E943033AEEB4@CHMAILMBX01.novachem.com> One option is to use Numpy/Scipy: import Image import numpy as n im = Image.Open(...) data = n.asarray(im) There is a center_of_mass function in scipy.ndimage.measurements. Andrew -----Original Message----- From: image-sig-bounces+hawryla=novachem.com at python.org [mailto:image-sig-bounces+hawryla=novachem.com at python.org]On Behalf Of Ashish Asgekar Sent: 19 Aug 2008 10:31 PM To: image-sig at python.org Subject: [Image-SIG] PIL - 1.1.6, Centroid Hello I was looking for Centroid function in Python and downloaded PIL-1.1.6. I learnt that Centroid function is available as Crack Code. However, when I search for CrackCode, I find it is not available anymore from PythonWare. My questions are: 1) Is CrackCode available in PIL-1.1.6 in some other form? 2) Can I compute Centroid of an image using some other existing function? Thank you. -- ashish -- ----------------------------------------------------------------------------- Dr. Ashish Asgekar Physics Group, BITS Pilani-Goa Campus, Zuarinagar, Goa. India 403 726 www.bits-goa.ac.in/Departments/Physics/Faculty.htm ----------------------------------------------------------------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From cannon.el at gmail.com Thu Aug 21 03:39:58 2008 From: cannon.el at gmail.com (Laura & Edward Cannon) Date: Wed, 20 Aug 2008 18:39:58 -0700 Subject: [Image-SIG] PIL - 1.1.6, Centroid In-Reply-To: <59dee0170808192131o3f1feaafk2745887bebf4e77b@mail.gmail.com> References: <59dee0170808192131o3f1feaafk2745887bebf4e77b@mail.gmail.com> Message-ID: using the Image.load() function to create a pixel access object and loop through the file. g = a.load() #a is an image for i in xrange(width): for j in xrange(height): #do computations here also take a look at the ImageStat module, which might save some work, as well as being faster. 2008/8/19 Ashish Asgekar : > Hello > I was looking for Centroid function in Python and downloaded PIL-1.1.6. I > learnt that Centroid function is available as Crack Code. However, when I > search for CrackCode, I find it is not available anymore from PythonWare. > My questions are: > 1) Is CrackCode available in PIL-1.1.6 in some other form? > 2) Can I compute Centroid of an image using some other existing > function? > > Thank you. > -- ashish > > -- > ----------------------------------------------------------------------------- > Dr. Ashish Asgekar > Physics Group, > BITS Pilani-Goa Campus, > Zuarinagar, Goa. > India 403 726 > > www.bits-goa.ac.in/Departments/Physics/Faculty.htm > ----------------------------------------------------------------------------- > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > From fredrik at pythonware.com Mon Aug 25 20:58:36 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 25 Aug 2008 20:58:36 +0200 Subject: [Image-SIG] PIL - 1.1.6, Centroid In-Reply-To: <59dee0170808192131o3f1feaafk2745887bebf4e77b@mail.gmail.com> References: <59dee0170808192131o3f1feaafk2745887bebf4e77b@mail.gmail.com> Message-ID: Ashish Asgekar wrote: > I was looking for Centroid function in Python and downloaded > PIL-1.1.6. I learnt that Centroid function is available as Crack Code. > However, when I search for CrackCode, I find it is not available anymore > from PythonWare. > 1) Is CrackCode available in PIL-1.1.6 in some > other form? the CrackCode extension is no longer available, for licensing reasons. > 2) Can I compute Centroid of an image using some other > existing function? assuming that "im" contains a single feature (represented by non-zero pixels), the following function should do the trick: def get_centroid(im): sx = sy = n = 0 x0, y0, x1, y1 = im.getbbox() pix = im.load() for y in range(y0, y1): for x in range(x0, x1): if pix[x, y]: sx += x sy += y n += 1 return float(sx) / n + 0.5, float(sy) / n + 0.5 on my machine, the above can process about fourty 512x512 grayscale images per second. From ashishbitsgoa at gmail.com Tue Aug 26 11:01:35 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Tue, 26 Aug 2008 14:31:35 +0530 Subject: [Image-SIG] problem in converting pixel data to image file In-Reply-To: <1219421519.6882.25.camel@lieryan-laptop> References: <1219421519.6882.25.camel@lieryan-laptop> Message-ID: Hey all I am back with a new doubt (all be it in the same color space spectrum) MY doubts are regarding YUV color spectrum:- 1. How r yuv files saved in memory, I mean the format of yuv files and how can PIL open yuv files. 2. How to obtain Y,U,V data of individual pixels and convert YUV 4:4:4 to 4:2:0, 4:1:1, 4:2:2 and vice versa 3. I would be very thankful if you could point me towards some reading material regarding YUV conversions and also from where to download a sample YUV file to test run my codes. Thanks In Advance Ashish From ashishbitsgoa at gmail.com Tue Aug 26 11:12:02 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Tue, 26 Aug 2008 14:42:02 +0530 Subject: [Image-SIG] VUV color space conversions?? Message-ID: Hey all I am back with a new doubt (all be it in the same color space spectrum) MY doubts are regarding YUV color spectrum:- 1. How r yuv files saved in memory, I mean the format of yuv files and how can PIL open yuv files. 2. How to obtain Y,U,V data of individual pixels and convert YUV 4:4:4 to 4:2:0, 4:1:1, 4:2:2 and vice versa 3. I would be very thankful if you could point me towards some reading material regarding YUV conversions and also from where to download a sample YUV file to test run my codes. Thanks In Advance Ashish From shiva at analogiccontrols.com Tue Aug 26 14:27:27 2008 From: shiva at analogiccontrols.com (SHIVA) Date: Tue, 26 Aug 2008 17:57:27 +0530 Subject: [Image-SIG] 3-bit color palette Message-ID: <200808261204.m7QC4BuQ026528@web335.linux-hosting.com> Can you provide 3bit image converter for our color graphic display drivers development purpose Regards shiva -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Tue Aug 26 18:21:17 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 26 Aug 2008 18:21:17 +0200 Subject: [Image-SIG] 3-bit color palette In-Reply-To: <200808261204.m7QC4BuQ026528@web335.linux-hosting.com> References: <200808261204.m7QC4BuQ026528@web335.linux-hosting.com> Message-ID: SHIVA wrote: > Can you provide 3bit image converter for our color graphic display > drivers development purpose that's impossible to tell, given the complete lack of details in your post. From fredrik at pythonware.com Tue Aug 26 18:29:28 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 26 Aug 2008 18:29:28 +0200 Subject: [Image-SIG] VUV color space conversions?? In-Reply-To: References: Message-ID: Ashish Sethi wrote: > I am back with a new doubt (all be it in the same color space spectrum) > MY doubts are regarding YUV color spectrum:- (I suspect you mean "question" here, not "doubt"; the latter usually implies disagreement. see http://www.perlmonks.org/?node_id=444996 ) > 1. How r yuv files saved in memory, I mean the format of yuv files and > how can PIL open yuv files. depends on the file format. PIL doesn't support any file format that supports the YUV color space (the closest you get is YCrCb). > 2. How to obtain Y,U,V data of individual pixels and convert YUV 4:4:4 > to 4:2:0, 4:1:1, 4:2:2 and vice versa that's chroma subsampling; see http://en.wikipedia.org/wiki/Chroma_subsampling From Chris.Barker at noaa.gov Tue Aug 26 22:30:30 2008 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Tue, 26 Aug 2008 13:30:30 -0700 Subject: [Image-SIG] PIL on Mac OS X 10.5 In-Reply-To: References: Message-ID: <48B467E6.1020800@noaa.gov> Fredrik Lundh wrote: > just for the archives: Matt Kangas recently posted a workaround showing > how to use the pythonmac.org PIL build with the original OS X Python: > > http://www.p16blog.com/p16/2008/05/appengine-installing-pil-on-os-x-1053.html > > > (not a mac user myself, so I cannot verify that this works. comments > and clarifications from the resident mac experts are welcome.) yup, that should work. I don't have 10.5, so I can't tell you for sure. However, for future reference, the last time we discussed this here, we "determined" that there was no (easy) way to build a single installer that would work with either python build. However, Robin Dunn has just done that with wxPython. His trick is to put that actually package into /usr/local/bin, then install two symlinks to it, one from each of the python locations. It's a bit weird, but it seems to work pretty well. Maybe for the next release. -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 pirmin.moesle at alpstein.de Wed Aug 27 12:18:53 2008 From: pirmin.moesle at alpstein.de (pirmin.moesle at alpstein.de) Date: Wed, 27 Aug 2008 10:18:53 +0000 Subject: [Image-SIG] Converting 32Bit png to 8Bit png Message-ID: Hi guys, I'm currently using pngnq (pngnq.sourceforge.net/) for postprocessing my pngs - converting the 32Bit RGBA pngs to 8Bit pngs. Is there a way using PIL to prevent myself from the postprocessing job. I do exactly need 2 ways of processing: a) Convert the 32Bit RGBA png to a 8Bit RGB palette png a) Convert the 32Bit RGBA png to a 8Bit RGBA palette png Quite a lot research didn't answered my question. Hopefully I get some ideas here. Thanks in advance. From fredrik at pythonware.com Wed Aug 27 13:51:12 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 27 Aug 2008 13:51:12 +0200 Subject: [Image-SIG] Converting 32Bit png to 8Bit png In-Reply-To: References: Message-ID: pirmin.moesle at alpstein.de skrev: > I do exactly need 2 ways of processing: > > a) Convert the 32Bit RGBA png to a 8Bit RGB palette png how do you want to treat the alpha layer when doing this? > a) Convert the 32Bit RGBA png to a 8Bit RGBA palette png same here. (PIL's standard conversion just drops the alpha, but there are ways to get around that.) From ashishbitsgoa at gmail.com Fri Aug 29 07:56:51 2008 From: ashishbitsgoa at gmail.com (Ashish Sethi) Date: Fri, 29 Aug 2008 11:26:51 +0530 Subject: [Image-SIG] Converting PPM-P3 file type to PPM-P6 file type Message-ID: Hey freinds, I have a problem...PIL doesnt understand PPM-P3 (ascii) file type. It only accepts PPM-P6 (binary) as an image file.Since I am dealing with both these file types and wish to use python for my processing tasks..I descided to create a script to convert P3 to P6 type...here is my code : import Image import string im=open("C:\\Documents and Settings\\ashishs trainee\\Desktop\\lena3.ppm") x=im.readline() x=x.rstrip("\r\n") print x if x=="P3": y=im.readline() z=im.readline() y=y.rstrip("\r\n") a=string.split(y,' ') m,n=a ftype='P6' ppmfile=open('C:\\Documents and Settings\\ashishs trainee\\Desktop\\lena5.ppm','wb') ppmfile.write("%s\n" % (ftype)) ppmfile.write("%d %d\n" % (int(m),int(n))) ppmfile.write("255\n") q=im.readline() while (q!=''): q=q.rstrip("\r\n") a=string.split(q,' ') red,green,blue=a red=int(red) green=int(green) blue=int(blue) ppmfile.write("%c%c%c" % (red,green,blue)) q=im.readline() ppmfile.close() i=Image.open("C:\\Documents and Settings\\ashishs trainee\\Desktop\\lena5.ppm") i.show() The file created using this script is an truncated image which when viewed using xv shows the correct image but with python gives the following error : Traceback (most recent call last): File "C:/ash/imaging/p3_2_p6.py", line 38, in i.show() File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1449, in show _showxv(self, title, command) File "C:\Python25\Lib\site-packages\PIL\Image.py", line 2082, in _showxv file = image._dump(format=format) File "C:\Python25\Lib\site-packages\PIL\Image.py", line 476, in _dump self.load() File "C:\Python25\Lib\site-packages\PIL\ImageFile.py", line 192, in load raise IOError("image file is truncated (%d bytes not processed)" % len(b)) IOError: image file is truncated (381 bytes not processed) The first few lines of my input file are : P3 128 128 255 214 167 126 218 169 114 218 167 118 213 165 111 213 167 112 213 161 91 213 161 98 210 160 113 215 162 96 and so on Can you please tell me where am i going wrong?? From sittner at lkb.ens.fr Fri Aug 29 13:01:38 2008 From: sittner at lkb.ens.fr (assa sittner) Date: Fri, 29 Aug 2008 13:01:38 +0200 Subject: [Image-SIG] Generate .tif stack Message-ID: Hi There, I would like to generate a series of synthetic images, and then wrap them all up into a single-file .tif stack (like in metamorph or ImageJ). how can i do that in python? thanks, -- Assa Sittner Optics & Biology group, Physics Dept. Ecole Normale Superieure, Paris -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Sat Aug 30 09:34:01 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 30 Aug 2008 09:34:01 +0200 Subject: [Image-SIG] Generate .tif stack In-Reply-To: References: Message-ID: assa sittner wrote: > I would like to generate a series of synthetic images, and then wrap > them all up into a single-file .tif stack (like in metamorph or ImageJ). > how can i do that in python? you can use PIL to create the individual frames, but PIL doesn't contain any ready-made API for creating stacks; the simplest approach is probably to write the frames to disk, and then use the external "tiffcp" command to build the final file. outline: command = ["tiffcp"] # add options here, if any (e.g. for compression) for i in range(...): im = Image.new(...) ... framefile = "frame%d.tif" % i im.save(framefile) command.append(framefile) command.append("stack.tif") subprocess.call(command) # remove frame files here From haase at msg.ucsf.edu Sat Aug 30 10:56:45 2008 From: haase at msg.ucsf.edu (Sebastian Haase) Date: Sat, 30 Aug 2008 10:56:45 +0200 Subject: [Image-SIG] Generate .tif stack In-Reply-To: References: Message-ID: Hi Assa, Fredrik, I submitted a patch to this list some time ago that allows creating this kind of "multi page" TIFF files. Could this get applied to the trunk PIL version !? Regards, Sebastian Haase On Sat, Aug 30, 2008 at 9:34 AM, Fredrik Lundh wrote: > assa sittner wrote: > >> I would like to generate a series of synthetic images, and then wrap them >> all up into a single-file .tif stack (like in metamorph or ImageJ). >> how can i do that in python? > > you can use PIL to create the individual frames, but PIL doesn't contain any > ready-made API for creating stacks; the simplest approach is probably to > write the frames to disk, and then use the external "tiffcp" > command to build the final file. > > outline: > > command = ["tiffcp"] > # add options here, if any (e.g. for compression) > > for i in range(...): > im = Image.new(...) > ... > framefile = "frame%d.tif" % i > im.save(framefile) > command.append(framefile) > > command.append("stack.tif") > subprocess.call(command) > > # remove frame files here > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig >