From Richard.E.Brown at DARTWARE.COM Mon Sep 3 09:03:01 2007 From: Richard.E.Brown at DARTWARE.COM (Richard E. Brown) Date: 03 Sep 2007 03:03:01 -0400 Subject: [Image-SIG] Trouble building PIL 1.1.6 on MacOS X Intel Message-ID: <3225826@blitz.dartware.com> An embedded and charset-unspecified text was scrubbed... Name: not available Url: http://mail.python.org/pipermail/image-sig/attachments/20070903/25d7dfd4/attachment.txt From tim at concussion.cc Wed Sep 5 22:34:31 2007 From: tim at concussion.cc (Concussion GFX - Tim) Date: Wed, 05 Sep 2007 16:34:31 -0400 Subject: [Image-SIG] PSD support help Message-ID: <46DF12D7.5070801@concussion.cc> hey list! Is there any info on an updated plugin for PSD's (greater then version 3?) I have been playing around with PSD's in pil for the last couple of days and it has been hit and miss with getting PSD files to load. After digging a little deeper it turns out that if the bottom most layer (layer 0 i presume) has transparency, then it will not load the PSD file. If I create a new layer with a solid fill and move it to the bottom,save the PSD, then the PSD will load. If I comment out the following line, the PSD will load, but the channels are not lined up correctly. Also if there is an extra channel in the file, i get the same 'not lined-up' error in the rendered image. self.layers = _layerinfo(self.fp) Have a look at this jpg to see how the PSD are being displayed. http://www.concussion.cc/preview.jpg Thanks -Tim From jantod at gmail.com Thu Sep 6 17:09:40 2007 From: jantod at gmail.com (Janto Dreijer) Date: Thu, 6 Sep 2007 17:09:40 +0200 Subject: [Image-SIG] more descriptive error for image.paste Message-ID: I'd really appreciate it if Image.paste can be more explicit about what went wrong than just "ValueError: images do not match". I've been sitting here for at least an hour trying to figure out why the images are incompatible. Different color mode? Pasted image size != bbox size? bbox outside image? Wrong parmeters? Argh! Just tell me! Thanks Janto From premal at crestgarments.com Mon Sep 10 17:20:19 2007 From: premal at crestgarments.com (premal at crestgarments.com) Date: Mon, 10 Sep 2007 19:20:19 +0400 Subject: [Image-SIG] **VIRUS** Hi Message-ID: <142D05C69@tydex.ru> The original message was received at Mon, 10 Sep 2007 19:20:19 +0400 from 163.86.100.134 ----- The following addresses had permanent fatal errors ----- image-sig at python.org ----- Transcript of session follows ----- ... while talking to host 207.189.228.24: >>> RCPT To: <<< 550 MAILBOX NOT FOUND -------------- next part -------------- Kerio WinRoute Firewall email scanner found a virus in the following attachment: Name: instruction.zip Content type: application/octet-stream Additional information from antivirus: External AV verdict: Win32/Mydoom.R worm The attachment has been removed. From gandalf at shopzeus.com Tue Sep 11 13:45:53 2007 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Tue, 11 Sep 2007 13:45:53 +0200 Subject: [Image-SIG] Antialiased text on transparent image fails? Message-ID: <46E67FF1.70705@shopzeus.com> Hi All, I tried to put a text on a transparent image. Here is a test: import Image import ImageDraw import ImageFont img = Image.new('RGBA',(100,20),(255,0,0,0)) drawer = ImageDraw.Draw(img) fnt = ImageFont.truetype("Vera.ttf",20) # http://ftp.gnome.org/pub/GNOME/sources/ttf-bitstream-vera/1.10/ drawer.text((0,0),"ABCDE",font=fnt,fill="#00ff00") img.save("test.png") # Result image I'm working on a rendering engine but I created this example to show the problem. The rendering engine should be able to create an image with transparent parts, and one should be able to put the rendered image on top of any other image. The problem itself: font edges are interpolated between the background and foreground color. You can see it on the resulting image. If you open the created "test.png" file in GIMP and use the color picker tool then you can see values like: (203,52,0,52) (215,40,0,40) I think that this is bad. The background was fully transparent. If you put a green object on a fully transparent thing, you should never see any red in it. I believe that the result should be something like (0,52,0,52) (0,40,0,40) In other words, when antialiasing a text, the background pixel's color should be weighted with its transparency. In my example, the background pixel is fully red but should have zero weight. Workarounds? Working with black or white initial background is not a workaround, because PIL will darken/lighten the pixels. I used red+green just to make the problem more visible. A correct workaround is to use the actual target background that will finally be used, but it is not a good workaround. This is obvious: I want to render the result image once, then put it on different target images. Rendering the result image each time I need to put it on a target would be very slow. Can you please confirm if this is a bug in PIL? Comments welcome. Best, Laszlo -------------- next part -------------- A non-text attachment was scrubbed... Name: test.png Type: image/png Size: 1524 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20070911/29ca4ada/attachment.png From cyril.giraudon at free.fr Tue Sep 11 17:26:25 2007 From: cyril.giraudon at free.fr (cyril giraudon) Date: Tue, 11 Sep 2007 17:26:25 +0200 Subject: [Image-SIG] PIL Pixmap from XLIB Pixmap Message-ID: <46E6B3A1.2020704@free.fr> Hi, I 'm currently trying to write a xulrunner windowless plugin in python. Data are drawn in a xlib pixmap (a XID). I 'd like to know if it's possible to create a PIL image from XLIB Pixmap XID ? And then expose the image into this pximap. Under windows, plugins uses an HDC. PIL can expose images in HDC object, I 'd like the same behaviour under UNIX. Thanks a lot, Cyril. From justin2 at fagnani.com Wed Sep 12 01:04:14 2007 From: justin2 at fagnani.com (Justin Fagnani-Bell) Date: Tue, 11 Sep 2007 16:04:14 -0700 Subject: [Image-SIG] Antialias, Bicubic resampling not working... Message-ID: <3CAE6C6A-E82E-49FF-BC3E-A1E953170CF4@fagnani.com> I'm writing a thumb-nailing script that also rotates the thumbs, so I'm using both Image.thumbnail and Image.rotate. Neither antialiasing with thumbnail, or bicubic with rotate are working, adn the results look horrendous with nearest neighbor. I'm not getting any errors, and I haven't figured anything out by digging through the PIL source. I have version 1.1.6 installed via MacPorts. Any ideas? Thanks, Justin From cyril.giraudon at free.fr Wed Sep 12 10:11:31 2007 From: cyril.giraudon at free.fr (cyril giraudon) Date: Wed, 12 Sep 2007 10:11:31 +0200 Subject: [Image-SIG] PIL Pixmap from XLIB Pixmap In-Reply-To: <46E6B3A1.2020704@free.fr> References: <46E6B3A1.2020704@free.fr> Message-ID: <46E79F33.7050001@free.fr> Sorry, I wanted to say : I 'd like to know if it's possible to expose a PIL image into an XLIB Pixmap known by its XID ? (create a PIL Pixmap from an XID). Cyril. cyril giraudon a ?crit : > Hi, > > I 'm currently trying to write a xulrunner windowless plugin in python. > Data are drawn in a xlib pixmap (a XID). > > I 'd like to know if it's possible to create a PIL image from XLIB > Pixmap XID ? > And then expose the image into this pximap. > > Under windows, plugins uses an HDC. PIL can expose images in HDC object, > I 'd like the same behaviour under UNIX. > > Thanks a lot, > > Cyril. > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From connellybarnes at yahoo.com Thu Sep 13 07:57:02 2007 From: connellybarnes at yahoo.com (Connelly Barnes) Date: Wed, 12 Sep 2007 22:57:02 -0700 (PDT) Subject: [Image-SIG] Filter PIL images with arbitrary kernels via numpy and FFT Message-ID: <284800.85171.qm@web54304.mail.re2.yahoo.com> The Python Imaging Library currently only supports 3x3 and 5x5 image filters. Here's a module which uses numpy and the FFT to compute filters of arbitrary size: http://barnesc.blogspot.com/2007/09/filter-numpy-images-with-fft-python.html For an image and filter which contain a total of N pixels overall, it runs in O(N*log(N)) time; however, numpy's FFT isn't too fast and so in practice other methods may be more appropriate to compute filters quickly, as described in the blog post linked above. Connelly Barnes http://www.connellybarnes.com/ ____________________________________________________________________________________ Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase. http://farechase.yahoo.com/ From coen at reservoir.nl Fri Sep 14 15:36:00 2007 From: coen at reservoir.nl (Coen van der Kamp) Date: Fri, 14 Sep 2007 15:36:00 +0200 Subject: [Image-SIG] Antialiased text on transparent image fails? In-Reply-To: <46E67FF1.70705@shopzeus.com> References: <46E67FF1.70705@shopzeus.com> Message-ID: <46EA8E40.8050307@reservoir.nl> Hi Laszlo, Isn't this the way it should work? The alpha value of a pixel is treated the same way as any other channel. When a pixel is half covered by a shape, PIL wil draw 50% of the foreground and 50% of the background. In your case: a green shape 0, 255, 0, 255 (rgba) and background 255, 0, 0, 0. If you take the average of the two you come up with R=128 in the pixel and will be visible for 50% A=128. Isn't this the desired effect? And if it would be a color? Don't you want the same to happen? The solution? Render the shape on a 0,0,0,0 background. No red will be added, your half filled pixel with a correct alpha value will blend with new backgrounds as it is supposed to. You can save this image in various ways for later use. Just my thought... and i hope it helps. Greetings, Coen Laszlo Nagy wrote: > > Hi All, > > I tried to put a text on a transparent image. Here is a test: > > import Image > import ImageDraw > import ImageFont > > img = Image.new('RGBA',(100,20),(255,0,0,0)) > drawer = ImageDraw.Draw(img) > fnt = ImageFont.truetype("Vera.ttf",20) # > http://ftp.gnome.org/pub/GNOME/sources/ttf-bitstream-vera/1.10/ > drawer.text((0,0),"ABCDE",font=fnt,fill="#00ff00") > img.save("test.png") # Result image > > I'm working on a rendering engine but I created this example to show > the problem. The rendering engine should be able to create an image > with transparent parts, and one should be able to put the rendered > image on top of any other image. > > The problem itself: font edges are interpolated between the background > and foreground color. You can see it on the resulting image. If you > open the created "test.png" file in GIMP and use the color picker tool > then you can see values like: > > (203,52,0,52) > (215,40,0,40) > > > I think that this is bad. The background was fully transparent. If you > put a green object on a fully transparent thing, you should never see > any red in it. I believe that the result should be something like > > (0,52,0,52) > (0,40,0,40) > > In other words, when antialiasing a text, the background pixel's color > should be weighted with its transparency. In my example, the > background pixel is fully red but should have zero weight. > > Workarounds? > > Working with black or white initial background is not a workaround, > because PIL will darken/lighten the pixels. I used red+green just to > make the problem more visible. A correct workaround is to use the > actual target background that will finally be used, but it is not a > good workaround. This is obvious: I want to render the result image > once, then put it on different target images. Rendering the result > image each time I need to put it on a target would be very slow. > > Can you please confirm if this is a bug in PIL? Comments welcome. > > Best, > > Laszlo > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------ > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From btvlinux at orange.nl Sun Sep 16 14:36:51 2007 From: btvlinux at orange.nl (Bauke Veenstra) Date: Sun, 16 Sep 2007 14:36:51 +0200 Subject: [Image-SIG] PSDraw instance has no attribute 'textsize' Message-ID: <1189946211.6008.0.camel@localhost.localdomain> Running the example from the excellent PIL handbook gives an error, after these two lines: ps.setfont("HelveticaNarrow-Bold", 36) w, h, b = ps.textsize(title) AttributeError: PSDraw instance has no attribute 'textsize' This error occurred on my Linux and on my Windows system. Regards, Bauke From bloominator at hotmail.com Fri Sep 14 04:50:39 2007 From: bloominator at hotmail.com (Gary Bloom) Date: Thu, 13 Sep 2007 22:50:39 -0400 Subject: [Image-SIG] PIL DPI trouble Message-ID: Howdy! I notice that the PIL has trouble playing with the DPI of other programs and image standards: when I create a file with Paint Shop Pro or Photoshop, the PIL routines can't properly recognize the DPI. And when I create an image file (via the save method) of PIL, setting the DPI, those same two programs can't read the DPI as set by them. Is there a workaround for this? Other than this one issue, I have found the PIL to be a BLAST! :) Thanks! Gary Bloom -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070913/84ead2b5/attachment.htm From e.man.69 at gmail.com Fri Sep 14 18:24:27 2007 From: e.man.69 at gmail.com (E.Masta) Date: Fri, 14 Sep 2007 12:24:27 -0400 Subject: [Image-SIG] Installation not succesful on Vista Message-ID: <8bc5ff710709140924p2f424669ode1e6a250875b68@mail.gmail.com> When I try to install, it spews some error messages. Can you tell me what to do? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070914/4d66b450/attachment.htm From fredrik at pythonware.com Mon Sep 17 00:36:28 2007 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 17 Sep 2007 00:36:28 +0200 Subject: [Image-SIG] 1.1.5 and 1.1.6 compatibility issues In-Reply-To: <469B6484.8020105@redhat.com> References: <469B6484.8020105@redhat.com> Message-ID: Joel Andres Granados wrote: > Is version 1.1.6 backward compatible with 1.1.5? Yes, with the possible exception of code that relies on bugs or undefined behaviour. See the CHANGES document in the source distribution for more details. From fredrik at pythonware.com Mon Sep 17 00:46:32 2007 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 17 Sep 2007 00:46:32 +0200 Subject: [Image-SIG] Installation not succesful on Vista In-Reply-To: <8bc5ff710709140924p2f424669ode1e6a250875b68@mail.gmail.com> References: <8bc5ff710709140924p2f424669ode1e6a250875b68@mail.gmail.com> Message-ID: E.Masta wrote: > When I try to install, it spews some error messages. Can you tell me > what to do? Telling us what the error messages are might help. From fredrik at pythonware.com Mon Sep 17 00:47:56 2007 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 17 Sep 2007 00:47:56 +0200 Subject: [Image-SIG] Antialias, Bicubic resampling not working... In-Reply-To: <3CAE6C6A-E82E-49FF-BC3E-A1E953170CF4@fagnani.com> References: <3CAE6C6A-E82E-49FF-BC3E-A1E953170CF4@fagnani.com> Message-ID: Justin Fagnani-Bell wrote: > I'm writing a thumb-nailing script that also rotates the thumbs, so > I'm using both Image.thumbnail and Image.rotate. Neither antialiasing > with thumbnail, or bicubic with rotate are working, adn the results > look horrendous with nearest neighbor. I'm not getting any errors, > and I haven't figured anything out by digging through the PIL source. > I have version 1.1.6 installed via MacPorts. What's the "mode" attribute for these images? Does it work better if you do image = image.convert("RGB") first? From lucadex at gmail.com Mon Sep 17 09:36:16 2007 From: lucadex at gmail.com (Luca De Santis) Date: Mon, 17 Sep 2007 09:36:16 +0200 Subject: [Image-SIG] PIL DPI trouble In-Reply-To: References: Message-ID: <2ce6cd010709170036x29666383rff5f5a7c9c2a164b@mail.gmail.com> That's exactly the same problem I incurred into. I tried PIL version 1.1.6 on a Mac OS X 10.4 and on an old Linux box and can't get the DPI attribute for JPEG and PNG files that I've created with Photoshop. I tested that both on Python 2.5 and Python 2.1.3 with the same result. I tried also to update libjpeg on Linux but nothing changes. Any help on that is greatly appreciated. TIA. Ciao, Luca On 9/14/07, Gary Bloom wrote: > I notice that the PIL has trouble playing with the DPI of other programs and > image standards: when I create a file with Paint Shop Pro or Photoshop, the > PIL routines can't properly recognize the DPI. And when I create an image > file (via the save method) of PIL, setting the DPI, those same two programs > can't read the DPI as set by them. Is there a workaround for this? > > Other than this one issue, I have found the PIL to be a BLAST! :) > > Thanks! > > Gary Bloom -- Luca De Santis Pisa, Italy From justin2 at fagnani.com Mon Sep 17 19:10:32 2007 From: justin2 at fagnani.com (Justin Fagnani-Bell) Date: Mon, 17 Sep 2007 10:10:32 -0700 Subject: [Image-SIG] Antialias, Bicubic resampling not working... In-Reply-To: References: <3CAE6C6A-E82E-49FF-BC3E-A1E953170CF4@fagnani.com> Message-ID: <21CAAD36-53F6-446E-A010-ED863F8E3A30@fagnani.com> So the mode was P and converting to RGB fixed the thumbnail issue, but it didn't fix the rotate problem. It very noticeable, because I'm using expand=True with a white background test image, and the edges are very jagged. I'm saving as a PNG, and there's pretty much nothing going on other than a thumbnail and rotate. Any other ideas? Thanks a lot, Justin On Sep 16, 2007, at 3:47 PM, Fredrik Lundh wrote: > Justin Fagnani-Bell wrote: > >> I'm writing a thumb-nailing script that also rotates the thumbs, so >> I'm using both Image.thumbnail and Image.rotate. Neither antialiasing >> with thumbnail, or bicubic with rotate are working, adn the results >> look horrendous with nearest neighbor. I'm not getting any errors, >> and I haven't figured anything out by digging through the PIL source. >> I have version 1.1.6 installed via MacPorts. > > What's the "mode" attribute for these images? Does it work better > if you do > > image = image.convert("RGB") > > first? > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From lucadex at gmail.com Fri Sep 21 12:12:24 2007 From: lucadex at gmail.com (Luca De Santis) Date: Fri, 21 Sep 2007 12:12:24 +0200 Subject: [Image-SIG] PIL DPI trouble - Solved Message-ID: <2ce6cd010709210312u7b7d474ct48bb877d7eb0c09b@mail.gmail.com> I found out that the behaviour of PIL was totally correct and simply Photoshop "adds" some more information sometimes when a JPEG file is opened. I summarize what I discovered here, hoping it might be useful to others. The JPEG standard doesn't cover a way to encode the resolution of a file but the JFIF extension does. For a quick and useful introduction to these concepts you can visit the Wikipedia page http://en.wikipedia.org/wiki/JFIF Here you can find a very useful table with the byte map of a JFIF file. In particular the "Density Units" field is a byte with three possible values: * 0 - No units, aspect ratio only specified * 1 - Pixels per Inch * 2 - Pixels per Centimetre With a value of Density Units == 1 or == 2 you can get the resolution information in the next two fields (2 bytes long each), that is "X Density" and "Y Density". Of course these map exactly "dpi" when Density Units == 1. For all the images that I opened with PIL and couldn't find the dpi attribute I "hex-dumped" them and found out the following values for these fields: * Density Unit: 0 * X Density: 1 * Y Density: 1 I assume that in these cases Photoshop simply sets the resolution to the default for screens (which is 72 dpi at least on the Mac). Correctly PIL doesn't set the dpi attribute in the "info" dictionary. To cut this long story short... I was wrong and PIL rocks hard! :-) Hope my experience could help others. Ciao, Luca Luca De Santis Pisa, Italy On 9/17/07, Luca De Santis wrote: > That's exactly the same problem I incurred into. > I tried PIL version 1.1.6 on a Mac OS X 10.4 and on an old Linux box > and can't get the DPI attribute for JPEG and PNG files that I've > created with Photoshop. > > I tested that both on Python 2.5 and Python 2.1.3 with the same result. > > I tried also to update libjpeg on Linux but nothing changes. > > Any help on that is greatly appreciated. > TIA. From bloominator at hotmail.com Fri Sep 21 21:28:57 2007 From: bloominator at hotmail.com (Gary Bloom) Date: Fri, 21 Sep 2007 15:28:57 -0400 Subject: [Image-SIG] PIL DPI trouble - Solved References: <2ce6cd010709210312u7b7d474ct48bb877d7eb0c09b@mail.gmail.com> Message-ID: Hi Luca, Thanks for shedding some light on this topic. However, what you've said has left me even more curious than before. There are still some things I don't understand... For one, why do Photoshop (PS) and Paint Shop Pro (PSP) play so nicely together when the PIL doesn't play along at all for DPI. If I create an image with certain DPI in Photoshop, Paint Shop Pro can read the image and see that set density, and vice versa. But the PIL doesn't recognize the DPI of either a PSP or Photoshop image. And of course neither PS or PSP recognize the DPI of a PIL image. So I'm a bit confused. You say that PIL seems to be "playing by the rules" and adhering to the JFIF standard. (My images are both TIFF and JPEG, but I'm guessing that it's the same problem regardless of which image type it is.), yet PSP and PS cannot read the DPI of these PIL-processed images. This doesn't make sense to me. If, what you say below is true and PSP and PS are adding "extra stuff" outside of the JFIF standard, is it coincidental that they can understand one another? And, even if they are both writing (and reading the other's) non-standard DPI info, shouldn't the PIL be foresighted enough to have a "compatibility mode"' for that "extra stuff"? Sometimes just adhering blindly to a standard is a good thing, unless the rest of the world is ignoring the standard, which is what it seems PSP and PS are doing. So do you have any idea how to make the PIL compatible with these other programs? At work my company has a product which also deals with images, and one day I imported an image that I had resized and changed the DPI of it via the PIL, and it made our software crash. This has never happened when using any other program to manipulate images. Any thoughts on this? Or perhaps can you point me to someone who can shed even more light on the matter? Thanks so much for your reply, Gary ----- Original Message ----- From: "Luca De Santis" To: Cc: Sent: Friday, September 21, 2007 6:12 AM Subject: PIL DPI trouble - Solved >I found out that the behaviour of PIL was totally correct and simply > Photoshop "adds" some more information sometimes when a JPEG file is > opened. > > I summarize what I discovered here, hoping it might be useful to others. > > The JPEG standard doesn't cover a way to encode the resolution of a > file but the JFIF extension does. For a quick and useful introduction > to these concepts you can visit the Wikipedia page > http://en.wikipedia.org/wiki/JFIF > Here you can find a very useful table with the byte map of a JFIF file. > > In particular the "Density Units" field is a byte with three possible > values: > * 0 - No units, aspect ratio only specified > * 1 - Pixels per Inch > * 2 - Pixels per Centimetre > With a value of Density Units == 1 or == 2 you can get the resolution > information in the next two fields (2 bytes long each), that is "X > Density" and "Y Density". Of course these map exactly "dpi" when > Density Units == 1. > > For all the images that I opened with PIL and couldn't find the dpi > attribute I "hex-dumped" them and found out the following values for > these fields: > * Density Unit: 0 > * X Density: 1 > * Y Density: 1 > > I assume that in these cases Photoshop simply sets the resolution to > the default for screens (which is 72 dpi at least on the Mac). > Correctly PIL doesn't set the dpi attribute in the "info" dictionary. > > To cut this long story short... I was wrong and PIL rocks hard! :-) > > Hope my experience could help others. > > Ciao, > Luca > > Luca De Santis > Pisa, Italy > > On 9/17/07, Luca De Santis wrote: >> That's exactly the same problem I incurred into. >> I tried PIL version 1.1.6 on a Mac OS X 10.4 and on an old Linux box >> and can't get the DPI attribute for JPEG and PNG files that I've >> created with Photoshop. >> >> I tested that both on Python 2.5 and Python 2.1.3 with the same result. >> >> I tried also to update libjpeg on Linux but nothing changes. >> >> Any help on that is greatly appreciated. >> TIA. > From jcupitt at gmail.com Sat Sep 22 12:51:23 2007 From: jcupitt at gmail.com (jcupitt at gmail.com) Date: Sat, 22 Sep 2007 11:51:23 +0100 Subject: [Image-SIG] PIL DPI trouble - Solved In-Reply-To: <2ce6cd010709210312u7b7d474ct48bb877d7eb0c09b@mail.gmail.com> References: <2ce6cd010709210312u7b7d474ct48bb877d7eb0c09b@mail.gmail.com> Message-ID: <522c6460709220351q7e95fd04s702aaaec5a4dc27d@mail.gmail.com> On 9/21/07, Luca De Santis wrote: > The JPEG standard doesn't cover a way to encode the resolution of a > file but the JFIF extension does. For a quick and useful introduction > to these concepts you can visit the Wikipedia page > http://en.wikipedia.org/wiki/JFIF > Here you can find a very useful table with the byte map of a JFIF file. My understanding is that EXIF has now pretty much replaced the JFIF resolution system. http://en.wikipedia.org/wiki/Exif I think most image processing systems use EXIF to put DPI information into JPEG images. PIL will read EXIF tags from a JPEG image, but (as far as I can see) will not write tags back again. Googling for "PIL EXIF" seems uncertain anyway. John From khademi.somayeh63 at gmail.com Sun Sep 23 09:37:37 2007 From: khademi.somayeh63 at gmail.com (somayeh khademi) Date: Sun, 23 Sep 2007 11:07:37 +0330 Subject: [Image-SIG] screenshot in python Message-ID: <7e7b076d0709230037t2b621f1bjd0a755a1103db850@mail.gmail.com> Hello, I want write a screenshot with python, Has python any module related it? please help me about it. Thank for future help. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070923/2b659739/attachment.htm From douglas at paradise.net.nz Mon Sep 24 03:48:49 2007 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Mon, 24 Sep 2007 13:48:49 +1200 Subject: [Image-SIG] crop is a little too lazy (with patch) Message-ID: <46F71781.60806@paradise.net.nz> A cropped image does not return a pixel access object when load()ed. This seems to be a simple oversight. >>> im = Image.new('L',(50,50)) >>> im.load() >>> im2 = im.crop((0, 0, 20, 20)) >>> im2.load() None There is an easy workaround: >>> im2.im.pixel_access() and the patch below cures the problem. douglas --------------------------------------------- --- Image-old.py 2007-09-24 13:19:30.000000000 +1200 +++ Image-new.py 2007-09-24 13:19:17.000000000 +1200 @@ -1666,6 +1666,8 @@ if self.__crop: self.im = self.im.crop(self.__crop) self.__crop = None + if self.im: + return self.im.pixel_access(self.readonly) # FIXME: future versions should optimize crop/paste # sequences! From fredrik at pythonware.com Mon Sep 24 18:33:45 2007 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 24 Sep 2007 18:33:45 +0200 Subject: [Image-SIG] SGI format In-Reply-To: <46C985DC.F393DA00@wadsworth.org> References: <46C985DC.F393DA00@wadsworth.org> Message-ID: William Baxter wrote: > Does anyone have any experience with the SGI RGB format? The PIL > documentation says SGI images are 'read only'. Image does open them, but > then it seems you can't get at the data. Any convert, copy, getpixel > commands give an error: > > raise IOError("decoder %s not available" % decoder_name) > IOError: decoder sgi_rle not available PIL only reads uncompressed SGI images; the reference to "sgi_rle" indicates that your images are run-length encoded. Unfortunately, I cannot say that improving the SGI support is high on my todo-list; the SGI driver was written in September 1995 (!), and I don't think anyone's ever asked about this since then... From short.jones.cipher at gmail.com Tue Sep 25 04:39:04 2007 From: short.jones.cipher at gmail.com (Christopher Jones) Date: Tue, 25 Sep 2007 12:39:04 +1000 Subject: [Image-SIG] PIL histogram bin 255 empty Message-ID: <25825ac50709241939wf4fb83dve4ed838805125c9@mail.gmail.com> With mode I images, the histogram method sometimes returns bin 255 empty, counting the getextrema maximum value in bin 254 instead. Is this a bug or is bin 255 treated in a special way, perhaps to count clipped pixels? Chris Jones -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20070925/8f9ad06e/attachment.htm From fredrik at pythonware.com Tue Sep 25 09:39:33 2007 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 25 Sep 2007 09:39:33 +0200 Subject: [Image-SIG] PIL histogram bin 255 empty In-Reply-To: <25825ac50709241939wf4fb83dve4ed838805125c9@mail.gmail.com> References: <25825ac50709241939wf4fb83dve4ed838805125c9@mail.gmail.com> Message-ID: Christopher Jones wrote: > With mode I images, the histogram method sometimes returns bin 255 > empty, counting the getextrema maximum value in bin 254 instead. Is this > a bug or is bin 255 treated in a special way, perhaps to count clipped > pixels? what is the getextrema() when this happens? my guess is that it's a rounding error in the histogram code; it basically does scale = 255.0F / (max - min); for each pixel: i = (int) ((pixel-min)*scale); if (i >= 0 && i < 256) histogram[i]++; I don't have time to verify this right now, but I guess changing the index calculation to: i = (int) ((pixel-imin)*scale + 0.5); would take care of this. (the whole histogram-of-I/F approach feels a bit odd; not sure why it was done that way, really). From lucadex at gmail.com Wed Sep 26 16:30:42 2007 From: lucadex at gmail.com (Luca De Santis) Date: Wed, 26 Sep 2007 16:30:42 +0200 Subject: [Image-SIG] PIL DPI trouble - Solved In-Reply-To: References: <2ce6cd010709210312u7b7d474ct48bb877d7eb0c09b@mail.gmail.com> Message-ID: <2ce6cd010709260730q261998e9q33a946afdda3181e@mail.gmail.com> > .... > Any thoughts on this? Or perhaps can you > point me to someone who can shed even more light on the matter? Hi Gary sorry if it took me some time to get back on this topic. I made a couple of tests, that I describe below, which seems to confirm the correct behavior of PIL in managing the dpi of JPEGs. Take everything "with a grain of salt" since I'm not an expert on the subject: I just followed an empiric method which seems quite sound. First of all, I'm dealing with JPEGs so I can't say if what I'm doing applies to other file formats. My test environment consists of Python 2.1.3 (I used also Python 2.5 with no apparent changes), PIL 1.1.6 on a Mac OS X 10.4. I'm reading images with Photoshop 7 plus Preview and Graphic Converter 5.9.5 which are Mac specific applications. # First test: reading a JPEG image # I started from a simple JPEG created from Photoshop and saved at 150 dpi (image.jpg). Hexdumping the image I get, as expected, the following values for the field of the JFIF Segment (cfr. http://en.wikipedia.org/wiki/JFIF#JFIF_Segment_Format ): * Density Unit: 0x01 (dpi) * X/Y Density: 0x0096 (150) I read the image with PIL in the following way: >>> import Image >>> i = Image.open('image.jpg') >>> i.info['dpi'] (150, 150) Opening the image with the other two applications just gives the same value for the resolution. Now I opened again the image from Photoshop and saved it with the "Save for Web" option, using the name "image2.jpg". Hexdumping the image I had the following values for the JFIF attributes: * Density Unit: 0x00 (No units, aspect ratio only specified) * X/Y Density: 0x0064 (100) The 100 value seems to make sense because, according to the Density Unit value, it is the ratio (100%) by which you should use/visualize the image. Now with PIL you (correctly) can't read the dpi attribute anymore. >>> i = Image.open('image2.jpg') >>> i.info {'adobe_transform': 100, 'jfif_density': (100, 100), 'jfif_version': (1, 2), 'adobe': 100, 'jfif_unit': 0, 'jfif': 258} Opening the image again with Photoshop and selecting the "Image size" option you get 72 dpi but this seems a sort of default behavior of this application. Preview for example lefts blank in this case the dpi attribute, while Graphic Converter must have a bug since it thinks that the resolution is 100 dpi! _Conclusion_: PIL seems to interpret correctly the JFIF attributes. PIL also reads the EXIF attributes if present: they are stored in the 'app' dictionary associated to the Image instance. # Second test: saving a JPEG image # Things are a bit different when the JPEG image is saved through PIL, which _by default_ doesn't handle the dpi attribute (see also below). In fact, I opened again the 150 dpi image, and saved with name "image3.jpg" through PIL with the following commands: >>> i = Image.open('image.jpg') >>> i.info['dpi'] (150, 150) >>> i.save('image3.jpg') >>> i3 = Image.open('image3.jpg') >>> i3.info {'jfif_density': (1, 1), 'jfif_unit': 0, 'jfif': 257, 'jfif_version': (1, 1)} Hexdumping image3.jpg you get: * Density Unit: 0x00 (No units, aspect ratio only specified) * X/Y Density: 0x0001 Now, I don't really know if the correct value here should be 1 or 100 (I honestly assume 100, so probably this could be a PIL bug). If you want to maintain the original dpi with PIL when saving the image just do the following: i.save(filename, dpi=i.info['dpi']) In fact: >>> i = Image.open('image.jpg') >>> i.info['dpi'] (150, 150) >>> i.save('image4.jpg', dpi=i.info['dpi']) >>> i4 = Image.open('image4.jpg') >>> i4.info {'dpi': (150, 150), 'jfif_density': (150, 150), 'jfif_unit': 1, 'jfif': 257, 'jfif_version': (1, 1)} Hexdumping this new image I got: * Density Unit: 0x01 (dpi) * X/Y Density: 0x0096 (150) and all the applications, Photoshop included, recognize the right resolution (150dpi) for the image. _Conclusion_: Just remember to specify the 'dpi' parameter when saving a JPEG whose resolution should be different than 72dpi. Sorry if I wrote too much! I honestly don't know other things on that so I hoped I helped to shed some light on this matter. Ciao, Luca Luca De Santis, Pisa, Italy From jefflwise at verizon.net Thu Sep 27 08:30:53 2007 From: jefflwise at verizon.net (Jeffrey Wise) Date: Thu, 27 Sep 2007 02:30:53 -0400 Subject: [Image-SIG] An algorithm to find connected groups of pixels Message-ID: <001801c800cf$f5a76e00$0401a8c0@Willow> Hi, I'm in my first week with PIL and doing well - it's a tremendous library! I've gotten to the point in my image analysis that I need to find all the groups of connected pixels in an image. These groups form arbitrary shapes in the image. I want to preserve the shape information for each group, so I can compare/analyze/categorize... it later. The image is composed of pixels of value 0 or 255 in "L" B&W format. I assume such an algorithm will need to find a pixel of value 255 and then check in every direction about it for a neighbor that is 255 too. The algorithm would presumably recurse to find neighbors of the neighbor, etc. I suspect the trick in this algorithm is the data structures needed to keep track of the discovered adjacencies. I have loaded the image into the 2D array-like accessor, so I have free access to each pixel. I haven't noticed such an algorithm in the PIL yet; maybe I've missed it. Or perhaps there is Python code available to do this algorithm? Any ideas? Thanks, .Jeff Wise From ggerber at sun.ac.za Thu Sep 27 11:55:40 2007 From: ggerber at sun.ac.za (George Gerber) Date: Thu, 27 Sep 2007 11:55:40 +0200 Subject: [Image-SIG] PIL 1.1.5 & 1.1.6 'png decoding error' Message-ID: <46FB7E1C.3060905@sun.ac.za> Hi. PIL 1.1.5 and 1.1.6 cannot load the png: http://www.ggerber.globesky.com/phd%5Fsite/Stat1Hz_frame_0041.png I get: "IOError: decoding error when reading image file" However both versions can load this png: http://www.ggerber.globesky.com/phd%5Fsite/Stat1Hz_frame_0040.png Is there a work around for this error? I would like to work with numpy arrays. Hence using PIL 1.1.6 the code is: import Image from numpy import asarray img = Image.open('C:\Stat1Hz_frame_0041.png') raw = asarray(img) Regards George From jcupitt at gmail.com Thu Sep 27 12:45:37 2007 From: jcupitt at gmail.com (jcupitt at gmail.com) Date: Thu, 27 Sep 2007 11:45:37 +0100 Subject: [Image-SIG] An algorithm to find connected groups of pixels In-Reply-To: <001801c800cf$f5a76e00$0401a8c0@Willow> References: <001801c800cf$f5a76e00$0401a8c0@Willow> Message-ID: <522c6460709270345s6ce29883ke18364ac71d2373c@mail.gmail.com> Hi Jeff, On 9/27/07, Jeffrey Wise wrote: > I've gotten to the point in my image analysis that I need to find all the > groups of connected pixels in an image. These groups form arbitrary shapes > in the image. I want to preserve the shape information for each group, so I > can compare/analyze/categorize... it later. This is usually done with chain codes. Use a filter (and morphology?) and a threshold to turn your image into a set of edges, then search for part of the edge and trace around it, recording up/down/left/right movements. Once you have the boundary as a set of lines it's easy to calculate things like area and principal axis. > check in every direction about it for a neighbor that is 255 too. The > algorithm would presumably recurse to find neighbors of the neighbor, etc. > I suspect the trick in this algorithm is the data structures needed to keep > track of the discovered adjacencies. I have loaded the image into the 2D This sounds very like a flood-fill. You'll find if you recurse for each connection you will use huge amounts of stack. It's usually better to keep a list of candidates for later testing and iterate rather then recurse. You can also do it a line at a time rather than a point at a time. Write a function to fill to the right or left until it hits an edge, then add the point below to your undone list. You need much less memory and it'll run a lot quicker. But chain codes are probably a better bet. John From janssen at parc.com Thu Sep 27 18:31:59 2007 From: janssen at parc.com (Bill Janssen) Date: Thu, 27 Sep 2007 09:31:59 PDT Subject: [Image-SIG] An algorithm to find connected groups of pixels In-Reply-To: <001801c800cf$f5a76e00$0401a8c0@Willow> References: <001801c800cf$f5a76e00$0401a8c0@Willow> Message-ID: <07Sep27.093200pdt."57996"@synergy1.parc.xerox.com> The Leptonica library (www.leptonica.org) has some papers on how to do this (and code, thought it's in C -- I guess you could call it with ctypes). Bill From dblank at brynmawr.edu Thu Sep 27 19:57:32 2007 From: dblank at brynmawr.edu (Douglas S. Blank) Date: Thu, 27 Sep 2007 13:57:32 -0400 Subject: [Image-SIG] An algorithm to find connected groups of pixels In-Reply-To: <001801c800cf$f5a76e00$0401a8c0@Willow> References: <001801c800cf$f5a76e00$0401a8c0@Willow> Message-ID: <46FBEF0C.3000908@brynmawr.edu> Jeffrey Wise wrote: > Hi, > > I'm in my first week with PIL and doing well - it's a tremendous library! > I've gotten to the point in my image analysis that I need to find all the > groups of connected pixels in an image. These groups form arbitrary shapes > in the image. I want to preserve the shape information for each group, so I > can compare/analyze/categorize... it later. > > The image is composed of pixels of value 0 or 255 in "L" B&W format. I > assume such an algorithm will need to find a pixel of value 255 and then > check in every direction about it for a neighbor that is 255 too. The > algorithm would presumably recurse to find neighbors of the neighbor, etc. > I suspect the trick in this algorithm is the data structures needed to keep > track of the discovered adjacencies. I have loaded the image into the 2D > array-like accessor, so I have free access to each pixel. > > I haven't noticed such an algorithm in the PIL yet; maybe I've missed it. > Or perhaps there is Python code available to do this algorithm? Any ideas? Jeff, You can take a look at some code from Pyrobot, Python Robotics, that was written by a student: http://cvs.cs.brynmawr.edu/cgi-bin/viewcvs.cgi/pyrobot/vision/__init__.py?rev=HEAD&content-type=text/vnd.viewcvs-markup Start with the Blob class. We also have similar code in C++, and wrapped by Python using SWIG: http://cvs.cs.brynmawr.edu/cgi-bin/viewcvs.cgi/pyrobot/vision/cvision/Vision.cpp?rev=HEAD&content-type=text/vnd.viewcvs-markup If you are interested in image processing, robotics, or other camera-based functions, see our course materials here: http://pyrorobotics.org/?page=PyroModuleComputerVision -Doug > Thanks, > .Jeff Wise > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From douglas at paradise.net.nz Fri Sep 28 01:06:55 2007 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Fri, 28 Sep 2007 11:06:55 +1200 Subject: [Image-SIG] An algorithm to find connected groups of pixels In-Reply-To: <001801c800cf$f5a76e00$0401a8c0@Willow> References: <001801c800cf$f5a76e00$0401a8c0@Willow> Message-ID: <46FC378F.8090800@paradise.net.nz> Jeffrey Wise wrote: > I'm in my first week with PIL and doing well - it's a tremendous library! > I've gotten to the point in my image analysis that I need to find all the > groups of connected pixels in an image. These groups form arbitrary shapes > in the image. I want to preserve the shape information for each group, so I > can compare/analyze/categorize... it later. > > The image is composed of pixels of value 0 or 255 in "L" B&W format. I > assume such an algorithm will need to find a pixel of value 255 and then > check in every direction about it for a neighbor that is 255 too. The > algorithm would presumably recurse to find neighbors of the neighbor, etc. > I suspect the trick in this algorithm is the data structures needed to keep > track of the discovered adjacencies. I have loaded the image into the 2D > array-like accessor, so I have free access to each pixel. That's more or less floodfill, as John Cupitt said, and would look something like this: http://mail.python.org/pipermail/image-sig/2005-September/003559.html There's a version of it at the bottom of ImageDraw.py in 1.1.6. You'll presumably want to change the innermost bit from changing the colour to shifting the shape onto another image, or something. douglas