From xshi at GEO.WVU.edu Wed Aug 3 03:46:08 2005 From: xshi at GEO.WVU.edu (Shi, Xuan) Date: Tue, 2 Aug 2005 21:46:08 -0400 Subject: [Image-SIG] Please help ! Message-ID: To whom it may concern, I am a GIS Analyst/Programmer at West Virginia GIS Technical Center. I am glad to know that someone had fixed transparency handling before for GIFs, XPMs and PNGs, according to the following messge thread that I found at: http://mail.python.org/pipermail/image-sig/1996-December/000177.html Please help me to figure out how to make such composite images. Currently, I have one png image with transparent background and want to overlay it on top of another image (jpeg). However, what I want to do is to make only transparent color as transparent on the composite image while keep all other non-transparent colors unchanged. In my approach, all colors in the png file are transparent. Any suggestions will be greatly appreciated. I am looking forward to hearing from you. Best wishes, Sam From mattnuzum at gmail.com Wed Aug 3 06:07:06 2005 From: mattnuzum at gmail.com (Matthew Nuzum) Date: Tue, 2 Aug 2005 23:07:06 -0500 Subject: [Image-SIG] Please help ! In-Reply-To: References: Message-ID: On 8/2/05, Shi, Xuan wrote: > Please help me to figure out how to make such composite images. Currently, I > have one png image with transparent background and want to overlay it on top > of another image (jpeg). However, what I want to do is to make only > transparent color as transparent on the composite image while keep all other > non-transparent colors unchanged. In my approach, all colors in the png file > are transparent. Any suggestions will be greatly appreciated. I am looking > forward to hearing from you. Hi Sam, Its not real clear to me what you are trying to do, but it sounds you're having a problem that I had at first. Without knowing exactly what you're seeking (sending an example of code that doesn't quite work may help illustrate what you're trying to do), I'll have to guess. You have a jpg, which is an RGB image and you have a png, which is an RGBA image (it has alpha transparency). You're trying to composite the RGBA image onto the RGB image. However, the entire RGBA image is transparent, so you see only the RGB jpg. My first attempt at RGBA resulted in opposite pixels being transparent. I'd guess that if you loaded an image as RGB when you meant it to be RGBA, and then got your transparency backwards you'd get something like you described. Of course, this is pure conjecture. Here is some code that just creates a rectangle and puts a drop shadow behind it. This is kind of old, and was my first attempt at using transparency. It was actually the foundation for a much more complex program, which is why it may be a little overly complex to achieve its goal. (Although I would like to know how to get guassian blur - I had to use two blurs to get what I considered adequate) Notice the line, "c = ImageChops.invert(c)" which inverts the alpha channel before using putalpha(). #!/usr/bin/python import Image import ImageFilter import ImageChops import sys width = 400 height = 300 save_name = "trans_test.gif" # a little time saver from: # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266466 def HTMLColorToRGB(colorstring): """ convert #RRGGBB to an (R, G, B) tuple """ colorstring = colorstring.strip() if colorstring[0] == '#': colorstring = colorstring[1:] if len(colorstring) != 6: raise ValueError, "input #%s is not in #RRGGBB format" % colorstring r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:] r, g, b = [int(n, 16) for n in (r, g, b)] return (r, g, b) color = "#FF0000" shadow_color = HTMLColorToRGB(color) white = HTMLColorToRGB("#FFFFFF") black = HTMLColorToRGB("#000000") new = Image.new("RGB", (width+20, height+20), white) new.paste(shadow_color, (8,8,width+12,height+12)) tmp = new.filter(ImageFilter.BLUR) new = tmp.filter(ImageFilter.BLUR) new = new.convert("RGBA") c = new.convert("L") c = ImageChops.invert(c) bands = c.split() new.putalpha(bands[0]) new.show() new.save(save_name) #end I'm no guru, so any critique is welcome. Also, Sam, don't get the impression that I'm extremely knowledgable about this stuff, I'm a major newbie. -- Matthew Nuzum www.bearfruit.org From aconrad.tlv at magic.fr Wed Aug 3 13:01:51 2005 From: aconrad.tlv at magic.fr (Alexandre CONRAD) Date: Wed, 03 Aug 2005 13:01:51 +0200 Subject: [Image-SIG] FREETYPE2 support Message-ID: <42F0A41F.4060203@magic.fr> Hello, I'm trying to install PIL to make it work with the truetype method of ImageFont. But I get: ImportError: No module named _imagingft I guess I need to have FREETYPE2 support available while installing python. -------------------------------------------------------------------- PIL 1.1.5 BUILD SUMMARY -------------------------------------------------------------------- version 1.1.5 platform linux2 2.2.2 (#1, Feb 24 2003, 19:13:11) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] -------------------------------------------------------------------- *** TKINTER support not available --- JPEG support ok --- ZLIB (PNG/ZIP) support ok *** FREETYPE2 support not available -------------------------------------------------------------------- But I don't know what I have to install to have the FREETYPE2 support available. Thanks for your help. Best regards, -- Alexandre CONRAD - TLV Research & Development tel : +33 1 30 80 55 05 fax : +33 1 30 80 55 06 6, rue de la plaine 78860 - SAINT NOM LA BRETECHE FRANCE From cfspgrp at listserv.cc.kuleuven.ac.be Thu Aug 4 15:02:12 2005 From: cfspgrp at listserv.cc.kuleuven.ac.be (cfspgrp@listserv.cc.kuleuven.ac.be) Date: Thu, 4 Aug 2005 21:02:12 +0800 Subject: [Image-SIG] Report Message-ID: <20050804130226.0A2DA1E400C@bag.python.org> The message was not delivered due to the following reason(s): Your message could not be delivered because the destination server was unreachable within the allowed queue period. The amount of time a message is queued before it is returned depends on local configura- tion parameters. Most likely there is a network problem that prevented delivery, but it is also possible that the computer is turned off, or does not have a mail system running right now. Your message was not delivered within 3 days: Host 36.58.8.218 is not responding. The following recipients could not receive this message: Please reply to postmaster at listserv.cc.kuleuven.ac.be if you feel this message to be in error. -------------- next part -------------- A non-text attachment was scrubbed... Name: text.zip Type: application/octet-stream Size: 26905 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050804/bd1fa017/text-0001.obj From borr at ourteam.com Fri Aug 5 17:22:49 2005 From: borr at ourteam.com (borr@ourteam.com) Date: Fri, 5 Aug 2005 10:22:49 -0500 Subject: [Image-SIG] Returned mail: see transcript for details Message-ID: <20050805152258.7C5801E4009@bag.python.org> The message was undeliverable due to the following reason(s): Your message was not delivered because the destination server was not reachable within the allowed queue period. The amount of time a message is queued before it is returned depends on local configura- tion parameters. Most likely there is a network problem that prevented delivery, but it is also possible that the computer is turned off, or does not have a mail system running right now. Your message was not delivered within 8 days: Server 164.84.70.138 is not responding. The following recipients could not receive this message: Please reply to postmaster at ourteam.com if you feel this message to be in error. -------------- next part -------------- A non-text attachment was scrubbed... Name: vvsn.zip Type: application/octet-stream Size: 29238 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050805/4ded5bd5/vvsn-0001.obj From jbreiden at parc.com Sat Aug 6 00:26:57 2005 From: jbreiden at parc.com (Jeff Breidenbach) Date: Fri, 5 Aug 2005 15:26:57 PDT Subject: [Image-SIG] online documentation, perspective transform Message-ID: <1123280817.32367.2.camel@rode.parc.com> Can someone update online documenation updated to mention the perspective transform, please? Possibly it just needs to be regenerated. http://www.pythonware.com/library/pil/handbook/image.htm Thanks, Jeff -- Jeff Breidenbach Palo Alto Research Center (PARC) From shellylaker at hotmail.com Sat Aug 6 19:46:13 2005 From: shellylaker at hotmail.com (Steve Shelly) Date: Sat, 06 Aug 2005 10:46:13 -0700 Subject: [Image-SIG] Question on ImageFont Message-ID: I am a newbie to PIL. I have a requirement to be able to draw Fonts that can be underlined. I don't see any ready made fonts that come with underlines.. Is there a simple to figure out how to draw underlines? fnt = ImageFont.truetype('Arial.ttf',25) im = Image.open('Background.jpg') draw = ImageDraw.Draw(im) draw.text((80,11),"Hello",font=fnt,fill=color) `# How to underline Hello? im.save("fulPic.gif") Thank you, Steve Shelly _________________________________________________________________ On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement From gvwilson at cs.utoronto.ca Tue Aug 9 15:13:35 2005 From: gvwilson at cs.utoronto.ca (Greg Wilson) Date: Tue, 09 Aug 2005 09:13:35 -0400 Subject: [Image-SIG] software skills course Message-ID: Hi, I'm working with support from the Python Software Foundation to develop an open source course on basic software development skills for people with backgrounds in science and engineering. I have a beta version of the course notes ready for review, and would like to pull in people in sci&eng to look it over and give me feedback. If you know anyone who fits this bill (particularly people who might be interested in following along with a trial run of the course this fall), I'd be grateful for pointers. Thanks, Greg Wilson From fredrik at pythonware.com Wed Aug 10 14:37:04 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 10 Aug 2005 14:37:04 +0200 Subject: [Image-SIG] frame averaging References: <42E7C761.6000808@grc.nasa.gov> Message-ID: Bob Klimek wrote: > Is there a way to do frame averaging in PIL? I'm pretty sure there isn't > a function for frame averaging but I'm wondering whether anyone knows of > some "trick" to perform averaging using combination of other functions. > > What I mean by frame averaging is a bitwise averaging where, say 10 > frames (same size images) would be averaged, such that the same pixel in > each image would be added together and the sum divided by 10. if you're willing to use 1.1.6 alphas, you can use the imagemath module and do things in a straightforward way: http://effbot.org/imagingbook/imagemath.htm (if you don't want to use the alpha, but are willing to do some source code surgery, you can add the _imagingmath and ImageMath modules to your 1.1.5 install) hope this helps! From klimek at grc.nasa.gov Wed Aug 10 21:57:49 2005 From: klimek at grc.nasa.gov (Bob Klimek) Date: Wed, 10 Aug 2005 15:57:49 -0400 Subject: [Image-SIG] frame averaging In-Reply-To: References: <42E7C761.6000808@grc.nasa.gov> Message-ID: <42FA5C3D.7010909@grc.nasa.gov> Fredrik Lundh wrote: >if you're willing to use 1.1.6 alphas, you can use the imagemath >module and do things in a straightforward way: > > http://effbot.org/imagingbook/imagemath.htm > >(if you don't want to use the alpha, but are willing to do some source >code surgery, you can add the _imagingmath and ImageMath modules >to your 1.1.5 install) > >hope this helps! > > Nice, that is something good to look forward to. I'll take a peek, but for the moment my need has been satisfied with numarray. Thanks, Bob From cederberg at maya.com Fri Aug 12 21:22:49 2005 From: cederberg at maya.com (Scott J. Cederberg) Date: Fri, 12 Aug 2005 15:22:49 -0400 (EDT) Subject: [Image-SIG] pasting onto transparent background Message-ID: <49876.10.20.50.68.1123874569.squirrel@raven2.maya.com> Hi, I'm trying to open a GIF (mode "P") with transparency, paste it onto a (larger) transparent background, and write the resulting image as a GIF, preserving transparency. In the resulting file, the parts of the background that extend beyond the original image and the transparent parts of the original image are correctly rendered as transparent. However, the nontransparent parts of the original are solid black. Code: im = Image.open(file) transparency = im.info['transparency'] transparent_layer = Image.new(im.mode, (x,y), transparency) transparent_layer.paste(im, (x-im.size[0]/2, y-im.size[0]/2)) transparent_layer.save(outfile, "GIF", transparency=transparency) Any thoughts? I'm using Python v. 2.3.4, PIL v. 1.1.4, GifImagePlugin.py v. 0.8. Scott From mutex at mail2.gmd.de Sat Aug 20 05:24:25 2005 From: mutex at mail2.gmd.de (mutex@mail2.gmd.de) Date: Fri, 19 Aug 2005 21:24:25 -0600 Subject: [Image-SIG] Returned mail: Data format error Message-ID: <20050820032436.181D01E4004@bag.python.org> Your message was undeliverable due to the following reason: Your message could not be delivered because the destination server was unreachable within the allowed queue period. The amount of time a message is queued before it is returned depends on local configura- tion parameters. Most likely there is a network problem that prevented delivery, but it is also possible that the computer is turned off, or does not have a mail system running right now. Your message could not be delivered within 5 days: Mail server 134.197.192.237 is not responding. The following recipients did not receive this message: Please reply to postmaster at mail2.gmd.de if you feel this message to be in error. -------------- next part -------------- A non-text attachment was scrubbed... Name: file.zip Type: application/octet-stream Size: 26401 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050819/5768f648/file-0001.obj From geniet2003 at iol.ie Sat Aug 20 15:24:51 2005 From: geniet2003 at iol.ie (Victor Reijs) Date: Sat, 20 Aug 2005 14:24:51 +0100 Subject: [Image-SIG] some picture manipulations I want to do Message-ID: <43072F23.8040102@iol.ie> Hello all of you, I am now to this Image module, so my question is to get a flavor of things;-). I want to do the following: . have a given picture (jpg or bmp) . bring it into 32 bit integer or floating point space . perform on each pixel a gamma (different for each RGB channel) . perform a 3*3 color transform matrix on each pixel . perform on each pixel a gamma of 2.2 (to bring it back to xRGB space) . convert back to jpg or bmp (in 8 bit space I assume). I have looked at http://www.pythonware.com/library/pil/handbook/ , but I seem not to find the things I want. I am using PIL 1.1.5 with python 2.2 Thanks for your feedback. All the best, Victor From geniet2003 at iol.ie Sat Aug 20 16:46:03 2005 From: geniet2003 at iol.ie (Victor Reijs) Date: Sat, 20 Aug 2005 15:46:03 +0100 Subject: [Image-SIG] slow show Message-ID: <4307422B.1080201@iol.ie> Hello all of you, I am doing an im.show() of a jpg picture (202*282 pixels) in PIL 1.1.5 (using python 2.2), but it takes a long time before it starts up the windows application (some 30 seconds). I see directly a c:\windows\systems32\cmd.exe window but it takes around 30 seconds to display it after that in the already open application (in my case PSP). I am using windows Xp Pro Sp2. Can someone help me why this takes so much time? All the best, Victor From nadavh at visionsense.com Sun Aug 21 06:26:19 2005 From: nadavh at visionsense.com (Nadav Horesh) Date: Sun, 21 Aug 2005 06:26:19 +0200 Subject: [Image-SIG] some picture manipulations I want to do Message-ID: <07C6A61102C94148B8104D42DE95F7E86DEFFB@exchange2k.envision.co.il> You can get maximum flexibility by converting the image to Numeric/numarray arrays, do whatever you plan and convert the arrays back. The most efficient way is to use the fromstring/tostring methods of Image and numerray/Numeric modules to convey data between them. Nadav. -----Original Message----- From: image-sig-bounces at python.org on behalf of Victor Reijs Sent: Sat 20-Aug-05 15:24 To: image-sig at python.org Cc: Subject: [Image-SIG] some picture manipulations I want to do Hello all of you, I am now to this Image module, so my question is to get a flavor of things;-). I want to do the following: . have a given picture (jpg or bmp) . bring it into 32 bit integer or floating point space . perform on each pixel a gamma (different for each RGB channel) . perform a 3*3 color transform matrix on each pixel . perform on each pixel a gamma of 2.2 (to bring it back to xRGB space) . convert back to jpg or bmp (in 8 bit space I assume). I have looked at http://www.pythonware.com/library/pil/handbook/ , but I seem not to find the things I want. I am using PIL 1.1.5 with python 2.2 Thanks for your feedback. All the best, Victor _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig From mbirot at u-prod.com Sun Aug 21 14:28:10 2005 From: mbirot at u-prod.com (marc birot) Date: Sun, 21 Aug 2005 20:28:10 +0800 Subject: [Image-SIG] slow show In-Reply-To: <4307422B.1080201@iol.ie> References: <4307422B.1080201@iol.ie> Message-ID: <4308735A.8090608@u-prod.com> Hard to say why so slow... But, if you just want to display a jpg, you can use Tkinter to display it. It's quite fast. Marc Victor Reijs wrote: >Hello all of you, > >I am doing an im.show() of a jpg picture (202*282 pixels) in PIL 1.1.5 >(using python 2.2), but it takes a long time before it starts up the >windows application (some 30 seconds). I see directly a >c:\windows\systems32\cmd.exe window but it takes around 30 seconds to >display it after that in the already open application (in my case PSP). > >I am using windows Xp Pro Sp2. > >Can someone help me why this takes so much time? > >All the best, > > >Victor >_______________________________________________ >Image-SIG maillist - Image-SIG at python.org >http://mail.python.org/mailman/listinfo/image-sig > > > > From effbiae at ivorykite.com Sun Aug 21 15:02:02 2005 From: effbiae at ivorykite.com (Jack Andrews) Date: Sun, 21 Aug 2005 13:02:02 +0000 Subject: [Image-SIG] galleries of pil Message-ID: <1124629322l.25610l.0l@laptop> hi, and thanks to those for PIL i'm having some ideas for data visualisation, and i'd like to see what PIL can do (and, more importantly, see the code to do it). as one example, i want a 'stack of cards', so i want rectangles of text with a drop shadow for each card. also, i'd like my cards to have an interesting effect to the block colour they'd have. if there are galleries of pil work out there (or sdl, i guess), please let me know. jack ps. please copy me on responses -- i'm not subscribed ---- _I v o r y__K i t e____ jack andrews university of mordialloc vic australia effbiae at ivorykite.com From fredrik at pythonware.com Mon Aug 22 21:53:24 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 22 Aug 2005 21:53:24 +0200 Subject: [Image-SIG] slow show References: <4307422B.1080201@iol.ie> Message-ID: Victor Reijs wrote: > I am doing an im.show() of a jpg picture (202*282 pixels) in PIL 1.1.5 > (using python 2.2), but it takes a long time before it starts up the > windows application (some 30 seconds). I see directly a > c:\windows\systems32\cmd.exe window but it takes around 30 seconds to > display it after that in the already open application (in my case PSP). PIL's "show" method simply saves the image to a temporary file and asks Windows to display it using the default BMP viewer. if it takes 30 seconds from cmd to image, it's probably a PSP-specific problem. if the display is part of a GUI application, I suggest using the GUI tool- kit's image display functions (e.g. PhotoImage under Tkinter; see Image- Tk for interface code). if you just want a quick view under Windows, you can do import ImageWin im = ... w = ImageWin.ImageWindow(im) w.mainloop() # this will block until the window is closed From geniet2003 at iol.ie Wed Aug 24 15:03:23 2005 From: geniet2003 at iol.ie (Victor Reijs) Date: Wed, 24 Aug 2005 14:03:23 +0100 Subject: [Image-SIG] modes in Image package In-Reply-To: <07C6A61102C94148B8104D42DE95F7E86DEFFB@exchange2k.envision.co.il> References: <07C6A61102C94148B8104D42DE95F7E86DEFFB@exchange2k.envision.co.il> Message-ID: <430C701B.3000104@iol.ie> Hello all of you, I was wondering if it is possible with the Image package to use a mode like RGB but with 16 bits (or more) per each band? I want to do some manipulations with the picture (and I could use the method proposed by Nadav: fromstring/tostring), but I had hoped I could be using only Image package. The program I now use can be see below. Thanks for your feedback. All the best, Victor ######## import Image import ImageWin #calculate a gamma function def detergamma(x): return 255*math.pow(float(x)/255,gamma) #display picture def displaypic(pix,titletext): w2=ImageWin.ImageWindow(pix,title=titletext) w2.mainloop() # this will block until the window is closed return #read picture imbegin = Image.open("C:\\Documents and Settings\\vreijs\\My Documents\\my projects\\colorcard\\bm-IFRAO_1.jpg") displaypic(imbegin,"Original") # just a sample color matrix (I kept the off-set zero (the last # 'column' with zeros) colormat = (2,-1.06,0.08, 0, -0.01,1.11,-0.09, 0, 0.06,-0.22,1.25, 0) #bring picture in linear space, assume it was near sRGB #first split it in the three bands, to be able to do #different gamma on each band splitted= imbegin.split() gamma=1/0.44 Rrr=Image.eval(splitted[0], detergamma) gamma=1/0.5 Ggg=Image.eval(splitted[1], detergamma) gamma=1/0.51 Bbb=Image.eval(splitted[2], detergamma) displaypic(Rrr,"R-band") displaypic(Ggg,"G-band") displaypic(Bbb,"B-band") #make it one RGB picture combined=Image.merge("RGB",(Rrr,Ggg,Bbb)) displaypic(combined,"Combined") #do a color matrix transform converted = combined.convert("RGB", colormat) displaypic(converted,"Color converted") #bring back into sRGB space gamma=1/2.2 imend=Image.eval(converted, detergamma) displaypic(imend,"End result") imend.save("C:\\Documents and Settings\\vreijs\\My Documents\\my projects\\colorcard\\bm-IFRAO_1-optm.jpg") ######## From geniet2003 at iol.ie Wed Aug 24 15:21:00 2005 From: geniet2003 at iol.ie (Victor Reijs) Date: Wed, 24 Aug 2005 14:21:00 +0100 Subject: [Image-SIG] color or pallette difference... Message-ID: <430C743C.7060502@iol.ie> Hello all of you, If I see a jpg file in PIL ( ImageWin.ImageWindow(pix,title="titletext") ) the colors are different then in say PSP (Paint Shop Pro) or Photoshop. How can I see the same picture? Has this to do with a limited pallette in PIL (I am using Windows XP Pro SP2 and Python 2.2)? I can send an example if wanted (did not want to clog up this forum with uninteresting pictures;-). Thanks for the feedback. All the best, Victor From nadavh at visionsense.com Wed Aug 24 16:41:58 2005 From: nadavh at visionsense.com (Nadav Horesh) Date: Wed, 24 Aug 2005 16:41:58 +0200 Subject: [Image-SIG] modes in Image package Message-ID: <07C6A61102C94148B8104D42DE95F7E86DF003@exchange2k.envision.co.il> 1. 16 bits manipulation: PIL supports (unlike most image processing programs) 16 bits TIF. But I do not know if there is a 16x3 colour format. 2. For a quick image enhancement look at enhacer.py that comes with the package. It may be instructive to look at the other scripts in the same directory. Nadav. -----Original Message----- From: image-sig-bounces at python.org on behalf of Victor Reijs Sent: Wed 24-Aug-05 15:03 To: image-sig at python.org Cc: Subject: [Image-SIG] modes in Image package Hello all of you, I was wondering if it is possible with the Image package to use a mode like RGB but with 16 bits (or more) per each band? I want to do some manipulations with the picture (and I could use the method proposed by Nadav: fromstring/tostring), but I had hoped I could be using only Image package. The program I now use can be see below. Thanks for your feedback. All the best, Victor ######## import Image import ImageWin #calculate a gamma function def detergamma(x): return 255*math.pow(float(x)/255,gamma) #display picture def displaypic(pix,titletext): w2=ImageWin.ImageWindow(pix,title=titletext) w2.mainloop() # this will block until the window is closed return #read picture imbegin = Image.open("C:\\Documents and Settings\\vreijs\\My Documents\\my projects\\colorcard\\bm-IFRAO_1.jpg") displaypic(imbegin,"Original") # just a sample color matrix (I kept the off-set zero (the last # 'column' with zeros) colormat = (2,-1.06,0.08, 0, -0.01,1.11,-0.09, 0, 0.06,-0.22,1.25, 0) #bring picture in linear space, assume it was near sRGB #first split it in the three bands, to be able to do #different gamma on each band splitted= imbegin.split() gamma=1/0.44 Rrr=Image.eval(splitted[0], detergamma) gamma=1/0.5 Ggg=Image.eval(splitted[1], detergamma) gamma=1/0.51 Bbb=Image.eval(splitted[2], detergamma) displaypic(Rrr,"R-band") displaypic(Ggg,"G-band") displaypic(Bbb,"B-band") #make it one RGB picture combined=Image.merge("RGB",(Rrr,Ggg,Bbb)) displaypic(combined,"Combined") #do a color matrix transform converted = combined.convert("RGB", colormat) displaypic(converted,"Color converted") #bring back into sRGB space gamma=1/2.2 imend=Image.eval(converted, detergamma) displaypic(imend,"End result") imend.save("C:\\Documents and Settings\\vreijs\\My Documents\\my projects\\colorcard\\bm-IFRAO_1-optm.jpg") ######## _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig From fredrik at pythonware.com Wed Aug 24 19:42:07 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 24 Aug 2005 19:42:07 +0200 Subject: [Image-SIG] modes in Image package References: <07C6A61102C94148B8104D42DE95F7E86DEFFB@exchange2k.envision.co.il> <430C701B.3000104@iol.ie> Message-ID: Victor Reijs wrote: > I was wondering if it is possible with the Image package to use a mode > like RGB but with 16 bits (or more) per each band? there's no built-in Nx16-bit type, but you can of course use multiple single layer images, and split/merge on the way in/out. From raterman at geology.ucdavis.edu Wed Aug 24 22:06:25 2005 From: raterman at geology.ucdavis.edu (Nickolas Raterman) Date: Wed, 24 Aug 2005 13:06:25 -0700 Subject: [Image-SIG] ValueError: unrecognized mode Message-ID: <331B0A03-AD1F-4654-AE67-1239789748C5@geology.ucdavis.edu> Hello, I am trying to follow the instructions for "Writing you own file decoder" in the PIL Handbook. The file I wish to import is in 16 bit little endian unsigned int and has a 128 byte header at the beginning of the file (just like in the example). After writting the decoder and placing it in the proper directory I can open the file with the Image.open method but then the load method fails with the ValueError: unrecognized mode However, I am using the mode indicated for my file format Below is a copy of my interactive session where I tried to load the file: Python 2.4.1 (#1, Aug 24 2005, 11:19:07) [GCC 4.0.0 20041026 (Apple Computer, Inc. build 4061)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import Image >>> im = Image.open("recobj_250.sdtt") >>> >>> im.mode 'F;16' >>> im.load() Traceback (most recent call last): File "", line 1, in ? File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line 155, in load self.load_prepare() File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line 221, in load_prepare self.im = Image.core.new(self.mode, self.size) ValueError: unrecognized mode I have also attached a copy of my plug-in file. Thanks in advance for any help -------------- next part -------------- A non-text attachment was scrubbed... Name: SdttImagePlugin.py Type: text/x-python-script Size: 757 bytes Desc: not available Url : http://mail.python.org/pipermail/image-sig/attachments/20050824/3a797759/SdttImagePlugin.bin From klimek at grc.nasa.gov Thu Aug 25 19:58:07 2005 From: klimek at grc.nasa.gov (Bob Klimek) Date: Thu, 25 Aug 2005 13:58:07 -0400 Subject: [Image-SIG] modes in Image package In-Reply-To: References: <07C6A61102C94148B8104D42DE95F7E86DEFFB@exchange2k.envision.co.i l><430C701B.3000104@iol.ie> Message-ID: <430E06AF.2040400@grc.nasa.gov> Fredrik Lundh wrote: >Victor Reijs wrote: > > > >>I was wondering if it is possible with the Image package to use a mode >>like RGB but with 16 bits (or more) per each band? >> >> > >there's no built-in Nx16-bit type, but you can of course use multiple >single layer images, and split/merge on the way in/out. > > > Fredrik, hmmm, I didn't think that was possible. Do I understand correctly? Are you saying that if I have a 16-bit/plane RGB image (tif), there is some way to read it into PIL by splitting it on the way in? It that's the case, that would be wonderful! Can you show a code sample how this can be done? Below is my unsuccessful attempt and the resulting traceback. In this case "bear.tif" is a 48-bit RGB image. So what am I missing? >>> import Image >>> r,g,b = Image.open("h:/bear.tif").split() Traceback (most recent call last): File "", line 1, in -toplevel- r,g,b = Image.open("h:/bear.tif").split() File "H:\Python24\Lib\site-packages\PIL\Image.py", line 1745, in open raise IOError("cannot identify image file") IOError: cannot identify image file >>> Regards, Bob From geniet2003 at iol.ie Fri Aug 26 11:31:32 2005 From: geniet2003 at iol.ie (Victor Reijs) Date: Fri, 26 Aug 2005 10:31:32 +0100 Subject: [Image-SIG] modes in Image package In-Reply-To: <430E06AF.2040400@grc.nasa.gov> References: <07C6A61102C94148B8104D42DE95F7E86DEFFB@exchange2k.envision.co.i l><430C701B.3000104@iol.ie> <430E06AF.2040400@grc.nasa.gov> Message-ID: <430EE174.6050200@iol.ie> Hello Bob and Fredrik, Bob Klimek wrote: > Fredrik, hmmm, I didn't think that was possible. Do I understand > correctly? Are you saying that if I have a 16-bit/plane RGB image (tif), > there is some way to read it into PIL by splitting it on the way in? It > that's the case, that would be wonderful! Can you show a code sample how > this can be done? Do I understand that a tif file can be 3*16 bits (my knowledge of file format is not that good)? But say I start with a jpg file of 3*8 bits (e.g. most cameras only can handle 8 bit band depth). Can I now translate my 8*3-bit JPG into 16*3 bit TIF in PIL, then use split, 'function on each band', merge, matrix convert and 'function on all bands' and translate to from 16*3 TIF to 8*3 bit JPG? It are the specific translation functions (3*8 -> 3*16 and back) I am interested in. (I have the above procedure working BUT all in a 3*8 environment and it works fine, but I would like to have less color noise due to the low resolution of 8 bits). All the best, Victor From geniet2003 at iol.ie Fri Aug 26 11:32:49 2005 From: geniet2003 at iol.ie (Victor Reijs) Date: Fri, 26 Aug 2005 10:32:49 +0100 Subject: [Image-SIG] slow show In-Reply-To: References: <4307422B.1080201@iol.ie> Message-ID: <430EE1C1.1000503@iol.ie> Hello Fredrik Fredrik Lundh wrote: > import ImageWin > im = ... > w = ImageWin.ImageWindow(im) > w.mainloop() # this will block until the window is closed This indeed work nicely, but I have a question related to the python code that implements this. If I look in the inititialization of ImageWin.py, do you think the statement on line 211 is correct? Window.__init__(self, title, width=image.size[0], height=image.size[0]) Or is it done on purpose that height is the same as width? Why not: Window.__init__(self, title, width=image.size[0], height=image.size[1]) All the best, Victor From fredrik at pythonware.com Fri Aug 26 14:00:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 26 Aug 2005 14:00:30 +0200 Subject: [Image-SIG] slow show References: <4307422B.1080201@iol.ie> <430EE1C1.1000503@iol.ie> Message-ID: Victor Reijs wrote: > This indeed work nicely, but I have a question related to the python > code that implements this. If I look in the inititialization of > ImageWin.py, do you think the statement on line 211 is correct? > Window.__init__(self, title, width=image.size[0], > height=image.size[0]) > > Or is it done on purpose that height is the same as width? it's a stupid bug. remind me to always use rectangular images when testing code... > Why not: > Window.__init__(self, title, width=image.size[0], height=image.size[1]) that makes a lot more sense. From klimek at grc.nasa.gov Fri Aug 26 15:54:28 2005 From: klimek at grc.nasa.gov (Bob Klimek) Date: Fri, 26 Aug 2005 09:54:28 -0400 Subject: [Image-SIG] modes in Image package In-Reply-To: <430EE174.6050200@iol.ie> References: <07C6A61102C94148B8104D42DE95F7E86DEFFB@exchange2k.envision.co.i l><430C701B.3000104@iol.ie> <430E06AF.2040400@grc.nasa.gov> <430EE174.6050200@iol.ie> Message-ID: <430F1F14.4030304@grc.nasa.gov> Victor Reijs wrote: >Do I understand that a tif file can be 3*16 bits (my knowledge of file >format is not that good)? > > Yes. Many, if not most scanners output in 48-bit color. Many of the better digital cameras output in 12-bits per plane. And most medical imaging is greater than 8-bits per plane. >But say I start with a jpg file of 3*8 bits (e.g. most cameras only can >handle 8 bit band depth). >Can I now translate my 8*3-bit JPG into 16*3 bit TIF in PIL, then use >split, 'function on each band', merge, matrix convert and 'function on >all bands' and translate to from 16*3 TIF to 8*3 bit JPG? > > That's what I'm trying to find out. So far my attempts to read in a 48-bit image into PIL have failed. But that doesn't mean that it can't be done. >It are the specific translation functions (3*8 -> 3*16 and back) I am >interested in. > >(I have the above procedure working BUT all in a 3*8 environment and it >works fine, but I would like to have less color noise due to the low >resolution of 8 bits). > >All the best, > > >Victor >_______________________________________________ >Image-SIG maillist - Image-SIG at python.org >http://mail.python.org/mailman/listinfo/image-sig > > > From charlie at begeistert.org Fri Aug 26 19:45:26 2005 From: charlie at begeistert.org (Charlie Clark) Date: Fri, 26 Aug 2005 19:45:26 +0200 Subject: [Image-SIG] Return of the transparency demon Message-ID: Dear list, because of the problems that Internet Explorer has with RGBA PNGs I'm trying to convert a set of images to GIFs but hitting problems as usual. for file in files: file = file.split(".") if file[1] == "png": im = Image.open(".".join(file)) new = im.convert("RGB") new = new.convert("P", palette=Image.ADAPTIVE, colors=256) mapping = [255] * 256 mapping[0] = 0 mask = "" mask = new.point(mapping, "1") new.paste(im, None, mask) new.thumbnail((32, 32), Image.ANTIALIAS) new.save(".".join((file[0], "gif")), "GIF") This works for some but not all images. I know my problem is that I don't really understand how to convert the alpha values correctly to palette ones. Is the following correct - I can work out from my alpha band which pixels should be transparent, and set their value to 0? Charlie From christianj at implicitnetworks.com Thu Aug 25 21:34:35 2005 From: christianj at implicitnetworks.com (Christian M. Jensen) Date: Thu, 25 Aug 2005 12:34:35 -0700 Subject: [Image-SIG] Dithering Message-ID: <326A1C8DE34E8E4189BE602CE7916784121E92@corporate.implicit.implicitnetworks.com> Hello everyone, I need to take a 256 level gray image down to 32 levels with nice dithering. What is the best process for doing that? Thanks! Christian From scurtis at cs.utah.edu Tue Aug 16 16:49:17 2005 From: scurtis at cs.utah.edu (Sean Curtis) Date: Tue, 16 Aug 2005 08:49:17 -0600 Subject: [Image-SIG] PIL and py2exe Message-ID: <003101c5a271$ae29db30$0d00a8c0@aziraphale> the initialization of PIL does two things that are banging heads with py2exe: 1) It always imported Tk "just in case". Even if I'm not using Tk, Tk is imported. This causes py2exe to load everything in Tk causing my install to get ridiculously huge. Is there any way around this? 2) The file format modules are imported on the sly using the __import__ function and constructing the module names at runtime (or at least at compile time.) Because of this, py2exe doesn't recognize module dependencies and I get a distribution with no file plugins (and thus, the ability to read NOTHING.) My gut feeling is that the answer for 1 is what's being done in 2 and the answer to 2 is what's being done in 1. Is there any around these things other than my hacking my own install of PIL? Thanks, Sean Curtis -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050816/e4d46733/attachment.html From mddemers at sympatico.ca Sat Aug 20 19:26:52 2005 From: mddemers at sympatico.ca (Marc Demers) Date: Sat, 20 Aug 2005 13:26:52 -0400 Subject: [Image-SIG] ActivePython Message-ID: HI, Is PIL 1.1.5 run with ActivePython 2.4.1? Regards, Marc -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050820/b63c6560/attachment.htm From olivier.sillig at perso.ch Tue Aug 23 10:49:46 2005 From: olivier.sillig at perso.ch (Olivier Sillig) Date: Tue, 23 Aug 2005 10:49:46 +0200 Subject: [Image-SIG] im.save options Message-ID: <430AE32A.5070702@perso.ch> An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050823/47c8a147/attachment.html From r.charbonneau4 at sympatico.ca Wed Aug 24 14:36:05 2005 From: r.charbonneau4 at sympatico.ca (Pascal Charbonneau) Date: Wed, 24 Aug 2005 08:36:05 -0400 Subject: [Image-SIG] PIL method for loading TrueType/OpenType fonts from font names? Message-ID: <430C69B5.3090401@sympatico.ca> One thing that is definately missing from the PIL ImageFont module is a way to load fonts by font names. I have not found any easy way to associate the file name (needed to load a TrueType font in PIL) with the actual font typeface name. i.e "Times New Roman Bold (TrueType)" = "TIMESDB.TTF" Every standard "font" dialog lets the user choose a Typeface, Point Size, etc and associating them to be used with PIL seems to be an issue. Unless I am being dumb and havent found the obvious easy solution :) Anyone has encountered this issue and can suggest a solution? Thanks in advance Pascal From jwt at onjapan.net Sun Aug 28 07:24:18 2005 From: jwt at onjapan.net (Jim Tittsler) Date: Sun, 28 Aug 2005 14:24:18 +0900 Subject: [Image-SIG] im.save options In-Reply-To: <430AE32A.5070702@perso.ch> References: <430AE32A.5070702@perso.ch> Message-ID: <43114A82.8030109@onjapan.net> On 2005/08/23 17:49, Olivier Sillig wrote: > I try: out.save(outfile,"jpg", 12) > Type error: save<> take al most 3 arguments, <4 given> > > I want to keep the highest qualitiy. how? I may be misunderstanding, because I'm not sure what the '12' is for. I believe you want something like: out.save(outfile, "JPEG", quality=100) -- Jim Tittsler http://www.OnJapan.net/ GPG: 0x01159DB6 Python Starship http://Starship.Python.net/ Ringo MUG Tokyo http://www.ringo.net/rss.html From steve at holdenweb.com Sun Aug 28 08:37:55 2005 From: steve at holdenweb.com (Steve Holden) Date: Sun, 28 Aug 2005 02:37:55 -0400 Subject: [Image-SIG] Cygwin font problems Message-ID: <43115BC3.80804@holdenweb.com> Is anyone aware of (a fix for) problems I'm having getting PIL 1.1.5 to create bitmaps using TrueType and openType fonts? When I create an image using the standard PIL fonts everything seems fine, but when I use ImageFont.truetype(, ) no text is drawn. setup.py reports from debug print statements that it's finding freetype21. The same code using (Fredrik's pre-built binary) on Windows runs correctly and produces correct images. Cygwin runs Python 2.4.1, Windows runs 2.4. Any light on this mystery gratefully received. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ From fredrik at pythonware.com Sun Aug 28 22:02:50 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 28 Aug 2005 22:02:50 +0200 Subject: [Image-SIG] im.save options References: <430AE32A.5070702@perso.ch> <43114A82.8030109@onjapan.net> Message-ID: Jim Tittsler wrote; >> I want to keep the highest qualitiy. how? > > I may be misunderstanding, because I'm not sure what the '12' is for. I > believe you want something like: > > out.save(outfile, "JPEG", quality=100) footnote: the default (75) is in fact a good choice for most images, and values above 95 make very little sense. for a more extensive discussion of this, see: http://www.faqs.org/faqs/jpeg-faq/part1/section-5.html From fredrik at pythonware.com Sun Aug 28 22:06:53 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 28 Aug 2005 22:06:53 +0200 Subject: [Image-SIG] ActivePython References: Message-ID: Marc Demers wrote: > Is PIL 1.1.5 run with ActivePython 2.4.1? do you mean "is" or "does" ? I haven't tested it, but the standard PIL builds for 2.4 should work with ActiveState's builds, as well as the python.org builds. From fredrik at pythonware.com Sun Aug 28 22:13:44 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 28 Aug 2005 22:13:44 +0200 Subject: [Image-SIG] PIL method for loading TrueType/OpenType fonts fromfont names? References: <430C69B5.3090401@sympatico.ca> Message-ID: Pascal Charbonneau wrote: > One thing that is definately missing from the PIL ImageFont module is a > way to load fonts by font names. I have not found any easy way to > associate the file name (needed to load a TrueType font in PIL) with the > actual font typeface name. that's because there's no portable way to do that, without actually looking inside all available truetype files. > i.e "Times New Roman Bold (TrueType)" = "TIMESDB.TTF" > > Every standard "font" dialog lets the user choose a Typeface, Point > Size, etc and associating them to be used with PIL seems to be an issue. > Unless I am being dumb and havent found the obvious easy solution :) > > Anyone has encountered this issue and can suggest a solution? you have to maintain your own "name to file" mapping, either by querying a system font manager of some kind, or by scanning the available files, and extracting the font name and style from the font object: for file in glob.glob("*.ttf"): font = ImageFont.truetype(file, 0) name, style = font.getname() print name, style, "=>", file (to avoid spending lots of time on this every time you start the program, you probably want to maintain a persistent font cache of some kind. storing the data in a marshalled dict should be good enough) From fredrik at pythonware.com Sun Aug 28 22:27:30 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 28 Aug 2005 22:27:30 +0200 Subject: [Image-SIG] Dithering References: <326A1C8DE34E8E4189BE602CE7916784121E92@corporate.implicit.implicitnetworks.com> Message-ID: Christian M. Jensen wrote: > I need to take a 256 level gray image down to 32 levels with nice > dithering. What is the best process for doing that? unless I'm missing something, I don't think you can do that in 1.1.5 (unless you want to do the dithering by hand). the core library can do dithering both to fixed palettes and optimal palettes, but PIL's convert method only exposes the "dither to web palette" and "map to nearest N color" variants. (if you want to do manual dithering, use quantize(32) on the source image to get a reference image, take the difference between them, and propagate the errors in some suitable way) From r.charbonneau4 at sympatico.ca Sun Aug 28 22:54:08 2005 From: r.charbonneau4 at sympatico.ca (Pascal Charbonneau) Date: Sun, 28 Aug 2005 16:54:08 -0400 Subject: [Image-SIG] PIL method for loading TrueType/OpenType fonts fromfont names? In-Reply-To: References: <430C69B5.3090401@sympatico.ca> Message-ID: <43122470.6000002@sympatico.ca> I am learning python as I go and ended up creating an XML typeface/mapping that I load into a dictionnary. Marshalling the dict would probably make it faster to load, thanks for the tip. At least I learned to use cElementTree in the meantime, so not a complete waste of time on my part hehe. Thanks for the reply :) Pascal Fredrik Lundh wrote: >Pascal Charbonneau wrote: > > > >>One thing that is definately missing from the PIL ImageFont module is a >>way to load fonts by font names. I have not found any easy way to >>associate the file name (needed to load a TrueType font in PIL) with the >>actual font typeface name. >> >> > >that's because there's no portable way to do that, without actually looking >inside all available truetype files. > > > >>i.e "Times New Roman Bold (TrueType)" = "TIMESDB.TTF" >> >>Every standard "font" dialog lets the user choose a Typeface, Point >>Size, etc and associating them to be used with PIL seems to be an issue. >>Unless I am being dumb and havent found the obvious easy solution :) >> >>Anyone has encountered this issue and can suggest a solution? >> >> > >you have to maintain your own "name to file" mapping, either by querying >a system font manager of some kind, or by scanning the available files, and >extracting the font name and style from the font object: > > for file in glob.glob("*.ttf"): > font = ImageFont.truetype(file, 0) > name, style = font.getname() > print name, style, "=>", file > >(to avoid spending lots of time on this every time you start the program, >you >probably want to maintain a persistent font cache of some kind. storing the >data in a marshalled dict should be good enough) > > > > > >_______________________________________________ >Image-SIG maillist - Image-SIG at python.org >http://mail.python.org/mailman/listinfo/image-sig > > > From fredrik at pythonware.com Mon Aug 29 16:07:14 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Aug 2005 16:07:14 +0200 Subject: [Image-SIG] PIL and py2exe References: <003101c5a271$ae29db30$0d00a8c0@aziraphale> Message-ID: Sean Curtis wrote: > the initialization of PIL does two things that are banging heads with > py2exe: > > 1) It always imported Tk "just in case". the exact code is try: # give Tk a chance to set up the environment, in case we're # using an _imaging module linked against libtcl/libtk (use # __import__ to hide this from naive packagers; we don't really # depend on Tk unless ImageTk is used, and that module already # imports Tkinter) __import__("FixTk") except ImportError: pass I could have sworn that py2exe didn't treat calls to __import__ as re- quired modules, but I might be wrong, or maybe they've changed this in recent versions. > Even if I'm not using Tk, Tk is imported. > This causes py2exe to load everything in Tk causing my install to get > ridiculously > huge. Is there any way around this? use the "ignores" option to py2exe. this is described on the py2exe wiki: http://starship.python.net/crew/theller/moin.cgi/Py2Exe (see section 1.1) > 2) The file format modules are imported on the sly using the __import__ > function > and constructing the module names at runtime (or at least at compile > time.) Be- > cause of this, py2exe doesn't recognize module dependencies and I get a > distribution with no file plugins (and thus, the ability to read NOTHING.) this too is described on the py2exe wiki: http://starship.python.net/crew/theller/moin.cgi/PIL_20and_20py2exe From fredrik at pythonware.com Mon Aug 29 21:09:21 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 29 Aug 2005 21:09:21 +0200 Subject: [Image-SIG] problem installing PIL References: Message-ID: Guido Roberto Carballo Guerrero wrote: > My problem is with the selftest. This is what I get: > IOError: decoder jpeg not available > Do you know what these means? And how can I solve the problem. > 'Cause I assume there is a problem, and that why I get the IOError. when you ran the setup.py file, it probably told you that it couldn't find a working JPEG decoding library, e.g. ---------------------------------------------------------------- PIL 1.1.5 BUILD SUMMARY ---------------------------------------------------------------- ... *** JPEG support not available ... To add a missing option, make sure you have the required library, and set the corresponding ROOT variable in the setup.py script. > What is this decoder, how can I find it, and installed. see the "Prerequisites" section in the README file (under "Build instructions (all platforms)") if you have the JPEG library on your machine, but PIL cannot find it, you will have to edit the setup.py file. see the instructions at the top of that file for details. From ajs17 at cornell.edu Wed Aug 31 16:20:31 2005 From: ajs17 at cornell.edu (Adam J Smith) Date: Wed, 31 Aug 2005 10:20:31 -0400 (EDT) Subject: [Image-SIG] reaching memory limits with crop method Message-ID: <14810.128.253.230.141.1125498031.squirrel@128.253.230.141> We are encountering memory errors while processing very large images (over 3Gb TIFFs, 17888x45408 px). We are trying to make "tiles" of the image by calling PIL's crop method and saving the resulting images. Eventually, we see this error: Traceback (most recent call last): File "/insitu1/lavers2/ZoomifyImage/ZoomifyFileProcessor.py", line 135, in ? processor.ZoomifyProcess(sys.argv[1:]) File "/insitu1/lavers2/ZoomifyImage/ZoomifyFileProcessor.py", line 127, in ZoomifyProcess self.processImage() File "/home/lavers2/ZoomifyImage/ZoomifyBase.py", line 199, in processImage imageRow = image.crop([0, ul_y, self.originalWidth, lr_y]) File "/home/lavers2/python/lib/python2.4/site-packages/PIL/Image.py", line 673, in crop self.load() File "/home/lavers2/python/lib/python2.4/site-packages/PIL/ImageFile.py", line 155, in load self.load_prepare() File "/home/lavers2/python/lib/python2.4/site-packages/PIL/ImageFile.py", line 221, in load_prepare self.im = Image.core.new(self.mode, self.size) MemoryError This is on a linux box with 2Gb of RAM, 3Gb of swap space, using PIL 1.1.4. As I understand it, the load() method loads the entire image into memory, and although there appears to be some ways to stream image data through PIL for processing, it looks like you can't use this type of approach with the crop() method. Am I wrong about this, or is there another way to accomplish the same type of thing (saving a region of an image as an image) without using crop()? Thanks in advance for any guidance you can give. ____________________________ adam smith ajs17 at cornell.edu 255-8893 215 ccc From fredrik at pythonware.com Wed Aug 31 17:47:04 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 31 Aug 2005 17:47:04 +0200 Subject: [Image-SIG] reaching memory limits with crop method References: <14810.128.253.230.141.1125498031.squirrel@128.253.230.141> Message-ID: Adam J Smith wrote: > We are encountering memory errors while processing very large images (over > 3Gb TIFFs, 17888x45408 px). We are trying to make "tiles" of the image by > calling PIL's crop method and saving the resulting images. if you open such a file in PIL, what does the "tile" attribute contain? can you try the following on your files and post the result? >>> im = Image.open("verylargetiff.tif") >>> im.mode >>> im.size >>> im.tile From kevin at cazabon.com Sat Aug 27 12:45:20 2005 From: kevin at cazabon.com (kevin@cazabon.com) Date: Sat, 27 Aug 2005 12:45:20 +0200 Subject: [Image-SIG] PIL and py2exe References: <003101c5a271$ae29db30$0d00a8c0@aziraphale> Message-ID: <014401c5aaf4$6c15b030$650aa8c0@duallie> When you use py2exe, you can specifically exclude modules - in your setup.cfg file just add a line that says: excludes=Tkinter, (etc.) For forcing py2exe to import the format modules, just explicitly import them in your script, or once again, put an "includes" line in the seutp.cfg file for py2exe. Kevin. ----- Original Message ----- From: Sean Curtis To: image-sig at python.org Sent: Tuesday, August 16, 2005 4:49 PM Subject: [Image-SIG] PIL and py2exe the initialization of PIL does two things that are banging heads with py2exe: 1) It always imported Tk "just in case". Even if I'm not using Tk, Tk is imported. This causes py2exe to load everything in Tk causing my install to get ridiculously huge. Is there any way around this? 2) The file format modules are imported on the sly using the __import__ function and constructing the module names at runtime (or at least at compile time.) Because of this, py2exe doesn't recognize module dependencies and I get a distribution with no file plugins (and thus, the ability to read NOTHING.) My gut feeling is that the answer for 1 is what's being done in 2 and the answer to 2 is what's being done in 1. Is there any around these things other than my hacking my own install of PIL? Thanks, Sean Curtis ------------------------------------------------------------------------------ _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050827/e91e6fcf/attachment.html From kevin at cazabon.com Sat Aug 27 12:46:47 2005 From: kevin at cazabon.com (kevin@cazabon.com) Date: Sat, 27 Aug 2005 12:46:47 +0200 Subject: [Image-SIG] PIL 1.1.5 - Loss of resolution References: <0MKz5u-1Dn1Cq3ieD-00071J@mrelay.perfora.net> Message-ID: <015c01c5aaf4$9fe27dd0$650aa8c0@duallie> When you rotate an image, you're not modifying the image in place - the result is a new image, which unfortunately doesn't carry the format data from the original. You can simply copy the data over yourself from the original, or supply the dpi setting to the TIFF module when saving (it's supported now). Kevin. ----- Original Message ----- From: Tim Ake To: image-sig at python.org Sent: Monday, June 27, 2005 11:31 PM Subject: [Image-SIG] PIL 1.1.5 - Loss of resolution Hi, I am using PIL 1.1.5 with Python 2.4, and am seeing a loss of resolution when dealing with images. I open an image that is 200 dpi, do a rotate, and save the rotated image. What I'm seeing is that the rotated image is saved at the same size, but is at 100 dpi instead of 200 dpi. My code frament is as follows: # open the tif file image im = Image.open(strFile) # rotate the image 90 degrees CCW om = im.rotate(90) # save the image as a.tif om.save("a.tif", "TIFF") #save the rotated file I can't afford a loss of resolution - any thoughts on maintaining my original resolution? Thanks! Tim Ake 335 Old Hickory Rd. Woodstock, GA 30188 mailto:tim at timake.com http://www.timake.com (770) 928-2433 (phone) (404) 944-4890 (cell) soli deo gloria ------------------------------------------------------------------------------ _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050827/5db117a2/attachment.htm From christianj at implicitnetworks.com Mon Aug 29 07:01:14 2005 From: christianj at implicitnetworks.com (Christian M. Jensen) Date: Sun, 28 Aug 2005 22:01:14 -0700 Subject: [Image-SIG] Dithering Message-ID: <326A1C8DE34E8E4189BE602CE79167843D5E@corporate.implicit.implicitnetworks.com> If I were to build a 32 gray level palette, still composed of 256 colors, just having duplicates, 000011111111222222222 etc. What would the code look like - general example is fine, I am pretty adept. I am just looking for the recommended method to use. Please include how to build and apply the palette. Thanks! ________________________________ From: image-sig-bounces at python.org on behalf of Fredrik Lundh Sent: Sun 8/28/2005 1:27 PM To: image-sig at python.org Subject: Re: [Image-SIG] Dithering Christian M. Jensen wrote: > I need to take a 256 level gray image down to 32 levels with nice > dithering. What is the best process for doing that? unless I'm missing something, I don't think you can do that in 1.1.5 (unless you want to do the dithering by hand). the core library can do dithering both to fixed palettes and optimal palettes, but PIL's convert method only exposes the "dither to web palette" and "map to nearest N color" variants. (if you want to do manual dithering, use quantize(32) on the source image to get a reference image, take the difference between them, and propagate the errors in some suitable way) _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050828/76bdd1a8/attachment.html From nickg at modp.com Wed Aug 31 17:11:45 2005 From: nickg at modp.com (nickg) Date: Wed, 31 Aug 2005 11:11:45 -0400 Subject: [Image-SIG] On Controlling TrueType Font Antialiasing Message-ID: <31AE032A-4C34-41B4-98D3-0257FEB53F98@modp.com> Hello all. I assume this is mailing list for the python imaging library: http:// www.pythonware.com/products/pil/index.htm If so, let me say that I love PIL! But, I bumped into a problem. For an RGB image I wanted to use a small TrueType "pixel" font without antialiasing. (for instance Courier at 8 pt) I didn't see anything in the documentation on how to control this. However I found that setting "fontmode" on an ImageDraw instance seems to work The by commented out the draw.fontmode="1" one will get antialiasing or not. import sys import Image, ImageFont, ImageDraw font = ImageFont.truetype("/System/Library/Fonts/Monaco.dfont", 8) im = Image.new("RGB", (100, 100), "White") draw = ImageDraw.Draw(im) # draw.fontmode = "1" # draw.text((10,10), "hello", fill="Black", font=font) im.save(sys.stdout, "png") I assume this is a hack. It would be great if "fontmode" were formally exposed in ImageDraw.text as an option such as "antialias=true/false" I'm happy to work on a patch if so desired. thanks all, --nickg Here's the relevant code trace: ImageDraw: ctor: sets fontmode def __init__(self, im, mode=None): im.load() if im.readonly: im._copy() # make it writable blend = 0 if mode is None: mode = im.mode if mode != im.mode: if mode == "RGBA" and im.mode == "RGB": blend = 1 else: raise ValueError("mode mismatch") if mode == "P": self.palette = im.palette else: self.palette = None self.im = im.im self.draw = Image.core.draw(self.im, blend) self.mode = mode if mode in ("I", "F"): self.ink = self.draw.draw_ink(1, mode) else: self.ink = self.draw.draw_ink(-1, mode) if mode in ("1", "P", "I", "F"): # FIXME: fix Fill2 to properly support matte for I+F images self.fontmode = "1" else: self.fontmode = "L" # aliasing is okay for other modes self.fill = 0 self.font = None ImageDraw.text: passes fontmode to ImageFont.getmask def text(self, xy, text, fill=None, font=None, anchor=None): ink, fill = self._getink(fill) if font is None: font = self.getfont() if ink is None: ink = fill if ink is not None: try: mask = font.getmask(text, self.fontmode) except TypeError: mask = font.getmask(text) self.draw.draw_bitmap(xy, mask, ink) ImageFont.getmask calls fontrender with mode == "1", i.e. mode==1 -> 1, mode != 1 -> 0 def getmask(self, text, mode="", fill=Image.core.fill): size = self.font.getsize(text) im = fill("L", size, 0) self.font.render(text, im.id, mode=="1") return im For Freetype fonts, this goes to _imagingft.c, font_render and here mask = 1, no antialias mask = 0, antialias -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/image-sig/attachments/20050831/b50c35ff/attachment.htm