From santoshh19 at yahoo.co.in Wed Apr 1 21:20:47 2009 From: santoshh19 at yahoo.co.in (santosh panda) Date: Thu, 2 Apr 2009 00:50:47 +0530 (IST) Subject: [Image-SIG] Raster Calculation Message-ID: <578829.38226.qm@web95409.mail.in2.yahoo.com> Dear List members, I am a beginner in Python programming, I want to write a python script which would take 1 band .tiff raster image as input, then calculate the reflectance value for each pixel using the following equation [refl] = (pi * ((((lmax - lmin) / 255) * [filename]) + lmin) * d^2 ) / (esun * COS((90 - elevation) * .017453293)) and write the output to a raster file. Something very similar to what we do in ArcGIS raster calculator. I would appreciate any suggestion. Thanks for your time... Santosh Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From santoshh19 at yahoo.co.in Wed Apr 1 21:18:33 2009 From: santoshh19 at yahoo.co.in (santosh panda) Date: Thu, 2 Apr 2009 00:48:33 +0530 (IST) Subject: [Image-SIG] (no subject) Message-ID: <718622.42239.qm@web95410.mail.in2.yahoo.com> Dear List members, I am a beginner in Python programming, I want to write a python script which would take 1 band .tiff raster image as input, then calculate the reflectance value for each pixel using the following equation [refl] = (pi * ((((lmax - lmin) / 255) * [filename]) + lmin) * d^2 ) / (esun * COS((90 - elevation) * .017453293)) and write the output to a raster file. Something very similar to what we do in ArcGIS raster calculator. I would appreciate any suggestion. Thanks for your time... Santosh Connect with friends all over the world. Get Yahoo! India Messenger at http://in.messenger.yahoo.com/?wm=n/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Wed Apr 1 22:03:23 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 1 Apr 2009 22:03:23 +0200 Subject: [Image-SIG] Raster Calculation In-Reply-To: <578829.38226.qm@web95409.mail.in2.yahoo.com> References: <578829.38226.qm@web95409.mail.in2.yahoo.com> Message-ID: <368a5cd50904011303h58d45ebdi8b14145752a53e22@mail.gmail.com> 2009/4/1 santosh panda : > Dear List members, > > I am a beginner in Python programming, I want to write a python script which > would take 1 band .tiff raster image as input, then calculate the > reflectance value for each pixel using the following equation > [refl] = (pi * ((((lmax - lmin) / 255) * [filename]) > + lmin) * d^2 ) / (esun * COS((90 - elevation) * .017453293)) > and write the output to a raster file. You could use PIL's ImageMath module: >>> from PIL import Image, ImageMath, math >>> im = Image.open("input.tif") >>> out = ImageMath.eval("... expr ...", dict(im=im, lmax=..., pi=math.pi)) >>> out.save("output.tif") (see the handbook for details) or, alternatively, especially if you want to do more extensive calculations, numpy. Are elevation, esun etc constant for the whole image, btw? From santoshh19 at yahoo.co.in Thu Apr 2 08:31:29 2009 From: santoshh19 at yahoo.co.in (santosh panda) Date: Thu, 2 Apr 2009 12:01:29 +0530 (IST) Subject: [Image-SIG] PIL 1.1.6 Installation file Message-ID: <433421.15297.qm@web95405.mail.in2.yahoo.com> Dear List Members, I am looking for pil 1.1.6 installation file. All the search results takes me to either this http://effbot.org/downloads/#Imaging or http://www.pythonware.com/products/pil/ web pages and the links in both of the pages are not working. I don't know what's the deal here. I would appreciate any help or suggestion on the above issue. Thanks in advance... Santosh Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Thu Apr 2 12:55:30 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 2 Apr 2009 12:55:30 +0200 Subject: [Image-SIG] PIL 1.1.6 Installation file In-Reply-To: <433421.15297.qm@web95405.mail.in2.yahoo.com> References: <433421.15297.qm@web95405.mail.in2.yahoo.com> Message-ID: <368a5cd50904020355m7be2cf47yc9d3903385df5811@mail.gmail.com> On Thu, Apr 2, 2009 at 8:31 AM, santosh panda wrote: > I am looking for pil 1.1.6 installation file. All the search results takes > me to either this > http://effbot.org/downloads/#Imaging > or http://www.pythonware.com/products/pil/ > web pages and the links in both of the pages are not working.. I don't know > what's the deal here. Well, the links works perfectly fine from here, so it's most likely a local (or temporary) problem. Try again; if it still doesn't work, check with your local network administrators. From fredrik at pythonware.com Thu Apr 2 14:26:27 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 2 Apr 2009 14:26:27 +0200 Subject: [Image-SIG] ANN: PIL 1.1.7 alpha 2 (March 28, 2009) In-Reply-To: <368a5cd50903280936y707223a9lfacd36b36a3d29d8@mail.gmail.com> References: <368a5cd50903280642r4357c87bl9536f15d0d54a2e7@mail.gmail.com> <368a5cd50903280936y707223a9lfacd36b36a3d29d8@mail.gmail.com> Message-ID: <368a5cd50904020526s35981675g17d84304c214faac@mail.gmail.com> On Sat, Mar 28, 2009 at 6:36 PM, Fredrik Lundh wrote: >> Windows binaries for Python 2.4, 2.5, and 2.6 can be found here: >> >> ? ?http://effbot.org/downloads/#pil A binary for the python.org version of Python 2.5 for Mac OS X is now available, thanks to Chris Barker. It should work on Mac OS X 10.4 and 10.5, PPC or Intel. I've also posted Windows builds for a few ancient Python versions (but I don't really expect anyone to ever use one of those :-). From charlie at begeistert.org Thu Apr 2 22:31:51 2009 From: charlie at begeistert.org (Charlie Clark) Date: Thu, 2 Apr 2009 22:31:51 +0200 Subject: [Image-SIG] ANN: PIL 1.1.7 alpha 2 (March 28, 2009) In-Reply-To: <368a5cd50904020526s35981675g17d84304c214faac@mail.gmail.com> References: <368a5cd50903280642r4357c87bl9536f15d0d54a2e7@mail.gmail.com> <368a5cd50903280936y707223a9lfacd36b36a3d29d8@mail.gmail.com> <368a5cd50904020526s35981675g17d84304c214faac@mail.gmail.com> Message-ID: <8135AE4E-8FEA-4305-B102-BCEF9D63442C@begeistert.org> Am 02.04.2009 um 14:26 schrieb Fredrik Lundh: > I've also posted Windows builds for a few ancient Python versions (but > I don't really expect anyone to ever use one of those :-). No one expects the Spanish Inquistion! (Apologies for the blatantly inappropriate but Python-related joke) ;-) Looking forward to the new version. Charlie -- Charlie Clark Helmholtzstr. 20 D?sseldorf D- 40215 Tel: +49-211-938-5360 GSM: +49-178-782-6226 From todd at toddreed.name Thu Apr 2 22:55:06 2009 From: todd at toddreed.name (Todd Reed) Date: Thu, 2 Apr 2009 14:55:06 -0600 Subject: [Image-SIG] Bug in Image.rotate method and documentation Message-ID: I am using PIL 1.1.6, and found a trivial-to-fix bug in the Image.rotate method: If the expand argument is True (1), then the resample argument is ignored. Line 1320 is: return self.transform((w, h), AFFINE, matrix) and should be: return self.transform((w, h), AFFINE, matrix, resample) I also noticed that the documentation incorrectly specifies the resample argument as filter. Thanks. -- Todd From fredrik at pythonware.com Fri Apr 3 00:54:34 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 3 Apr 2009 00:54:34 +0200 Subject: [Image-SIG] Bug in Image.rotate method and documentation In-Reply-To: References: Message-ID: <368a5cd50904021554y26e2e6e7t952bf378936cb6d@mail.gmail.com> On Thu, Apr 2, 2009 at 10:55 PM, Todd Reed wrote: > I am using PIL 1.1.6, and found a trivial-to-fix bug in the Image.rotate > method: This is fixed in 1.1.7. As for filter vs. resample, it's a positional argument, not a keyword argument. From fredrik at pythonware.com Fri Apr 3 00:55:40 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 3 Apr 2009 00:55:40 +0200 Subject: [Image-SIG] Bug in Image.rotate method and documentation In-Reply-To: <368a5cd50904021554y26e2e6e7t952bf378936cb6d@mail.gmail.com> References: <368a5cd50904021554y26e2e6e7t952bf378936cb6d@mail.gmail.com> Message-ID: <368a5cd50904021555q7d0af5c1m327a02a1b26ac3eb@mail.gmail.com> On Fri, Apr 3, 2009 at 12:54 AM, Fredrik Lundh wrote: > This is fixed in 1.1.7. The relevant changeset is here, btw: http://hg.effbot.org/pil-2009-raclette/changeset/db1b40ca85c4/ From sierra_mtnview at sbcglobal.net Thu Apr 2 16:54:47 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Thu, 02 Apr 2009 07:54:47 -0700 Subject: [Image-SIG] Default Structure of a 640x480 PIL BMP File? Message-ID: <49D4D1B7.7040109@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Thu Apr 2 21:23:48 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Thu, 02 Apr 2009 12:23:48 -0700 Subject: [Image-SIG] PIL Handbooks Message-ID: <49D510C4.1030000@sbcglobal.net> An HTML attachment was scrubbed... URL: From santoshh19 at yahoo.co.in Fri Apr 3 04:59:42 2009 From: santoshh19 at yahoo.co.in (santosh panda) Date: Fri, 3 Apr 2009 08:29:42 +0530 (IST) Subject: [Image-SIG] Raster Calculation: Script Error Message-ID: <81265.44123.qm@web95409.mail.in2.yahoo.com> Dear List Members, I am using Landsat single band image as input and I want to apply the equation shown below in the script and write the output to a new raster file. 1. The below pasted script works fine without 'cos' term but it fails with 'cos' term even if I imported python math module. Should I import any other module so that the script will recognize 'cos' term? 2. I want my output data to be in same projection and pixel size as my input data. What command do I have to use to maintain the projection details and pixel size? 3. My input data is 8 bit and I want my output data also in 8 bit. How can I maintain the data mode? script: from PIL import Image, ImageMath import os, math os.curdir = 'C:/temp' im = Image.open("testraster.tif") out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* 0.0174)))", im=im, lmax= 30, lmin= 0.37) out.save("outRaster.tif") print 'All done...' Traceback (most recent call last): ? File "C:\temp\reflectance.py", line 7, in ??? out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* 0.0174)))", im=im, lmax= 30, lmin= 0.37) ? File "C:\Python25\Lib\site-packages\PIL\ImageMath.py", line 203, in eval ??? out =__builtin__.eval(expression, args) ? File "", line 1, in NameError: name 'cos' is not defined I looked in the Imaginbook and its tutorial section, but didn't find the exact answer to my questions. I would appreciate any suggestion or help to solve my problem. Thanks in advance. Santosh Add more friends to your messenger and enjoy! Go to http://messenger.yahoo.com/invite/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From adeuring at gmx.net Fri Apr 3 17:08:03 2009 From: adeuring at gmx.net (abel deuring) Date: Fri, 03 Apr 2009 17:08:03 +0200 Subject: [Image-SIG] PIL Handbooks In-Reply-To: <49D510C4.1030000@sbcglobal.net> References: <49D510C4.1030000@sbcglobal.net> Message-ID: <49D62653.8060904@gmx.net> On 02.04.2009 21:23, Wayne Watson wrote: > I'm very new to PIL, and don't see any handbooks for 1.1.6 or the forthcoming > 1.1.7. In fact, this looks like the extent of them: > > * Python Imaging Library Handbook for 1.1.5 > (online) > * Python Imaging Library Handbook for 1.1.3 > (PDF) > > Somewhere in my recent search I see that 1.1.6 has some features like digital > cameras and scanners. Ah here, I can't remember when exactly scanner support was added to PIL, but it is there since quite some time. I think though that it is not described in the Docs subdirectory of PIL's sourcecode. OTOH, the Sane module is basically a wrapper for the Sane C library, so you'd get most information from http://www.sane-project.org/html/ -- you "only" need to translate all the C stuff into Python ;) Regarding cameras: I can't claim that I have a good overview of all PIL features, but I think "features like digital cameras" means effectively support for cameras in the Sane library. I wouldn't take this too serious: While Sane has some camera support, cameras and scanners are quite different and the Sane API is quite closely tailored to suit "scanning needs" so that I'd say that camera support is quite marginal. Abel > > I'd settle even for a 1.15 pdf of the handbook right now. > > -- > > Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** > > > "Less than all cannot satisfy Man." -- William Blake > > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From adeuring at gmx.net Fri Apr 3 17:10:23 2009 From: adeuring at gmx.net (abel deuring) Date: Fri, 03 Apr 2009 17:10:23 +0200 Subject: [Image-SIG] Raster Calculation: Script Error In-Reply-To: <81265.44123.qm@web95409.mail.in2.yahoo.com> References: <81265.44123.qm@web95409.mail.in2.yahoo.com> Message-ID: <49D626DF.7060206@gmx.net> On 03.04.2009 04:59, santosh panda wrote: > Dear List Members, > > I am using Landsat single band image as input and I want to apply the equation shown below in the script and write the output to a new raster file. > > 1. The below pasted script works fine without 'cos' term but it fails with 'cos' term even if I imported python math module. Should I import any other module so that the script will recognize 'cos' term? > > 2. I want my output data to be in same projection and pixel size as my input data. What command do I have to use to maintain the projection details and pixel size? > > 3. My input data is 8 bit and I want my output data also in 8 bit. How can I maintain the data mode? > > script: > from PIL import Image, ImageMath > import os, math > os.curdir = 'C:/temp' > im = Image.open("testraster.tif") > out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* 0.0174)))", im=im, lmax= 30, lmin= 0.37) > out.save("outRaster.tif") > > print 'All done...' > > Traceback (most recent call last): > File "C:\temp\reflectance.py", line 7, in > out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* 0.0174)))", im=im, lmax= 30, lmin= 0.37) > File "C:\Python25\Lib\site-packages\PIL\ImageMath.py", line 203, in eval > out =__builtin__.eval(expression, args) > File "", line 1, in > NameError: name 'cos' is not defined > > I looked in the Imaginbook and its tutorial section, but didn't find the exact answer to my questions. I would appreciate any suggestion or help to solve my problem. Use either: from math import cos x = cos(1) or import math x = math.cos(1) Abel From fredrik at pythonware.com Fri Apr 3 17:53:30 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 3 Apr 2009 17:53:30 +0200 Subject: [Image-SIG] Raster Calculation: Script Error In-Reply-To: <81265.44123.qm@web95409.mail.in2.yahoo.com> References: <81265.44123.qm@web95409.mail.in2.yahoo.com> Message-ID: <368a5cd50904030853t5e1ec0e2odb2af8f2c327fd2e@mail.gmail.com> On Fri, Apr 3, 2009 at 4:59 AM, santosh panda wrote: > I am using Landsat single band image as input and I want to apply the > equation shown below in the script and write the output to a new raster > file. > > 1. The below pasted script works fine without 'cos' term but it fails with > 'cos' term even if I imported python math module. Should I import any other > module so that the script will recognize 'cos' term? > > 2. I want my output data to be in same projection and pixel size as my input > data. What command do I have to use to maintain the projection details and > pixel size? > > 3. My input data is 8 bit and I want my output data also in 8 bit. How can I > maintain the data mode? > > script: > from PIL import Image, ImageMath > import os, math > os.curdir = 'C:/temp' > im = Image.open("testraster.tif") > out = ImageMath.eval("((3.14*(((0.11*im) + lmin)*25))/(70*cos(50* > 0.0174)))", im=im, lmax= 30, lmin= 0.37) > out.save("outRaster.tif") The ImageMath eval function only supports a small number of functions. You can either calculate that part of the expression outside the call and pass it in as a parameter, or pass in cos() itself as a callable parameter: out = ImageMath.eval(..., cos=math.cos) The eval function uses I or F as intermediate modes; to convert back to a smaller mode, you can either use the convert function as described here: http://effbot.org/imagingbook/imagemath.htm#built-in-functions or do the conversion before saving the image: out = ImageMath.eval(...) out = out.convert("L") out.save("...") >From you example above, it looks like the expression is constant for the entire image; in that case, using the "point()" method on the Image object is probably more efficient (at least as long as you're working on 8-bit images). You can either build a lookup table, or pass in a lambda or other callable; point will then calculate the value once for each possible pixel value, and translate the image in one pass over all pixels: e.g. def function(pixel): return math.pi * (((0.11*pixel) + lmin)*25))/(70*math.cos(50*> 0.0174))) out = im.point(function) This will call the function once for each possible value, and then do the mapping. If you're processing a large number of images, you can even precompute the table: lut = map(function, range(256)) and then do "out = im.point(lut)" for each image. From fredrik at pythonware.com Fri Apr 3 17:54:54 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 3 Apr 2009 17:54:54 +0200 Subject: [Image-SIG] Raster Calculation: Script Error In-Reply-To: <49D626DF.7060206@gmx.net> References: <81265.44123.qm@web95409.mail.in2.yahoo.com> <49D626DF.7060206@gmx.net> Message-ID: <368a5cd50904030854w38ef20d6lbc362992b7702381@mail.gmail.com> On Fri, Apr 3, 2009 at 5:10 PM, abel deuring wrote: > Use either: > > ?from math import cos > ?x = cos(1) > > or > > ?import math > ?x = math.cos(1) That doesn't work with ImageMath.eval - it provides its own environment (including the names you pass in). It does the trick if you're using "point" instead, though. From fredrik at pythonware.com Fri Apr 3 17:57:42 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 3 Apr 2009 17:57:42 +0200 Subject: [Image-SIG] Default Structure of a 640x480 PIL BMP File? In-Reply-To: <49D4D1B7.7040109@sbcglobal.net> References: <49D4D1B7.7040109@sbcglobal.net> Message-ID: <368a5cd50904030857j6e687be0pc97f81deff4d8899@mail.gmail.com> On Thu, Apr 2, 2009 at 4:54 PM, Wayne Watson wrote: > See Subject. Does it have a header, DIB,? palette, and data section? What is > the default depth? All BMP files have headers, of course; PIL uses a standard 40-byte header. Palettes and depths depend on the mode of the image you're saving. See the BmpImagePlugin sources for exact details. From fredrik at pythonware.com Fri Apr 3 18:00:17 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 3 Apr 2009 18:00:17 +0200 Subject: [Image-SIG] PIL Handbooks In-Reply-To: <49D510C4.1030000@sbcglobal.net> References: <49D510C4.1030000@sbcglobal.net> Message-ID: <368a5cd50904030900y5b9b54eck5d3e75a5ea0ea878@mail.gmail.com> On Thu, Apr 2, 2009 at 9:23 PM, Wayne Watson wrote: > I'm very new to PIL, and don't see any handbooks for 1.1.6 or the > forthcoming 1.1.7. In fact, this looks like the extent of them: > > Python Imaging Library Handbook for 1.1.5 (online) > Python Imaging Library Handbook for 1.1.3 (PDF) Hmm. I thought we had a link to the working copy somewhere on pythonware.com, but given that I cannot even find it myself, it's probably not there. Anyway, the 1.1.6 working copy is here: http://effbot.org/imagingbook/ Not sure why it hasn't been pushed to the PythonWare site; I'll look into that when I find the time. From adeuring at gmx.net Fri Apr 3 18:18:44 2009 From: adeuring at gmx.net (abel deuring) Date: Fri, 03 Apr 2009 18:18:44 +0200 Subject: [Image-SIG] Raster Calculation: Script Error In-Reply-To: <368a5cd50904030854w38ef20d6lbc362992b7702381@mail.gmail.com> References: <81265.44123.qm@web95409.mail.in2.yahoo.com> <49D626DF.7060206@gmx.net> <368a5cd50904030854w38ef20d6lbc362992b7702381@mail.gmail.com> Message-ID: <49D636E4.1080907@gmx.net> On 03.04.2009 17:54, Fredrik Lundh wrote: > On Fri, Apr 3, 2009 at 5:10 PM, abel deuring wrote: > >> Use either: >> >> from math import cos >> x = cos(1) >> >> or >> >> import math >> x = math.cos(1) > > That doesn't work with ImageMath.eval - it provides its own > environment (including the names you pass in). whoops... right, I missed the ImageMath.eval stuff completely. Deuring, read these questions more carefully! Abel > > It does the trick if you're using "point" instead, though. > > > From fredrik at pythonware.com Fri Apr 3 23:02:52 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 3 Apr 2009 23:02:52 +0200 Subject: [Image-SIG] Default Structure of a 640x480 PIL BMP File? In-Reply-To: <49D673BF.8010601@sbcglobal.net> References: <49D4D1B7.7040109@sbcglobal.net> <368a5cd50904030857j6e687be0pc97f81deff4d8899@mail.gmail.com> <49D673BF.8010601@sbcglobal.net> Message-ID: <368a5cd50904031402l649bfcaan97c69c9058bd9edc@mail.gmail.com> On Fri, Apr 3, 2009 at 10:38 PM, Wayne Watson wrote: > The only PIL document that I have available is the PIL-handbook-2.pdf, which > describes 1.1.3. I can find nothing in it about the module you mention. I > have some scattered PIL material, but it is of no help here. I did a Google, > and see some references to it, but nothing explanatory. What document or web > site would I find the description? If you have installed the library, you have the BmpImagePlugin module installed (this is a Python library, so the source for the BmpImagePlugin module is in a file called BmpImagePlugin.py). I find your question a bit puzzling, btw. Why would anyone create a BMP-writing library that didn't include a header and data when the BMP specification says that a BMP file contains a header and data? Is this some homework assignment? From sierra_mtnview at sbcglobal.net Fri Apr 3 22:38:23 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Fri, 03 Apr 2009 13:38:23 -0700 Subject: [Image-SIG] Default Structure of a 640x480 PIL BMP File? In-Reply-To: <368a5cd50904030857j6e687be0pc97f81deff4d8899@mail.gmail.com> References: <49D4D1B7.7040109@sbcglobal.net> <368a5cd50904030857j6e687be0pc97f81deff4d8899@mail.gmail.com> Message-ID: <49D673BF.8010601@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Fri Apr 3 23:08:52 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Fri, 03 Apr 2009 14:08:52 -0700 Subject: [Image-SIG] PIL Handbooks In-Reply-To: <368a5cd50904030900y5b9b54eck5d3e75a5ea0ea878@mail.gmail.com> References: <49D510C4.1030000@sbcglobal.net> <368a5cd50904030900y5b9b54eck5d3e75a5ea0ea878@mail.gmail.com> Message-ID: <49D67AE4.8020102@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sat Apr 4 02:56:06 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Fri, 03 Apr 2009 17:56:06 -0700 Subject: [Image-SIG] Default Structure of a 640x480 PIL BMP File? In-Reply-To: <368a5cd50904031402l649bfcaan97c69c9058bd9edc@mail.gmail.com> References: <49D4D1B7.7040109@sbcglobal.net> <368a5cd50904030857j6e687be0pc97f81deff4d8899@mail.gmail.com> <49D673BF.8010601@sbcglobal.net> <368a5cd50904031402l649bfcaan97c69c9058bd9edc@mail.gmail.com> Message-ID: <49D6B026.2030705@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sat Apr 4 03:00:35 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Fri, 03 Apr 2009 18:00:35 -0700 Subject: [Image-SIG] Why Suspicious Headers? Message-ID: <49D6B133.3020104@sbcglobal.net> An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Sat Apr 4 03:17:02 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 4 Apr 2009 03:17:02 +0200 Subject: [Image-SIG] Why Suspicious Headers? In-Reply-To: <49D6B133.3020104@sbcglobal.net> References: <49D6B133.3020104@sbcglobal.net> Message-ID: <368a5cd50904031817k44564261ib17be54fd02e5923@mail.gmail.com> Your mail program produces HTML mail without an alternative text section; that's a rather common practice among spammers, messes things up for the mailing list archives, and makes your mail pretty much unreadable in some (older) mail programs. Here's the archived version of this mail: http://mail.python.org/pipermail/image-sig/2009-April/005550.html and here's what a non-HTML mail program would see (if it displays the mail at all): http://mail.python.org/pipermail/image-sig/attachments/20090403/b5052bc9/attachment.htm A quick look at the SeaMonkey sites shows that they have absolutely no documentation whatsoever (except for a few random screenshots), so I cannot help you configure the mail program to generate multipart/alternative instead of text/html-only mail, but there's probably some option for this. On Sat, Apr 4, 2009 at 3:00 AM, Wayne Watson wrote: > I've just begun using this mailing list, and have posted about 5-6 times. > Several posts are being held by the moderator because of suspicious headers. > I'm using Moz/Sea Monkey via SBC Global as my ISP. What's suspicious about > them? > -- > > Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) > > > "Less than all cannot satisfy Man." -- William Blake > > > _______________________________________________ > Image-SIG maillist ?- ?Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > From fredrik at pythonware.com Sat Apr 4 03:29:10 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 4 Apr 2009 03:29:10 +0200 Subject: [Image-SIG] Default Structure of a 640x480 PIL BMP File? In-Reply-To: <49D6B026.2030705@sbcglobal.net> References: <49D4D1B7.7040109@sbcglobal.net> <368a5cd50904030857j6e687be0pc97f81deff4d8899@mail.gmail.com> <49D673BF.8010601@sbcglobal.net> <368a5cd50904031402l649bfcaan97c69c9058bd9edc@mail.gmail.com> <49D6B026.2030705@sbcglobal.net> Message-ID: <368a5cd50904031829q5c70d1b6sa860fe504ff881fd@mail.gmail.com> On Sat, Apr 4, 2009 at 2:56 AM, Wayne Watson wrote: > I'm definitely well beyond my student days. > > Two months ago I took it upon myself to add new features to a 2000+ line > program,? authored by someone else, that use a special video camera and > hardware to detect bright meteors, and produce video images, b/w. My prior > experience with Python Win was limited to maybe a month of non-GUI work. No > Tkinter or PIL. I've gotten a fair dose of Tkinter with dialogs and menus. > > A few days ago I began looking at analytic features that I might want to add > using the video images/frames.? My first question was what sort of video > format is used? The answer seems to be a 640/480 b/w 8-bit pixel. That's it. > No headers or anything else. Although the image, date/time, meteor track > data are written to files, the files are not anything anyone else uses. > > The user can write individual frames in jpg and tiff. I began think of > adding bmp; however, I was curious how bmp worked, and whether I had control > over the bit depth. I understand the jpb and tiff have no headers--I think. > As I understand, it bmp has several types of blocks before the image, dib, > header, palette, I think.? If I'm going to have to provide them, I have yet > to figure that out. At this point, I'm mostly curious about them. That still doesn't make much sense - TIFF and JPEG definitely have headers that identify the contents of the files, and surely the point of using PIL for this would be to let PIL handle the BMP writing for you, not use the PIL handbook to figure out how to generate your own BMP files? All you have to do is to store the pixel data in a PIL Image object, and then call the save method: # load the image into a PIL Image object im = Image.open(filename) # or Image.fromstring or frombuffer or new/putdata or... # save the image to disk, as a BMP file im.save("out.bmp") But we're still missing way too much information to know how to best help you sort this one out. From where are you getting the video frames, and what format does the frames have? Is it just a 640x408=307200 byte file on disk, with no headers or anything? Or do you have the data in a memory buffer? What language is the program written in? If Python, what GUI toolkit are you using to display the frames? From cannon.el at gmail.com Sat Apr 4 06:59:14 2009 From: cannon.el at gmail.com (Laura & Edward Cannon) Date: Fri, 3 Apr 2009 21:59:14 -0700 Subject: [Image-SIG] Why Suspicious Headers? In-Reply-To: <368a5cd50904031817k44564261ib17be54fd02e5923@mail.gmail.com> References: <49D6B133.3020104@sbcglobal.net> <368a5cd50904031817k44564261ib17be54fd02e5923@mail.gmail.com> Message-ID: I also find that unless I send the message directly to image-sig at python.org I get held. (my mail client likes to respond the the person and CC image-sig at python.org) That might also be the cause of your problem. On Fri, Apr 3, 2009 at 6:17 PM, Fredrik Lundh wrote: > > Your mail program produces HTML mail without an alternative text > section; that's a rather common practice among spammers, messes things > up for the mailing list archives, and makes your mail pretty much > unreadable in some (older) mail programs. ?Here's the archived version > of this mail: > > ? ?http://mail.python.org/pipermail/image-sig/2009-April/005550.html > > and here's what a non-HTML mail program would see (if it displays the > mail at all): > > ? http://mail.python.org/pipermail/image-sig/attachments/20090403/b5052bc9/attachment.htm > > A quick look at the SeaMonkey sites shows that they have absolutely no > documentation whatsoever (except for a few random screenshots), so I > cannot help you configure the mail program to generate > multipart/alternative instead of text/html-only mail, but there's > probably some option for this. > > > > On Sat, Apr 4, 2009 at 3:00 AM, Wayne Watson > wrote: > > I've just begun using this mailing list, and have posted about 5-6 times. > > Several posts are being held by the moderator because of suspicious headers. > > I'm using Moz/Sea Monkey via SBC Global as my ISP. What's suspicious about > > them? > > -- > > > > ? ? ? ? ? ?Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > > > ? ? ? ? ? ? ?(121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) > > > > > > ? ? ? ? ? "Less than all cannot satisfy Man." -- William Blake > > > > > > _______________________________________________ > > Image-SIG maillist ?- ?Image-SIG at python.org > > http://mail.python.org/mailman/listinfo/image-sig > > > > > _______________________________________________ > Image-SIG maillist ?- ?Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From johnson at pharmacy.arizona.edu Sat Apr 4 18:13:52 2009 From: johnson at pharmacy.arizona.edu (Bruce Johnson) Date: Sat, 4 Apr 2009 09:13:52 -0700 Subject: [Image-SIG] Why Suspicious Headers? In-Reply-To: <368a5cd50904031817k44564261ib17be54fd02e5923@mail.gmail.com> References: <49D6B133.3020104@sbcglobal.net> <368a5cd50904031817k44564261ib17be54fd02e5923@mail.gmail.com> Message-ID: <8866FEBC-4E9D-4747-A23A-FB7CCB39B9F9@pharmacy.arizona.edu> On Apr 3, 2009, at 6:17 PM, Fredrik Lundh wrote: > A quick look at the SeaMonkey sites shows that they have absolutely no > documentation whatsoever (except for a few random screenshots), so I > cannot help you configure the mail program to generate > multipart/alternative instead of text/html-only mail, but there's > probably some option for this. Sea Monkey == Thunderbird + Firefox jammed together into one app like the old Netscape days. The options are in the composition preferences , just like Thunderbird. -- Bruce Johnson U of Az College of Pharmacy Information Technology Group Institutions don't have opinions, merely customs From wrybread at gmail.com Sat Apr 4 19:16:12 2009 From: wrybread at gmail.com (Alec Bennett) Date: Sat, 4 Apr 2009 11:16:12 -0600 Subject: [Image-SIG] text along a curve? Message-ID: I'm wondering if its possible to do text along a curve in PIL? Or if anyone can think of another way, short of Photoshop? Thanks for the help. From sierra_mtnview at sbcglobal.net Sat Apr 4 19:48:40 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 04 Apr 2009 10:48:40 -0700 Subject: [Image-SIG] Drawing, blobs, rubber bands, moving objects on the canvas (No html) Message-ID: <49D79D78.6060401@sbcglobal.net> (I have three posts delayed in moderator check needed. All with html format. Maybe this will break through. It's pure text.) As I start to warm up to PIL, I'd like to know a little more about what I might be able to do. Right now I'm trying to figure out how to overlay a mask over an image. That looks feasible through some combo of the convert method and the use of the alpha channel. It's quite conceivable that I will want to move the mask around the image with a mouse. Those are just a few things I have in mind. I've become familiar with part of the Grayson book whose contents are partly available on the web. It's mostly about graphics, Tkinter and the Pmw toolkit. Chapter 10 below looks of interest in the sense that I would like to move objects around the canvas, and possible stretch objects. Is it possible to do these things in PIL (under Python Win)? Secondly, I really have no experience with Pmw, but it would be of interest to use it to see how his examples work. All of the book examples are on the web. Is Pmw a freebie, and still maintained? From chapter 10 of Grayson's book on Tkinter 10 Drawing blobs and rubber lines 237 10.1 Drawing on a canvas 238 Moving canvas objects 243 10.2 A more complete drawing program 244 10.3 Scrolled canvases 251 10.4 Ruler-class tools 254 10.5 Stretching canvas objects 258 10.6 Some finishing touches 262 10.7 Speed drawing 271 10.8 Summary 275 -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** From sierra_mtnview at sbcglobal.net Sat Apr 4 20:40:47 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 04 Apr 2009 11:40:47 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt version) Message-ID: <49D7A9AF.3070009@sbcglobal.net> I have a 640x480 by 8-bit image produced by the hardware that interfaces with a program. I would like to create a transparent image with a circle on it and a crosshair at the center of the circle, then place it on top of the first (real) image (produced by the h/w). I have no trouble drawing on the real image, but I'd like use this transparency idea here. The reason is that eventually I'd like the user to drag around the circle over the real image, and place it where they think the center of the real image is. Yes, it's important not only to have the cross hair, but the circle too. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From sierra_mtnview at sbcglobal.net Sat Apr 4 14:27:22 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 04 Apr 2009 05:27:22 -0700 Subject: [Image-SIG] Why Suspicious Headers? In-Reply-To: References: <49D6B133.3020104@sbcglobal.net> <368a5cd50904031817k44564261ib17be54fd02e5923@mail.gmail.com> Message-ID: <49D7522A.5080801@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sat Apr 4 14:43:13 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 04 Apr 2009 05:43:13 -0700 Subject: [Image-SIG] Examining the Palette and Image Properties Message-ID: <49D755E1.6060402@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sat Apr 4 15:03:18 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 04 Apr 2009 06:03:18 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image Message-ID: <49D75A96.4020805@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sat Apr 4 19:29:29 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 04 Apr 2009 10:29:29 -0700 Subject: [Image-SIG] Why Suspicious Headers? In-Reply-To: <8866FEBC-4E9D-4747-A23A-FB7CCB39B9F9@pharmacy.arizona.edu> References: <49D6B133.3020104@sbcglobal.net> <368a5cd50904031817k44564261ib17be54fd02e5923@mail.gmail.com> <8866FEBC-4E9D-4747-A23A-FB7CCB39B9F9@pharmacy.arizona.edu> Message-ID: <49D798F9.7060305@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Mon Apr 6 01:27:40 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sun, 05 Apr 2009 16:27:40 -0700 Subject: [Image-SIG] Why Suspicious Headers? In-Reply-To: <200904061049.38769.g.kloss@massey.ac.nz> References: <49D6B133.3020104@sbcglobal.net> <8866FEBC-4E9D-4747-A23A-FB7CCB39B9F9@pharmacy.arizona.edu> <49D798F9.7060305@sbcglobal.net> <200904061049.38769.g.kloss@massey.ac.nz> Message-ID: <49D93E6C.1090404@sbcglobal.net> Actually, it looks I need to do plain text or my msgs do not get posted until the moderator clears them. I have one that's been in limbo now for possibly 36 hours. I may have reposted it as text. I think I'm now operating in plain text now, and until I get by some questions I have. As far as top vs bottom, I cannot change the scheme for every mail-list or newsgroup I go to. I'm afraid your stuck with wherever I post, top or bottom. I get messages top, bottom, and sprinkled. It doesn't bother me a bit. Guy K. Kloss wrote: > Hi Wayne, > > On Sun, 05 Apr 2009 05:29:29 Wayne Watson wrote: > >> I'm going to latch onto your post in an attempt to see if I can post >> without delay. I have three posts hanging for moderator approval. If it >> fails, I'll repost as text and not html. >> > > It would be *much* appreciated if you could use plain text for the mailing > list, plus not to top post (and full quote underneath). HTML plus top posting > makes following threads in a mailing list a real pain! > > Thx, > > Guy > > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** The Obama Administration plans to double the production in solar energy from 1% to 2% of the total energy supply in the next few years. One nuclear reaction would do the same. Heard on Bill Wattenburg, KGO-AM "Less than all cannot satisfy Man." -- William Blake From rollbak at gmail.com Mon Apr 6 05:33:02 2009 From: rollbak at gmail.com (Lucas) Date: Mon, 6 Apr 2009 00:33:02 -0300 Subject: [Image-SIG] Examining the Palette and Image Properties In-Reply-To: <49D755E1.6060402@sbcglobal.net> References: <49D755E1.6060402@sbcglobal.net> Message-ID: <194b7da00904052033i4660ca21u5d768bcd92f65ad1@mail.gmail.com> Hello, I think what you have to do instead of img.info is to call img.mode, this will give you the type of image (RGB, ARGB, P (indexed), etc). In a 'P' mode image you can make the following: myimg = im.palette data = myimg.getdata() data is a tuple with the following structure: (mode, str) mode: is the color mode, eg: RGB, ARGB... list: is a string that contains the values of the palette colors, once following each other, and you have to parse it by your own depending on the mode. eg: print data ('RGB', "\x80\x00\x00\x00\x00\x00\x00\x80\x00.....") The you can decode this with the following code: decoded = [ord(component) for component in data[1]] print decoded [128, 0, 0, 0, 0, 0, 0, 128, 0,...] because of the mode is RGB the colors of our palette are: R G B 128, 0, 0 0, 0, 0 0, 128, 0 ..... I hope i was clear enough. Lucas. On Sat, Apr 4, 2009 at 9:43 AM, Wayne Watson wrote: > Suppose img is a PIL image. img.palette is then an instance, say, myimg. How > do I display what is in it? mimg.hello_in_there()? > > Is the depth contained in the palette? PIL-handbook-2.pdf (1.1.3) has no > PaletteImage description, which is where I would expect to find out about > palette methods. Where other than looking in the PIL would I find a > description? Maybe this is basic Python OOP as a means to find out? Doc? > > When I use img.info on various images I see in a program I'm using, I see > this: > ??????? #? wagon.gif:??????? {'compression': 'raw', 'dpi': (1, 1)} > ??????? #? sentintel image:? {} > ??????? #? moon_surface.tif: {'compression': 'raw', 'dpi': (1, 1)} > ??????? #? v....bmp??????? : {'compression': 0} > > sentinel image is an image created by the hardware that interfaces with the > software, and is 640x480 by 8-bits. v....bmp is one of the output files from > the h/w that I've saved as bmp.? Is there a description somewhere of what > the dictionary output contains? I guess it's sort of obvious, but do other > formats have more? > > -- > > Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time) > > > The Obama Administration plans to double the production > in solar energy from 1% to 2% of the total energy > supply in the next few years. One nuclear reaction > would do the same. Heard on Bill Wattenburg, KGO-AM > > "Less than all cannot satisfy Man." -- William Blake > > > _______________________________________________ > Image-SIG maillist ?- ?Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > -- Lucas Shrewsbury ---------------------------------------------------- Open Your Mind, Use Open Source From Chris.Barker at noaa.gov Mon Apr 6 05:39:46 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Sun, 05 Apr 2009 20:39:46 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image In-Reply-To: <49D75A96.4020805@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net> Message-ID: <49D97982.4090202@noaa.gov> Wayne Watson wrote: > I would like to create a transparent image with a circle > on it and a crosshair at the center of the circle, then place it on top > of the first (real) image (produced by the h/w). I have no trouble > drawing on the real image, but I'd like use this transparency idea here. > The reason is that eventually I'd like the user to drag around the > circle over the real image, I'm not sure what GUI toolkit you're using, but it probably makes sense to use the toolkits drawing routines for this kind of thing. I know it's pretty easy with wxPython -- look fro various articles in the Wiki by searching for "drawing". Also, under "images", I think you'll find info about interfacing between IL images and wx.Image. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From denilsonsa at gmail.com Mon Apr 6 06:13:29 2009 From: denilsonsa at gmail.com (=?utf-8?Q?Denilson_Figueiredo_de_S=C3=A1?=) Date: Mon, 06 Apr 2009 01:13:29 -0300 Subject: [Image-SIG] Support for semi-transparent in PNG palette Message-ID: Hello, I think I found a bug/limitation in PIL. If I have a PNG with palette, and with semi-transparent colors at that palette, then PIL will ignore the semi-transparent information. In other words, it will always load the palette as RGB, instead of RGBA. Let's reproduce the bug, step-by-step: 1. Create an RGBA image using Gimp. Or, even easier, download this one I created: http://denilsonsa.selfip.org/~denilson/pil/rgba.png 2. Convert that image to RGBA palette. What I've done was: cp pil_rgba.png pil_palette.png optipng -o7 pil_palette.png You can download optipng at http://optipng.sourceforge.net/ Or you can download the converted image here: http://denilsonsa.selfip.org/~denilson/pil/palette.png 3. Try opening it using PIL, convert back to RGBA, and save as PNG: from PIL import Image f = Image.open("pil_palette.png") print f.palette.mode # This will print RGB, but should be RGBA f = f.convert("RGBA") f.save("pil_saved.png") Or you can download it from here: http://denilsonsa.selfip.org/~denilson/pil/saved.png == What did I expect? == I expected that PIL would correctly load RGBA palette, and thus correctly preserve the semi-transparent information. I expected that the pil_saved.png file still looked the same as pil_rgba.png. == What actually happens? == PIL throws away the Alpha channel, and the final pil_rgba.png image has all semi-transparent pixels converted to opaque. == Extra information == The "feh" image viewer correctly supports RGBA palettes. Also, I think it is a better replacement for xv, for use in image.show() http://www.linuxbrit.co.uk/feh Both Firefox and Opera browsers correctly support RGBA palettes. Surprisingly, Gimp does not support RGBA palettes, and will convert semi-transparent colors to full transparency. == Similar messages == While searching, I found these messages about the same subject: 25 Jan 2009 - http://www.mail-archive.com/image-sig at python.org/msg02275.html 15 Nov 2008 - http://www.mail-archive.com/image-sig at python.org/msg02182.html 27 Aug 2008 - http://www.mail-archive.com/image-sig at python.org/msg02065.html 26 Jan 2005 - http://www.mail-archive.com/image-sig at python.org/msg00069.html I'm not subscribed to this mail list, so please add me to CC when replying to this message. Thanks. -- Denilson Figueiredo de S? Rio de Janeiro - Brasil From sierra_mtnview at sbcglobal.net Mon Apr 6 06:47:13 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sun, 05 Apr 2009 21:47:13 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image In-Reply-To: <49D97982.4090202@noaa.gov> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> Message-ID: <49D98951.6060900@sbcglobal.net> So far I've used Python with Tkinter, and a touch of PIL. I'm pretty bound by Tkinter, since I'm modifying a program that used it quite a bit for the GUI ability rather than analysis of images with IP (image processing). Christopher Barker wrote: > > > Wayne Watson wrote: >> I would like to create a transparent image with a circle on it and a >> crosshair at the center of the circle, then place it on top of the >> first (real) image (produced by the h/w). I have no trouble drawing >> on the real image, but I'd like use this transparency idea here. The >> reason is that eventually I'd like the user to drag around the circle >> over the real image, > > I'm not sure what GUI toolkit you're using, but it probably makes > sense to use the toolkits drawing routines for this kind of thing. > > I know it's pretty easy with wxPython -- look fro various articles in > the Wiki by searching for "drawing". Also, under "images", I think > you'll find info about interfacing between IL images and wx.Image. > > -Chris > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From spe.stani.be at gmail.com Mon Apr 6 16:19:30 2009 From: spe.stani.be at gmail.com (Stani) Date: Mon, 6 Apr 2009 16:19:30 +0200 Subject: [Image-SIG] text along a curve? In-Reply-To: References: Message-ID: <2078a7ad0904060719x2b44b9a7r5da8d07581ba00a4@mail.gmail.com> AFAIK Pil does not provide this out of the box. You'll need the x,y equation of this curve to calculate the rotation and displacement. I would generate small images of each character individually, which can than be rotated and displaced according to the curve. On Sat, Apr 4, 2009 at 7:16 PM, Alec Bennett wrote: > I'm wondering if its possible to do text along a curve in PIL? > > Or if anyone can think of another way, short of Photoshop? > > Thanks for the help. > _______________________________________________ > Image-SIG maillist ?- ?Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -- Phatch Photo Batch Processor - http://photobatch.stani.be SPE Python IDE - http://pythonide.stani.be From howard at eegsoftware.com Mon Apr 6 18:42:04 2009 From: howard at eegsoftware.com (Howard Lightstone) Date: Mon, 06 Apr 2009 09:42:04 -0700 Subject: [Image-SIG] text along a curve? In-Reply-To: References: Message-ID: <49D9CE6C.9170.16D21A4E@howard.eegsoftware.com> ImageMagick can do this quite well - and scriptable from Python, too. Look at http://www.imagemagick.org/Usage/fonts/ From sierra_mtnview at sbcglobal.net Tue Apr 7 02:35:17 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Mon, 06 Apr 2009 17:35:17 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image In-Reply-To: <49D98951.6060900@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> Message-ID: <49DA9FC5.5040605@sbcglobal.net> Consider this program that I pulled off the web and was posted in 1999. It purports to illustrate how one might produce a transparency. #!/usr/bin/python # see http://mail.python.org/pipermail/python-list/1999-May/003388.html from Tkinter import * import Image, ImageTk import tkFileDialog class Transparency: def __init__(self, parent): self.canvas = Canvas(parent, bg='green') self.canvas.pack() b = Button(parent, command=self.open, text="Select graphics file") b.pack() def open(self): self.canvas.delete(ALL) filename = tkFileDialog.askopenfilename() if filename != '': im = Image.open(filename) if im.mode != "RGBA": im = Image.open(filename).convert("RGBA") source = im.split() R, G, B, A = 0, 1, 2, 3 mask = im.point(lambda i: i > 0 and 255) # use black as transparent source[A].paste(mask) im = Image.merge(im.mode, source) # build a new multiband image self.graphic = ImageTk.PhotoImage(image=im) self.canvas.create_image(100, 100, image=self.graphic) if __name__ == "__main__": root = Tk() test = Transparency(root) root.mainloop() It colors the canvas green, and produces a black background. An image is merged with the background. I tried out the program. It executes, but I do not see where the transparency is apparent. I used a gif with a picture of a telescope on a white background, and the result is what I would see if I pasted the telescope and white background onto the green canvas. If there's something missing in my observation, I'd like to know what it is. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From Chris.Barker at noaa.gov Tue Apr 7 04:52:51 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Mon, 06 Apr 2009 19:52:51 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image In-Reply-To: <49D98951.6060900@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> Message-ID: <49DAC003.9060102@noaa.gov> Wayne Watson wrote: > So far I've used Python with Tkinter, and a touch of PIL. I'm pretty > bound by Tkinter, since I'm modifying a program that used it quite a bit > for the GUI ability rather than analysis of images with IP (image > processing). OK, then dig around in the Tk docs and examples you can find. In any case, what I'm suggesting is that you don't need any fancy transparency in PIL -- you simply draw your image onto the screen (probaly add it to the Tk Canvas), then you draw your circle with the cross-hair on top of it, using Tk -- you aren't changing your image, so you can get it back by re-drawing it, or just removing the cross hair. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From sierra_mtnview at sbcglobal.net Tue Apr 7 05:50:47 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Mon, 06 Apr 2009 20:50:47 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DAC003.9060102@noaa.gov> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> <49DAC003.9060102@noaa.gov> Message-ID: <49DACD97.7060506@sbcglobal.net> (I see I missed shifting my post to text, so it is hung up with the moderator. This is in text format.) Digging around hasn't been very successful; however, with your suggestion above to look for images and drawing in Wiki-land may pay off. Drawing on top of an image doesn't seem like it's going to help much if I want the user to move the circle-crosshair with his mouse. In some ways this is kind of standard stuff found in programs like PaintShopPro, and PhotoShop. The ideas are the same as PIL in that layers correspond to a PIL modes, and bands are sub-layers that contain R,B,G, A. In PSP, one piles a transparency on top of another layer. In PIL land it seems like, according to the example, one pastes into the layer. Somehow I doubt that's the way it works. I would think they get stacked on top of one another, so they could slide easily if required by a mouse. It could go either way depending on use. Something that may be instructive on these needs is Grayson's book on Tkinter, which has a few chapters on the web. He provides all the examples, and one chapter of his book is a drawing program that uses rubberband effects, and moving objects on the canvas--maybe even IP work. I think I will shortly fire up the drawing program, after I locate the Pmw toolkit, which he likes to use. As for xpPython, I know little about it. I'm working with a 2000+ line program written by someone else that uses Tkinter. I'm adding new features to it, and not so sure it's wise to go off onto some other form of Python or toolkits without understanding what I've really got. I had not used Tkinter until 2 months ago, when I began this effort, and only have about 3 months of Python experience. However, I have plenty of programming experience in days of yore. A few weeks ago I bought Core Python and the author has a few pages on it, but doesn't make much of a case for it. He says though, "The best part of all is that wxWidgets use the native GUI on each platform, so your program will have the same loo-and-feel as the other applications on your desktop." That doesn't send me running for wxPython. Christopher Barker wrote: > Wayne Watson wrote: >> So far I've used Python with Tkinter, and a touch of PIL. I'm pretty >> bound by Tkinter, since I'm modifying a program that used it quite a >> bit for the GUI ability rather than analysis of images with IP (image >> processing). > > OK, then dig around in the Tk docs and examples you can find. > > In any case, what I'm suggesting is that you don't need any fancy > transparency in PIL -- you simply draw your image onto the screen > (probaly add it to the Tk Canvas), then you draw your circle with the > cross-hair on top of it, using Tk -- you aren't changing your image, > so you can get it back by re-drawing it, or just removing the cross hair. > > -Chris > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From sierra_mtnview at sbcglobal.net Tue Apr 7 13:12:38 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Tue, 07 Apr 2009 04:12:38 -0700 Subject: [Image-SIG] [AstroPy] numarray pdf 1.5 is broken. Using numdisplay, Python, PIL, and Tkinter (txt version) In-Reply-To: References: <49D98CD4.3090508@sbcglobal.net> <49D9BC1C.4040805@lpta.in2p3.fr> <49D9F65D.9010804@sbcglobal.net> <49DA0952.8070709@stsci.edu> <49DA16B4.6080002@sbcglobal.net> <49DA1AE3.5080902@stsci.edu> <49DA4E15.4080109@lpta.in2p3.fr> <49DB1D0B.3000806@sbcglobal.net> Message-ID: <49DB3526.2070607@sbcglobal.net> The simple answer is too many Python irons in the fire right now. PIL, Tkinter, and some Python apps. When I get stuck on one area, I wait for a solution, and move to another topic. I've just rotated back to FITS ( and the Pmw toolkit). I'll try DS9 out of curiosity, but I do like do some ground work first. I'm also trying not to take some mis-steps here. It's all to easy for people to misunderstand matters, and go off in unintended directions. Another reason to dive right in is that the app I'm working on works among its users pretty well, but they may not be receptive to changes I'm working (to a program I didn't write) if they have to do too many extras. For example, I do not want to complicate the install process for them. Virtually none of them is familiar with fits, although they certainly profit it by it. As another example, I wrote some simple utilities a few months ago, but no one picked up on them, since they required Python 2.5. They are stuck on version Pyton 2. 5 of the program. The sponsor even added new features to the app, but in 2.5, so there's reluctance even there. When I finish my additions to the app, I think people will clearly see it has features they need. It'll be in 2.5. I actually heard of DS9 about 3 weeks ago when my ccdsoft (Bisque product) that deals with fits as its normal format died. I needed to look at some files in fits, and someone recommended DS9. I think there's a web interactive version of it. I finally wrestled ccdsoft back into operability, and found a simpler way to deal with a fits file in the interim. I have lots of balls in the air. Cheers. Stefan Schwarzburg wrote: > > > On Tue, Apr 7, 2009 at 11:29, Wayne Watson > > > wrote: > > Thanks, but I'm not sure why people keep bringing up DS9. As I > understand it, it is a stand alone program of sorts that has no > interface with Python. It seems to me it would be like saying use > Word or Adobe Photoshop. > > > DS9 is a external program with a python interface. From the user / > programmer point of view you can not distinguish between a python ds9 > interface that has the "imshow" command and a pure python modeule that > has the "imshow" command. You can also (from that point of view) not > distinguish between a pure python module and one that is a wrapper for > a c library or something like this. > If you don't have stronger requirements, like for example a custom > python virtual machiene that can not run external programs, then I > don't see why you should care if this is an interface to a program or > if it is a interface to a module. > > By the way: have you tried it? Is there some reason why you don't like > this kind of solution? > > Cheers, > Stefan > > > > Stefan Schwarzburg wrote: >> >> >> On Mon, Apr 6, 2009 at 20:46, Cohen-Tanugi Johann >> > wrote: >> >> the main thing missing when using matplotlib is the correct >> use of >> astronomical coordinate information, and that is a pretty big >> plus of ds9. >> J >> >> >> I'm not sure if I posted this reply already to this thread, or if >> it was the same topic on a different thread: >> >> You can also try pysao to comminicate with ds9, the interface is >> nicer (although the implementation might not, I don't know). >> http://code.google.com/p/python-sao/ >> >>> import pysao >> >> # run new instance of ds9 >> >>> ds9 = pysao.ds9() >> >> >>> import pyfits >> >>> f = pyfits.open('test.fits') >> >> # display first extension of fits file >> >>> ds9.view(f[0]) >> >> >> >> Note also, that there is the kapteyn package which uses >> matplotlib (pylab) to display the data from fits files according >> to the wcs (World Coordinate System) contained in most fits files >> in the correct way. http://www.astro.rug.nl/software/kapteyn/ >> >> Cheers, >> Stefan >> >> >> >> >> Phil Hodge wrote: >> >> The question is whether ds9 is a module that can be used >> within a Python >> >> program? I really do not know, but indications are that it >> is not. >> >> >> > >> > >> > ds9 is not a Python module, it's a stand-alone program that >> you run from >> > Unix. However, there is an interface for displaying images >> to it, and >> > the Python module numdisplay uses that interface. The >> advantage of ds9 >> > is that it is so powerful. imshow in matplotlib is pretty >> good, though, >> > and you may want to use matplotlib anyway for plotting. >> > >> > Phil >> > >> > _______________________________________________ >> > AstroPy mailing list >> > AstroPy at scipy.org >> > http://mail.scipy.org/mailman/listinfo/astropy >> > >> _______________________________________________ >> AstroPy mailing list >> AstroPy at scipy.org >> http://mail.scipy.org/mailman/listinfo/astropy >> >> >> >> >> -- >> Institut f?r Astronomie und Astrophysik >> Eberhard Karls Universit?t T?bingen >> Sand 1 - D-72076 T?bingen >> schwarz at astro.uni-tuebingen.de >> >> stefan.schwarzburg at googlemail.com >> >> >> Tel.: 07071/29-78605 >> ----------------------------------------------------------------------- >> ------------------------------------------------------------------------ >> _______________________________________________ AstroPy mailing >> list AstroPy at scipy.org >> http://mail.scipy.org/mailman/listinfo/astropy > > -- > > Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** > > "Less than all cannot satisfy Man." -- William Blake > > > > > > -- > Institut f?r Astronomie und Astrophysik > Eberhard Karls Universit?t T?bingen > Sand 1 - D-72076 T?bingen > schwarz at astro.uni-tuebingen.de > stefan.schwarzburg at googlemail.com > > > Tel.: 07071/29-78605 > ----------------------------------------------------------------------- -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From sierra_mtnview at sbcglobal.net Tue Apr 7 05:43:18 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Mon, 06 Apr 2009 20:43:18 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image In-Reply-To: <49DAC003.9060102@noaa.gov> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> <49DAC003.9060102@noaa.gov> Message-ID: <49DACBD6.6050106@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Tue Apr 7 13:01:18 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Tue, 07 Apr 2009 04:01:18 -0700 Subject: [Image-SIG] [AstroPy] numarray pdf 1.5 is broken. Using numdisplay, Python, PIL, and Tkinter In-Reply-To: References: <49D98CD4.3090508@sbcglobal.net> <49D9BC1C.4040805@lpta.in2p3.fr> <49D9F65D.9010804@sbcglobal.net> <49DA0952.8070709@stsci.edu> <49DA16B4.6080002@sbcglobal.net> <49DA1AE3.5080902@stsci.edu> <49DA4E15.4080109@lpta.in2p3.fr> <49DB1D0B.3000806@sbcglobal.net> Message-ID: <49DB327E.5020906@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Tue Apr 7 16:00:18 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Tue, 07 Apr 2009 07:00:18 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image In-Reply-To: <49DA9FC5.5040605@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> <49DA9FC5.5040605@sbcglobal.net> Message-ID: <49DB5C72.8030906@sbcglobal.net> BTW, the solution here is: mask = im.point(lambda i: 255 if i >= 255 else 0) Wayne Watson wrote: > Consider this program that I pulled off the web and was posted in 1999. > It purports to illustrate how one might produce a transparency. > > #!/usr/bin/python > # see > http://mail.python.org/pipermail/python-list/1999-May/003388.html > from Tkinter import * > import Image, ImageTk > import tkFileDialog > > class Transparency: > def __init__(self, parent): > self.canvas = Canvas(parent, bg='green') > self.canvas.pack() > b = Button(parent, command=self.open, text="Select graphics file") > b.pack() > > def open(self): > self.canvas.delete(ALL) > filename = tkFileDialog.askopenfilename() > if filename != '': > im = Image.open(filename) > if im.mode != "RGBA": > im = Image.open(filename).convert("RGBA") > source = im.split() > R, G, B, A = 0, 1, 2, 3 > mask = im.point(lambda i: i > 0 and 255) # use black as > transparent > source[A].paste(mask) > im = Image.merge(im.mode, source) # build a new multiband image > > self.graphic = ImageTk.PhotoImage(image=im) > self.canvas.create_image(100, 100, image=self.graphic) > if __name__ == "__main__": > root = Tk() > test = Transparency(root) > root.mainloop() > > It colors the canvas green, and produces a black background. An image is > merged with the background. I tried out the program. It executes, but I > do not see where the transparency is apparent. I used a gif with a > picture of a telescope on a white background, and the result is what I > would see if I pasted the telescope and white background onto the green > canvas. > > If there's something missing in my observation, I'd like to know what > it is. > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From Chris.Barker at noaa.gov Tue Apr 7 16:04:05 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Tue, 07 Apr 2009 07:04:05 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DACD97.7060506@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> <49DAC003.9060102@noaa.gov> <49DACD97.7060506@sbcglobal.net> Message-ID: <49DB5D55.1090101@noaa.gov> Wayne Watson wrote: > Drawing on top of an image doesn't seem like it's going to help much if > I want the user to move the circle-crosshair with his mouse. I think we need a little more detail about what you need here: Is the cross-hair there for the user to indicate the location of something while using the program, or do you want to be able to save it out as part of a final product image? In either case, actually, you do have two choices: it could be a transparent image, or it could be created by "vector" drawing functions, something like one DrawCircle and two DrawLine calls. (what exactly they will be depends on the toolkit) >and PhotoShop. The ideas are the same as PIL in that layers correspond > to a PIL modes, and bands are sub-layers that contain R,B,G, A. In PSP, > one piles a transparency on top of another layer. In PIL land it seems > like, according to the example, one pastes into the layer. I don't think that PIL has the concept of layers, but rather individual images -- you'll have to manage them as layers yourself. But yes, paste() is the method to draw one image on top of another. It also may or may not make sense to use your GUI toolkit drawing capabilities, rather than PIL, to composite the layers. I probably would with wx -- I don't know about TK. > Something that may be instructive on these needs is Grayson's book on > Tkinter, which has a few chapters on the web. He provides all the > examples, and one chapter of his book is a drawing program that uses > rubberband effects, and moving objects on the canvas-- And that's all using the TK Canvas features -- I think. I was thinking that your cross hairs are more analogous to a "rubber band" box. > As for xpPython, I know little about it. I'm working with a 2000+ line > program written by someone else that uses Tkinter. I'm adding new > features to it, and not so sure it's wise to go off onto some other > form of Python or toolkits without understanding what I've really got. TK is quite capable, I mentioned wx, 'cause I know it well -- you can google around to get a sense of the strengths of the toolkits, if you are considering a change, but I don't imagine you can't use TK for this. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From sierra_mtnview at sbcglobal.net Tue Apr 7 16:32:23 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Tue, 07 Apr 2009 07:32:23 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DB5D55.1090101@noaa.gov> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> <49DAC003.9060102@noaa.gov> <49DACD97.7060506@sbcglobal.net> <49DB5D55.1090101@noaa.gov> Message-ID: <49DB63F7.6080809@sbcglobal.net> Christopher Barker wrote: > Wayne Watson wrote: >> Drawing on top of an image doesn't seem like it's going to help much >> if I want the user to move the circle-crosshair with his mouse. > > I think we need a little more detail about what you need here: > > Is the cross-hair there for the user to indicate the location of > something while using the program, or do you want to be able to save > it out as part of a final product image? Exactly the former. Once the user is happy, then clicking the mouse should indicate the x,y pixels he needs for a computation. > > In either case, actually, you do have two choices: it could be a > transparent image, or it could be created by "vector" drawing > functions, something like one DrawCircle and two DrawLine calls. (what > exactly they will be depends on the toolkit) Tkinter is all I will consider presently. > > >and PhotoShop. The ideas are the same as PIL in that layers correspond >> to a PIL modes, and bands are sub-layers that contain R,B,G, A. In >> PSP, one piles a transparency on top of another layer. In PIL land it >> seems like, according to the example, one pastes into the layer. > > I don't think that PIL has the concept of layers, but rather > individual images -- you'll have to manage them as layers Yes, PIL does not use the term layer, unfortunately. BTW, look at my post higher up in the thread. A simple change in the web example program produced a transparency as one might expect. > yourself. But yes, paste() is the method to draw one image on top of > another. It also may or may not make sense to use your GUI toolkit > drawing capabilities, rather than PIL, to composite the layers. I > probably would with wx -- I don't know about TK. > > >> Something that may be instructive on these needs is Grayson's book on >> Tkinter, which has a few chapters on the web. He provides all the >> examples, and one chapter of his book is a drawing program that uses >> rubberband effects, and moving objects on the canvas-- The download of Pmw left me the lurch for now. There's a part of the install process that is not explained for Win. I sent the host (a person) a msg. Although, I've heard on another list that Pmw is nearly dead it doesn't look that way to me. The posts and updates there look quite current. > > And that's all using the TK Canvas features -- I think. I was thinking > that your cross hairs are more analogous to a "rubber band" box. > >> As for xpPython, I know little about it. I'm working with a 2000+ >> line program written by someone else that uses Tkinter. I'm adding >> new features to it, and not so sure it's wise to go off onto some >> other form of Python or toolkits without understanding what I've >> really got. > > TK is quite capable, I mentioned wx, 'cause I know it well -- you can > google around to get a sense of the strengths of the toolkits, if you > are considering a change, but I don't imagine you can't use TK for this. Maybe Tk is not usable here, but I'd like to know definitely one way or the other. Canvas has create items like polygons, and arcs. I see that each has a transparency of some sort. It's not obvious what that's about. > > -Chris > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From sierra_mtnview at sbcglobal.net Tue Apr 7 16:40:08 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Tue, 07 Apr 2009 07:40:08 -0700 Subject: [Image-SIG] [AstroPy] numarray pdf 1.5 is broken. (Ignore it) In-Reply-To: <49DB3526.2070607@sbcglobal.net> References: <49D98CD4.3090508@sbcglobal.net> <49D9BC1C.4040805@lpta.in2p3.fr> <49D9F65D.9010804@sbcglobal.net> <49DA0952.8070709@stsci.edu> <49DA16B4.6080002@sbcglobal.net> <49DA1AE3.5080902@stsci.edu> <49DA4E15.4080109@lpta.in2p3.fr> <49DB1D0B.3000806@sbcglobal.net> <49DB3526.2070607@sbcglobal.net> Message-ID: <49DB65C8.4050301@sbcglobal.net> Ignore this post. It was meant for another list. I'm in too many mail lists with formats and response ideas that differ. Reply All (single sender and list). vs Reply. Reply All (all who have contributed! Gads.) vs Reply. Text or html, or either. A real challenge. Get the wrong method, and you get to do it again or wait for the moderator to free your post). -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From sierra_mtnview at sbcglobal.net Tue Apr 7 20:25:48 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Tue, 07 Apr 2009 11:25:48 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image In-Reply-To: References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> <49DA9FC5.5040605@sbcglobal.net> <49DB5C72.8030906@sbcglobal.net> Message-ID: <49DB9AAC.8040508@sbcglobal.net> Are you doing this purely with PIL or some toolkit? I would use a callback that each time the mouse moves you move the image. What about rubber lines, stretching, for an to resize an object like a box? Laura & Edward Cannon wrote: > I have had great success "moving" items across images by keeping a > copy of the original background, pasting into a copy, and updating the > copy as needed. This may not be perfectly elegant, but it works well > and is quite fast on modern hardware. > ERC > > On Tue, Apr 7, 2009 at 7:00 AM, Wayne Watson > wrote: > > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From cannon.el at gmail.com Tue Apr 7 21:10:50 2009 From: cannon.el at gmail.com (Laura & Edward Cannon) Date: Tue, 7 Apr 2009 12:10:50 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image In-Reply-To: <49DB9AAC.8040508@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net> <49D97982.4090202@noaa.gov> <49D98951.6060900@sbcglobal.net> <49DA9FC5.5040605@sbcglobal.net> <49DB5C72.8030906@sbcglobal.net> <49DB9AAC.8040508@sbcglobal.net> Message-ID: I do this using a callback from Tkinter, (and do the calculations in PIL) but you could get the callbacks from any windowing system you cared to use. On Tue, Apr 7, 2009 at 11:25 AM, Wayne Watson wrote: > Are you doing this purely with PIL or some toolkit? I would use a callback > that each time the mouse moves you move the image. > > What about rubber lines, stretching, for an to resize an object like a box? > > Laura & Edward Cannon wrote: >> >> I have had great success "moving" items across images by keeping a >> copy of the original background, pasting into a copy, and updating the >> copy as needed. This may not be perfectly elegant, but it works well >> and is quite fast on modern hardware. >> ERC >> >> On Tue, Apr 7, 2009 at 7:00 AM, Wayne Watson >> wrote: >> > > -- > > ? ? ? ? ?Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > ? ? ? ? ? ?(121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** > > ? ? ? ? "Less than all cannot satisfy Man." -- William Blake > > From howard at eegsoftware.com Tue Apr 7 21:49:05 2009 From: howard at eegsoftware.com (Howard Lightstone) Date: Tue, 07 Apr 2009 12:49:05 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DB5D55.1090101@noaa.gov> References: <49D75A96.4020805@sbcglobal.net>, <49DACD97.7060506@sbcglobal.net>, <49DB5D55.1090101@noaa.gov> Message-ID: <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> Here is a *dumb* example of what I think you want. It can be elaborated with crosshairs, ring sizing, etc. import PIL import Image import ImageTk class data: startx=0 starty=0 def startmotioncallback(event): data.startx=event.x data.starty=event.y def motioncallback(event): deltax=event.x-data.startx deltay=event.y-data.starty data.startx=event.x data.starty=event.y # should put some limits on where the cirle is moved # left as exercise..... data.cnv.move(data.ring,deltax,deltay) def Demo(root): # resize window root.geometry('400x400+0+0') data.root=root # make a canvas cnv=Canvas(root) cnv.pack(expand=1,fill=BOTH) data.cnv=cnv img=Image.open('white dragon.png') # some image you have..... data.img=ImageTk.PhotoImage(img) data.photo=cnv.create_image(0,0,image=data.img,anchor='nw') data.ring=cnv.create_oval((100,100,300,300)) cnv.bind("",motioncallback) cnv.bind("",startmotioncallback) root.mainloop() if __name__ == '__main__': root=Tk() Demo(root) From sierra_mtnview at sbcglobal.net Wed Apr 8 07:21:36 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Tue, 07 Apr 2009 22:21:36 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> References: <49D75A96.4020805@sbcglobal.net>, <49DACD97.7060506@sbcglobal.net>, <49DB5D55.1090101@noaa.gov> <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> Message-ID: <49DC3460.6080208@sbcglobal.net> This looks good, but there's a slight problem. It looks right, but I get this when I try to run it: Traceback (most recent call last): File "C:/Sandia_Meteors/Sentinel_Development/Development_Sentuser-Utilities/Playground/fun-move_object.py", line 42, in root=Tk() NameError: name 'Tk' is not defined Howard Lightstone wrote: > Here is a *dumb* example of what I think you want. It can be elaborated with > crosshairs, ring sizing, etc. > > import PIL > import Image > import ImageTk > > class data: > startx=0 > starty=0 > > def startmotioncallback(event): > data.startx=event.x > data.starty=event.y > > > def motioncallback(event): > deltax=event.x-data.startx > deltay=event.y-data.starty > data.startx=event.x > data.starty=event.y > # should put some limits on where the cirle is moved > # left as exercise..... > data.cnv.move(data.ring,deltax,deltay) > > def Demo(root): > # resize window > root.geometry('400x400+0+0') > data.root=root > # make a canvas > cnv=Canvas(root) > cnv.pack(expand=1,fill=BOTH) > data.cnv=cnv > img=Image.open('white dragon.png') # some image you have..... > data.img=ImageTk.PhotoImage(img) > data.photo=cnv.create_image(0,0,image=data.img,anchor='nw') > data.ring=cnv.create_oval((100,100,300,300)) > cnv.bind("",motioncallback) > cnv.bind("",startmotioncallback) > root.mainloop() > > > if __name__ == '__main__': > > root=Tk() > Demo(root) > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From cannon.el at gmail.com Wed Apr 8 17:55:15 2009 From: cannon.el at gmail.com (Edward Cannon) Date: Wed, 8 Apr 2009 08:55:15 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DC3460.6080208@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net>, <49DACD97.7060506@sbcglobal.net>, <49DB5D55.1090101@noaa.gov> <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> <49DC3460.6080208@sbcglobal.net> Message-ID: Add the line from Tkinter import On Apr 7, 2009, at 10:21 PM, Wayne Watson wrote: > This looks good, but there's a slight problem. It looks right, but I > get this when I try to run it: > Traceback (most recent call last): > File "C:/Sandia_Meteors/Sentinel_Development/Development_Sentuser- > Utilities/Playground/fun-move_object.py", line 42, in > root=Tk() > NameError: name 'Tk' is not defined > > Howard Lightstone wrote: >> Here is a *dumb* example of what I think you want. It can be >> elaborated with crosshairs, ring sizing, etc. >> >> import PIL >> import Image >> import ImageTk >> >> class data: >> startx=0 >> starty=0 >> >> def startmotioncallback(event): >> data.startx=event.x >> data.starty=event.y >> >> def motioncallback(event): >> deltax=event.x-data.startx >> deltay=event.y-data.starty >> data.startx=event.x >> data.starty=event.y >> # should put some limits on where the cirle is moved >> # left as exercise..... >> data.cnv.move(data.ring,deltax,deltay) >> def Demo(root): >> # resize window >> root.geometry('400x400+0+0') >> data.root=root >> # make a canvas >> cnv=Canvas(root) >> cnv.pack(expand=1,fill=BOTH) >> data.cnv=cnv >> img=Image.open('white dragon.png') # some image you have..... >> data.img=ImageTk.PhotoImage(img) >> data.photo=cnv.create_image(0,0,image=data.img,anchor='nw') >> data.ring=cnv.create_oval((100,100,300,300)) >> cnv.bind("",motioncallback) >> cnv.bind("",startmotioncallback) >> root.mainloop() >> >> if __name__ == '__main__': >> >> root=Tk() >> Demo(root) >> _______________________________________________ >> Image-SIG maillist - Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig >> >> > > -- > > Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** > > "Less than all cannot satisfy Man." -- William Blake > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From fredrik at pythonware.com Wed Apr 8 21:21:01 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 8 Apr 2009 21:21:01 +0200 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: References: <49D75A96.4020805@sbcglobal.net> <49DACD97.7060506@sbcglobal.net> <49DB5D55.1090101@noaa.gov> <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> <49DC3460.6080208@sbcglobal.net> Message-ID: <368a5cd50904081221q2eb61a55wa600b9aeb08e9715@mail.gmail.com> On Wed, Apr 8, 2009 at 5:55 PM, Edward Cannon wrote: > Add the line > from Tkinter import Lost an asterisk there, I think: from Tkinter import * > > > > On Apr 7, 2009, at 10:21 PM, Wayne Watson > wrote: > >> This looks good, but there's a slight problem. It looks right, but I get >> this when I try to run it: >> Traceback (most recent call last): >> File >> "C:/Sandia_Meteors/Sentinel_Development/Development_Sentuser-Utilities/Playground/fun-move_object.py", >> line 42, in >> ?root=Tk() >> NameError: name 'Tk' is not defined >> >> Howard Lightstone wrote: >>> >>> Here is a *dumb* example of what I think you want. ?It can be elaborated >>> with crosshairs, ring sizing, etc. >>> >>> import PIL >>> import Image >>> import ImageTk >>> >>> class data: >>> ? startx=0 >>> ? starty=0 >>> >>> def startmotioncallback(event): >>> ? data.startx=event.x >>> ? data.starty=event.y >>> >>> ? def motioncallback(event): >>> ? deltax=event.x-data.startx >>> ? deltay=event.y-data.starty >>> ? data.startx=event.x >>> ? data.starty=event.y >>> ? # should put some limits on where the cirle is moved >>> ? # left as exercise..... >>> ? data.cnv.move(data.ring,deltax,deltay) >>> ? def Demo(root): >>> ? # resize window >>> ? root.geometry('400x400+0+0') >>> ? data.root=root >>> ? # make a canvas >>> ? cnv=Canvas(root) >>> ? cnv.pack(expand=1,fill=BOTH) >>> ? data.cnv=cnv >>> ? img=Image.open('white dragon.png') ?# some image you have..... >>> ? data.img=ImageTk.PhotoImage(img) >>> ? data.photo=cnv.create_image(0,0,image=data.img,anchor='nw') >>> ? data.ring=cnv.create_oval((100,100,300,300)) >>> ? cnv.bind("",motioncallback) >>> ? cnv.bind("",startmotioncallback) >>> ? root.mainloop() >>> >>> if __name__ == '__main__': >>> >>> ? root=Tk() >>> ? Demo(root) >>> _______________________________________________ >>> Image-SIG maillist ?- ?Image-SIG at python.org >>> http://mail.python.org/mailman/listinfo/image-sig >>> >>> >> >> -- >> >> ? ? ? ? Wayne Watson (Watson Adventures, Prop., Nevada City, CA) >> >> ? ? ? ? ? (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** >> >> ? ? ? ?"Less than all cannot satisfy Man." -- William Blake >> >> >> _______________________________________________ >> Image-SIG maillist ?- ?Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig > > _______________________________________________ > Image-SIG maillist ?- ?Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From sierra_mtnview at sbcglobal.net Wed Apr 8 22:21:05 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Wed, 08 Apr 2009 13:21:05 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <368a5cd50904081221q2eb61a55wa600b9aeb08e9715@mail.gmail.com> References: <49D75A96.4020805@sbcglobal.net> <49DACD97.7060506@sbcglobal.net> <49DB5D55.1090101@noaa.gov> <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> <49DC3460.6080208@sbcglobal.net> <368a5cd50904081221q2eb61a55wa600b9aeb08e9715@mail.gmail.com> Message-ID: <49DD0731.3030609@sbcglobal.net> Still a problem. import PIL import Image from Tkinter import * ... cnv.pack(expand=1,fill=BOTH) data.cnv=cnv img=Image.open('jupa9810.jpg') # some image you have..... data.img=ImageTk.PhotoImage(img) produces: Traceback (most recent call last): File "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py", line 44, in Demo(root) File "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py", line 33, in Demo img=Image.open('jupa9810.jpg') # some image you have..... AttributeError: class Image has no attribute 'open' Fredrik Lundh wrote: > On Wed, Apr 8, 2009 at 5:55 PM, Edward Cannon wrote: > >> Add the line >> from Tkinter import >> > > Lost an asterisk there, I think: > > from Tkinter import * > > > > >> >> On Apr 7, 2009, at 10:21 PM, Wayne Watson >> wrote: >> >> >>> This looks good, but there's a slight problem. It looks right, but I get >>> this when I try to run it: >>> Traceback (most recent call last): >>> File >>> "C:/Sandia_Meteors/Sentinel_Development/Development_Sentuser-Utilities/Playground/fun-move_object.py", >>> line 42, in >>> root=Tk() >>> NameError: name 'Tk' is not defined >>> >>> Howard Lightstone wrote: >>> >>>> Here is a *dumb* example of what I think you want. It can be elaborated >>>> with crosshairs, ring sizing, etc. >>>> >>>> import PIL >>>> import Image >>>> import ImageTk >>>> >>>> class data: >>>> startx=0 >>>> starty=0 >>>> >>>> def startmotioncallback(event): >>>> data.startx=event.x >>>> data.starty=event.y >>>> >>>> def motioncallback(event): >>>> deltax=event.x-data.startx >>>> deltay=event.y-data.starty >>>> data.startx=event.x >>>> data.starty=event.y >>>> # should put some limits on where the cirle is moved >>>> # left as exercise..... >>>> data.cnv.move(data.ring,deltax,deltay) >>>> def Demo(root): >>>> # resize window >>>> root.geometry('400x400+0+0') >>>> data.root=root >>>> # make a canvas >>>> cnv=Canvas(root) >>>> cnv.pack(expand=1,fill=BOTH) >>>> data.cnv=cnv >>>> img=Image.open('white dragon.png') # some image you have..... >>>> data.img=ImageTk.PhotoImage(img) >>>> data.photo=cnv.create_image(0,0,image=data.img,anchor='nw') >>>> data.ring=cnv.create_oval((100,100,300,300)) >>>> cnv.bind("",motioncallback) >>>> cnv.bind("",startmotioncallback) >>>> root.mainloop() >>>> >>>> if __name__ == '__main__': >>>> >>>> root=Tk() >>>> Demo(root) >>>> _______________________________________________ >>>> Image-SIG maillist - Image-SIG at python.org >>>> http://mail.python.org/mailman/listinfo/image-sig >>>> >>>> >>>> >>> -- >>> >>> Wayne Watson (Watson Adventures, Prop., Nevada City, CA) >>> >>> (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** >>> >>> "Less than all cannot satisfy Man." -- William Blake >>> >>> >>> _______________________________________________ >>> Image-SIG maillist - Image-SIG at python.org >>> http://mail.python.org/mailman/listinfo/image-sig >>> >> _______________________________________________ >> Image-SIG maillist - Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig >> >> > > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "Less than all cannot satisfy Man." -- William Blake From fredrik at pythonware.com Wed Apr 8 22:37:12 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 8 Apr 2009 22:37:12 +0200 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DD0731.3030609@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net> <49DACD97.7060506@sbcglobal.net> <49DB5D55.1090101@noaa.gov> <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> <49DC3460.6080208@sbcglobal.net> <368a5cd50904081221q2eb61a55wa600b9aeb08e9715@mail.gmail.com> <49DD0731.3030609@sbcglobal.net> Message-ID: <368a5cd50904081337y6b6889b6s13074faa8ba8326d@mail.gmail.com> The Tkinter module contains a "Image" class, so doing the "import *" thing after all other imports will stomp out the Import module. Either fix all uses of PIL to use fully qualified names (replace "import Image" with "import PIL.Image", "Image.open" with "PIL.Image.open" etc), or, easier, move the "from Tkinter import *" line to the top of the imports. On Wed, Apr 8, 2009 at 10:21 PM, Wayne Watson wrote: > Still a problem. > > import PIL > import Image > from Tkinter import * > ... > ? cnv.pack(expand=1,fill=BOTH) > ? data.cnv=cnv > ? img=Image.open('jupa9810.jpg') ?# some image you have..... > ? data.img=ImageTk.PhotoImage(img) > > produces: > Traceback (most recent call last): > ?File > "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py", > line 44, in > ? Demo(root) > ?File > "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py", > line 33, in Demo > ? img=Image.open('jupa9810.jpg') ?# some image you have..... > AttributeError: class Image has no attribute 'open' > > > Fredrik Lundh wrote: >> >> On Wed, Apr 8, 2009 at 5:55 PM, Edward Cannon wrote: >> >>> >>> Add the line >>> from Tkinter import >>> >> >> Lost an asterisk there, I think: >> >> ? from Tkinter import * >> >> >> >> >>> >>> On Apr 7, 2009, at 10:21 PM, Wayne Watson >>> wrote: >>> >>> >>>> >>>> This looks good, but there's a slight problem. It looks right, but I get >>>> this when I try to run it: >>>> Traceback (most recent call last): >>>> File >>>> >>>> "C:/Sandia_Meteors/Sentinel_Development/Development_Sentuser-Utilities/Playground/fun-move_object.py", >>>> line 42, in >>>> ?root=Tk() >>>> NameError: name 'Tk' is not defined >>>> >>>> Howard Lightstone wrote: >>>> >>>>> >>>>> Here is a *dumb* example of what I think you want. ?It can be >>>>> elaborated >>>>> with crosshairs, ring sizing, etc. >>>>> >>>>> import PIL >>>>> import Image >>>>> import ImageTk >>>>> >>>>> class data: >>>>> ?startx=0 >>>>> ?starty=0 >>>>> >>>>> def startmotioncallback(event): >>>>> ?data.startx=event.x >>>>> ?data.starty=event.y >>>>> >>>>> ?def motioncallback(event): >>>>> ?deltax=event.x-data.startx >>>>> ?deltay=event.y-data.starty >>>>> ?data.startx=event.x >>>>> ?data.starty=event.y >>>>> ?# should put some limits on where the cirle is moved >>>>> ?# left as exercise..... >>>>> ?data.cnv.move(data.ring,deltax,deltay) >>>>> ?def Demo(root): >>>>> ?# resize window >>>>> ?root.geometry('400x400+0+0') >>>>> ?data.root=root >>>>> ?# make a canvas >>>>> ?cnv=Canvas(root) >>>>> ?cnv.pack(expand=1,fill=BOTH) >>>>> ?data.cnv=cnv >>>>> ?img=Image.open('white dragon.png') ?# some image you have..... >>>>> ?data.img=ImageTk.PhotoImage(img) >>>>> ?data.photo=cnv.create_image(0,0,image=data.img,anchor='nw') >>>>> ?data.ring=cnv.create_oval((100,100,300,300)) >>>>> ?cnv.bind("",motioncallback) >>>>> ?cnv.bind("",startmotioncallback) >>>>> ?root.mainloop() >>>>> >>>>> if __name__ == '__main__': >>>>> >>>>> ?root=Tk() >>>>> ?Demo(root) >>>>> _______________________________________________ >>>>> Image-SIG maillist ?- ?Image-SIG at python.org >>>>> http://mail.python.org/mailman/listinfo/image-sig >>>>> >>>>> >>>>> >>>> >>>> -- >>>> >>>> ? ? ? ?Wayne Watson (Watson Adventures, Prop., Nevada City, CA) >>>> >>>> ? ? ? ? ?(121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** >>>> >>>> ? ? ? "Less than all cannot satisfy Man." -- William Blake >>>> >>>> >>>> _______________________________________________ >>>> Image-SIG maillist ?- ?Image-SIG at python.org >>>> http://mail.python.org/mailman/listinfo/image-sig >>>> >>> >>> _______________________________________________ >>> Image-SIG maillist ?- ?Image-SIG at python.org >>> http://mail.python.org/mailman/listinfo/image-sig >>> >>> >> >> > > -- > > ? ? ? ? ?Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > ? ? ? ? ? ?(121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** > > ? ? ? ? "Less than all cannot satisfy Man." -- William Blake > > From santoshh19 at yahoo.co.in Wed Apr 8 20:25:43 2009 From: santoshh19 at yahoo.co.in (santosh panda) Date: Wed, 8 Apr 2009 23:55:43 +0530 (IST) Subject: [Image-SIG] raster extent problem Message-ID: <539997.52810.qm@web95413.mail.in2.yahoo.com> Dear List members, The python script pasted below does a calculation using the each pixel value of input data and writes it to new output raster. I also want to retrieve the extent and projection details from the input raster and pass it to output raster. gp.defineprojection() adds the projection details, but out.transform() fails to update the extent details in output raster. Am I doing anything wrong here or Is there any other way to pass the extent details from input to output raster? I would appreciate any suggestion or help on this problem. Thanks in advance... Santosh script: from PIL import Image, ImageMath import os, math, arcgisscripting gp = arcgisscripting.create(9.3) os.curdir = 'C:/temp' input = raw_input("Enter input raster name and path with extension: ") output = raw_input("Enter output raster name with extension: ") lmax = float(raw_input("Enter lmax value: ")) lmin = float(raw_input("Enter lmin value: ")) d = float(raw_input("Enter d value: ")) eSun = float(raw_input("Enter esun value: ")) elv = float(raw_input("Enter elevation value: ")) im = Image.open(input) def function(pixel): ??? return float((math.pi*((((lmax - lmin)/255)*pixel) + lmin)* d**2)/(eSun * math.cos((90 - elv)* .017453293))) size = im.size out = im.point(function) out.transform(size, Image.AFFINE, (30, 0, 326385, 0, 30, 6391185)) out.save(output) projection = 'C:/Program Files/ArcGIS/Coordinate Systems/Projected Coordinate Systems/UTM/WGS 1984/WGS 1984 UTM Zone 4N.prj' gp.DefineProjection_management(output, projection) print 'All done...' Check out the all-new Messenger 9.0! Go to http://in.messenger.yahoo.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From Chris.Barker at noaa.gov Thu Apr 9 19:46:02 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Thu, 09 Apr 2009 10:46:02 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <368a5cd50904081337y6b6889b6s13074faa8ba8326d@mail.gmail.com> References: <49D75A96.4020805@sbcglobal.net> <49DACD97.7060506@sbcglobal.net> <49DB5D55.1090101@noaa.gov> <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> <49DC3460.6080208@sbcglobal.net> <368a5cd50904081221q2eb61a55wa600b9aeb08e9715@mail.gmail.com> <49DD0731.3030609@sbcglobal.net> <368a5cd50904081337y6b6889b6s13074faa8ba8326d@mail.gmail.com> Message-ID: <49DE345A.1000805@noaa.gov> Fredrik Lundh wrote: > The Tkinter module contains a "Image" class, so doing the "import *" > thing after all other imports will stomp out the Import module. > Either fix all uses of PIL to use fully qualified names (replace > "import Image" with "import PIL.Image", "Image.open" with > "PIL.Image.open" etc), or, easier, move the "from Tkinter import *" > line to the top of the imports. but then you can't access the Tkinter Image class. "import *" is a bad idea, plain and simple, and this is why! "Namespaces are one honking great idea -- let's do more of those" note: that's not "less of those". EVERY package I work with that used to recommend "import *", no longer does: numpy, wxPython, matplotlib, .... I'd do something like: import PIL import PIL.Image as Image img=Image.open('white dragon.png') (By the way, is "import Image" depreciated? it should be.) import Tkinter as TK root=TK.Tk() etc. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From sierra_mtnview at sbcglobal.net Sat Apr 11 17:08:56 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 11 Apr 2009 08:08:56 -0700 Subject: [Image-SIG] Writing a "Raw" Image to a File Message-ID: <49E0B288.7040200@sbcglobal.net> I have an image of described as: Img Info---------------->: {} size: (640, 480) format: None mode: P palette: bands: ('P',) type: I'd like to write it to a file. Apparently, I need to convert it to a string first. How do I do that? -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "In arithemtic as in politics, the importance of one is determined by the number of zeros behind it." -- Anon From sierra_mtnview at sbcglobal.net Sat Apr 11 19:53:38 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 11 Apr 2009 10:53:38 -0700 Subject: [Image-SIG] Slowed Down by SBCglobal Spam Checker Message-ID: <49E0D922.5060409@sbcglobal.net> I just noticed by going directly to the Yahoo/SBC mail server some messages meant to get to me here were held as spam. They are now cleared, and I will respond to them as needed. There may be a way to unfilter image-sig at python.org there, but I don't know how to prevent mail-list traffic from getting stopped. Usually, after I clear things, the spam filter catches on. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "In arithemtic as in politics, the importance of one is determined by the number of zeros behind it." -- Anon From sierra_mtnview at sbcglobal.net Sat Apr 11 20:20:48 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 11 Apr 2009 11:20:48 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DE345A.1000805@noaa.gov> References: <49D75A96.4020805@sbcglobal.net> <49DACD97.7060506@sbcglobal.net> <49DB5D55.1090101@noaa.gov> <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> <49DC3460.6080208@sbcglobal.net> <368a5cd50904081221q2eb61a55wa600b9aeb08e9715@mail.gmail.com> <49DD0731.3030609@sbcglobal.net> <368a5cd50904081337y6b6889b6s13074faa8ba8326d@mail.gmail.com> <49DE345A.1000805@noaa.gov> Message-ID: <49E0DF80.2070603@sbcglobal.net> I thought I posted the solution, from Tkinter import * import Image, ImageTk import tkFileDialog Maybe as part of another thread. I've found it quite easy to put things in the wrong place. That has to do with sometimes not changing my usual format from html to plain text, which hangs the msg with the moderator, and Mozilla's Reply All. In the latter case, if I use Reply, which I usually to most mail, it gives me one address and not all. It might not include image-sig at python.org. Actually, there's a third way. Some posters seem to bet here from a non-image-sig at python.org address, so a Reply All won't get to image-sig at python.org. I'm not that far into Python to comment on the import-from stuff, but Chun in his book Core Pyton comments: "[use the] ... following order: Py std lib modules Py third party modules App specific" He comments that "from module-x import *" is bad form. However, he cites two places where it make sense, page 487. Christopher Barker wrote: > Fredrik Lundh wrote: >> The Tkinter module contains a "Image" class, so doing the "import *" >> thing after all other imports will stomp out the Import module. >> Either fix all uses of PIL to use fully qualified names (replace >> "import Image" with "import PIL.Image", "Image.open" with >> "PIL.Image.open" etc), or, easier, move the "from Tkinter import *" >> line to the top of the imports. > > but then you can't access the Tkinter Image class. > > "import *" is a bad idea, plain and simple, and this is why! > > "Namespaces are one honking great idea -- let's do more of those" > > note: that's not "less of those". > > EVERY package I work with that used to recommend "import *", no longer > does: numpy, wxPython, matplotlib, .... > > I'd do something like: > > import PIL > import PIL.Image as Image > > img=Image.open('white dragon.png') > > (By the way, is "import Image" depreciated? it should be.) > > > import Tkinter as TK > > root=TK.Tk() > > etc. > > > -Chris > > > Christopher Barker wrote: > Fredrik Lundh wrote: >> The Tkinter module contains a "Image" class, so doing the "import *" >> thing after all other imports will stomp out the Import module. >> Either fix all uses of PIL to use fully qualified names (replace >> "import Image" with "import PIL.Image", "Image.open" with >> "PIL.Image.open" etc), or, easier, move the "from Tkinter import *" >> line to the top of the imports. > > but then you can't access the Tkinter Image class. > > "import *" is a bad idea, plain and simple, and this is why! > > "Namespaces are one honking great idea -- let's do more of those" > > note: that's not "less of those". > > EVERY package I work with that used to recommend "import *", no longer > does: numpy, wxPython, matplotlib, .... > > I'd do something like: > > import PIL > import PIL.Image as Image > > img=Image.open('white dragon.png') > > (By the way, is "import Image" depreciated? it should be.) > > > import Tkinter as TK > > root=TK.Tk() > > etc. > > > -Chris > > > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "In arithemtic as in politics, the importance of one is determined by the number of zeros behind it." -- Anon From sierra_mtnview at sbcglobal.net Sat Apr 11 20:22:16 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 11 Apr 2009 11:22:16 -0700 Subject: [Image-SIG] Support for semi-transparent in PNG palette In-Reply-To: References: Message-ID: <49E0DFD8.40701@sbcglobal.net> I a bit tardy as explained by my Spam msg just posted. This is a very difficult list to post to for several reasons just mentioned in a msg I posted a few minutes ago. Interesting. Thanks. I did get what I was looking for (just posted a few mins ago), but this has some good twists. Denilson Figueiredo de S? wrote: > Hello, I think I found a bug/limitation in PIL. > > If I have a PNG with palette, and with semi-transparent colors at that > palette, then PIL will ignore the semi-transparent information. In > other words, it will always load the palette as RGB, instead of RGBA. > > Let's reproduce the bug, step-by-step: > > 1. Create an RGBA image using Gimp. Or, even easier, download this one > I created: > http://denilsonsa.selfip.org/~denilson/pil/rgba.png > > 2. Convert that image to RGBA palette. What I've done was: > > cp pil_rgba.png pil_palette.png > optipng -o7 pil_palette.png > > You can download optipng at http://optipng.sourceforge.net/ > Or you can download the converted image here: > http://denilsonsa.selfip.org/~denilson/pil/palette.png > > 3. Try opening it using PIL, convert back to RGBA, and save as PNG: > > from PIL import Image > f = Image.open("pil_palette.png") > print f.palette.mode # This will print RGB, but should be RGBA > f = f.convert("RGBA") > f.save("pil_saved.png") > > Or you can download it from here: > http://denilsonsa.selfip.org/~denilson/pil/saved.png > > > == What did I expect? == > > I expected that PIL would correctly load RGBA palette, and thus > correctly preserve the semi-transparent information. I expected that > the pil_saved.png file still looked the same as pil_rgba.png. > > > == What actually happens? == > > PIL throws away the Alpha channel, and the final pil_rgba.png image > has all semi-transparent pixels converted to opaque. > > > == Extra information == > > The "feh" image viewer correctly supports RGBA palettes. Also, I think > it is a better replacement for xv, for use in image.show() > http://www.linuxbrit.co.uk/feh > > Both Firefox and Opera browsers correctly support RGBA palettes. > > Surprisingly, Gimp does not support RGBA palettes, and will convert > semi-transparent colors to full transparency. > > > == Similar messages == > > While searching, I found these messages about the same subject: > 25 Jan 2009 - > http://www.mail-archive.com/image-sig at python.org/msg02275.html > 15 Nov 2008 - > http://www.mail-archive.com/image-sig at python.org/msg02182.html > 27 Aug 2008 - > http://www.mail-archive.com/image-sig at python.org/msg02065.html > 26 Jan 2005 - > http://www.mail-archive.com/image-sig at python.org/msg00069.html > > > > I'm not subscribed to this mail list, so please add me to CC when > replying to this message. > Thanks. > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** "In arithemtic as in politics, the importance of one is determined by the number of zeros behind it." -- Anon From rollbak at gmail.com Sat Apr 11 21:38:17 2009 From: rollbak at gmail.com (Lucas) Date: Sat, 11 Apr 2009 16:38:17 -0300 Subject: [Image-SIG] Writing a "Raw" Image to a File In-Reply-To: <49E0B288.7040200@sbcglobal.net> References: <49E0B288.7040200@sbcglobal.net> Message-ID: <194b7da00904111238g3bc9aaa5i9e35de019cac45a1@mail.gmail.com> Hello, Just a simple call to img.save("filename" [, "extension"]) regards, Lucas On Sat, Apr 11, 2009 at 12:08 PM, Wayne Watson wrote: > I have an image of described as: > Img Info---------------->: ?{} > ?size: ?(640, 480) > ?format: ?None > ?mode: ?P > ?palette: ? > ?bands: ?('P',) > ?type: ? > > I'd like to write it to a file. Apparently, I need to convert it to a string > first. How do I do that? > -- > > ? ? ? ? ?Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > ? ? ? ? ? ?(121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** > > ? ? ? ? "In arithemtic as in politics, the importance of one is > ? ? ? ? ?determined by the number of zeros behind it." -- Anon > _______________________________________________ > Image-SIG maillist ?- ?Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -- Lucas Shrewsbury ---------------------------------------------------- Open Your Mind, Use Open Source From sierra_mtnview at sbcglobal.net Sat Apr 11 17:00:49 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 11 Apr 2009 08:00:49 -0700 Subject: [Image-SIG] Writing a "Raw" Image to a File Message-ID: <49E0B0A1.1090402@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sat Apr 11 20:09:52 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 11 Apr 2009 11:09:52 -0700 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49DE345A.1000805@noaa.gov> References: <49D75A96.4020805@sbcglobal.net> <49DACD97.7060506@sbcglobal.net> <49DB5D55.1090101@noaa.gov> <49DB4BC1.26443.1CA3AE85@howard.eegsoftware.com> <49DC3460.6080208@sbcglobal.net> <368a5cd50904081221q2eb61a55wa600b9aeb08e9715@mail.gmail.com> <49DD0731.3030609@sbcglobal.net> <368a5cd50904081337y6b6889b6s13074faa8ba8326d@mail.gmail.com> <49DE345A.1000805@noaa.gov> Message-ID: <49E0DCF0.3000207@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sat Apr 11 20:14:08 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 11 Apr 2009 11:14:08 -0700 Subject: [Image-SIG] Examining the Palette and Image Properties In-Reply-To: <194b7da00904052033i4660ca21u5d768bcd92f65ad1@mail.gmail.com> References: <49D755E1.6060402@sbcglobal.net> <194b7da00904052033i4660ca21u5d768bcd92f65ad1@mail.gmail.com> Message-ID: <49E0DDF0.9000901@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sat Apr 11 20:21:24 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sat, 11 Apr 2009 11:21:24 -0700 Subject: [Image-SIG] Examining the Palette and Image Properties In-Reply-To: <194b7da00904052033i4660ca21u5d768bcd92f65ad1@mail.gmail.com> References: <49D755E1.6060402@sbcglobal.net> <194b7da00904052033i4660ca21u5d768bcd92f65ad1@mail.gmail.com> Message-ID: <49E0DFA4.6090506@sbcglobal.net> An HTML attachment was scrubbed... URL: From sierra_mtnview at sbcglobal.net Sun Apr 12 15:53:07 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sun, 12 Apr 2009 06:53:07 -0700 Subject: [Image-SIG] Writing a "Raw" Image to a File In-Reply-To: <194b7da00904111238g3bc9aaa5i9e35de019cac45a1@mail.gmail.com> References: <49E0B288.7040200@sbcglobal.net> <194b7da00904111238g3bc9aaa5i9e35de019cac45a1@mail.gmail.com> Message-ID: <49E1F243.2000100@sbcglobal.net> Not quite. That produces a header. I'm looking for a "raw" image. However, I solved that with a .tostring(). Lucas wrote: > Hello, > > Just a simple call to img.save("filename" [, "extension"]) > > regards, > > Lucas > > On Sat, Apr 11, 2009 at 12:08 PM, Wayne Watson > wrote: > >> I have an image of described as: >> Img Info---------------->: {} >> size: (640, 480) >> format: None >> mode: P >> palette: >> bands: ('P',) >> type: >> >> I'd like to write it to a file. Apparently, I need to convert it to a string >> first. How do I do that? >> -- >> >> Wayne Watson (Watson Adventures, Prop., Nevada City, CA) >> >> (121.01 Deg. W, 39.26 Deg. N) GMT-8 hr std. time)**** >> >> "In arithemtic as in politics, the importance of one is >> determined by the number of zeros behind it." -- Anon >> _______________________________________________ >> Image-SIG maillist - Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig >> >> > > > > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet "In arithemtic as in politics, the importance of one is determined by the number of zeros behind it." -- Anon From sierra_mtnview at sbcglobal.net Sun Apr 12 13:10:30 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sun, 12 Apr 2009 04:10:30 -0700 Subject: [Image-SIG] Writing a "Raw" Image to a File In-Reply-To: <194b7da00904111238g3bc9aaa5i9e35de019cac45a1@mail.gmail.com> References: <49E0B288.7040200@sbcglobal.net> <194b7da00904111238g3bc9aaa5i9e35de019cac45a1@mail.gmail.com> Message-ID: <49E1CC26.4060803@sbcglobal.net> An HTML attachment was scrubbed... URL: From g.kloss at massey.ac.nz Mon Apr 13 00:32:29 2009 From: g.kloss at massey.ac.nz (Guy K. Kloss) Date: Mon, 13 Apr 2009 10:32:29 +1200 Subject: [Image-SIG] Creating a Transparent Image and Placing it Over Another Image (txt) In-Reply-To: <49E0DCF0.3000207@sbcglobal.net> References: <49D75A96.4020805@sbcglobal.net> <49DE345A.1000805@noaa.gov> <49E0DCF0.3000207@sbcglobal.net> Message-ID: <200904131032.30328.g.kloss@massey.ac.nz> On Sun, 12 Apr 2009 06:09:52 Wayne Watson wrote: > import PIL > import PIL.Image as Image > > img=Image.open('white dragon.png') > > (By the way, is "import Image" depreciated? it should be.) There's no value in importing a module and renaming it to the same name. Your second import statement should look like this: from PIL import Image HTH, Guy -- Guy K. Kloss Institute of Information and Mathematical Sciences Te Kura P?taiao o M?hiohio me P?ngarau Room 2.63, Quad Block A Building Massey University, Auckland, Albany Private Bag 102 904, North Shore Mail Centre voice: +64 9 414-0800 ext. 9585 fax: +64 9 441-8181 eMail: G.Kloss at massey.ac.nz http://iims.massey.ac.nz From sierra_mtnview at sbcglobal.net Mon Apr 13 01:42:48 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sun, 12 Apr 2009 16:42:48 -0700 Subject: [Image-SIG] Tkinter and Antialiasing Message-ID: <49E27C78.1020204@sbcglobal.net> If I draw a fairly slanted line across an image using Tkinter, it looks a bit jagged. Is this typical of Tkinter graphics, or is there an option or mechanism that will antialias? Win XP, Python 2.5, Tkinter 8.4. -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet All the neutrons, and protons in the human body occupy a cube whose is 5.52*10**-6 meters. That adds up to a 150 pound person. It's not a surprise that we are mostly space. (Calculation by WTW) From ggpolo at gmail.com Mon Apr 13 02:30:07 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Sun, 12 Apr 2009 21:30:07 -0300 Subject: [Image-SIG] Tkinter and Antialiasing In-Reply-To: <49E27C78.1020204@sbcglobal.net> References: <49E27C78.1020204@sbcglobal.net> Message-ID: On Sun, Apr 12, 2009 at 8:42 PM, Wayne Watson wrote: > If I draw a fairly slanted line across an image using Tkinter, it looks > a bit jagged. Is this typical of Tkinter graphics, or is there an option > or mechanism that will antialias? > I'm not sure if this is ontopic for image-sig, but.. Tkinter is not really responsible for the drawing, it just passes the responsibility to tk. The standard tk canvas is not going to give you pretty results, but there is an option if you want to continue using tk for this. Last time I checked you could use the tkpath extension (can be found at http://tclbitprint.sourceforge.net/), and maybe there are other extensions to do the same. > Win XP, Python 2.5, Tkinter 8.4. > -- -- Guilherme H. Polo Goncalves From sierra_mtnview at sbcglobal.net Mon Apr 13 02:58:35 2009 From: sierra_mtnview at sbcglobal.net (Wayne Watson) Date: Sun, 12 Apr 2009 17:58:35 -0700 Subject: [Image-SIG] Tkinter and Antialiasing In-Reply-To: References: <49E27C78.1020204@sbcglobal.net> Message-ID: <49E28E3B.8030305@sbcglobal.net> You are right, I should have dropped this into the Tkinter mail list. Thanks for the info, but I think I'd like to stick to Tkinter for now. I do have a way out of my dilemma. I'm trying to draw something like a compass, and I don't necessarily need the lines emenating from the center to the edge of a circle. I can just intersect the circle with maybe a 10-20 pixel line. Out of curosity, I will re-post over in Tk-ville. Guilherme Polo wrote: > On Sun, Apr 12, 2009 at 8:42 PM, Wayne Watson > wrote: > >> If I draw a fairly slanted line across an image using Tkinter, it looks >> a bit jagged. Is this typical of Tkinter graphics, or is there an option >> or mechanism that will antialias? >> >> > > I'm not sure if this is ontopic for image-sig, but.. > > Tkinter is not really responsible for the drawing, it just passes the > responsibility to tk. The standard tk canvas is not going to give you > pretty results, but there is an option if you want to continue using > tk for this. Last time I checked you could use the tkpath extension > (can be found at http://tclbitprint.sourceforge.net/), and maybe there > are other extensions to do the same. > > >> Win XP, Python 2.5, Tkinter 8.4. >> >> > > > > -- Wayne Watson (Watson Adventures, Prop., Nevada City, CA) (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet All the neutrons, and protons in the human body occupy a cube whose is 5.52*10**-6 meters. That adds up to a 150 pound person. It's not a surprise that we are mostly space. (Calculation by WTW) From g.kloss at massey.ac.nz Mon Apr 13 05:01:58 2009 From: g.kloss at massey.ac.nz (Guy K. Kloss) Date: Mon, 13 Apr 2009 15:01:58 +1200 Subject: [Image-SIG] proper type of image objects Message-ID: <200904131501.59270.g.kloss@massey.ac.nz> Hi, I'm currently working on extending the ctypes based LCMS bindings, and I want to support PIL image types natively inside the doTransform() method on a Transform object. Anyway, for that task I need to distinguish between different valid object types for the input buffer to decide which action to take. For NumPy arrays that works nicely, but I don't know how to distinguish properly whether I'm dealing with a PIL.Image type object. Below you can find some of the tinkerings of the "obvious" candidates. So far it seems as if only the last one gives me a viable option, but it doesn't strike me as being very pythonic, elegant or even clean in the code. Any suggestions? Guy >>> type(a_numpy_array) >>> isinstance(a_numpy_array, numpy.ndarray) True >>> type(a_pil_image) >>> isinstance(a_pil_image, instance) [...] NameError: name 'instance' is not defined >>> isinstance(inImage, PIL.Image) [...] TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types >>> isinstance(a_pil_image, PIL.PngImagePlugin.PngImageFile) True >>> str(a_pil_image.__class__).startswith('PIL.') True -- Guy K. Kloss Institute of Information and Mathematical Sciences Te Kura P?taiao o M?hiohio me P?ngarau Room 2.63, Quad Block A Building Massey University, Auckland, Albany Private Bag 102 904, North Shore Mail Centre voice: +64 9 414-0800 ext. 9585 fax: +64 9 441-8181 eMail: G.Kloss at massey.ac.nz http://iims.massey.ac.nz From g.kloss at massey.ac.nz Mon Apr 13 05:11:57 2009 From: g.kloss at massey.ac.nz (Guy K. Kloss) Date: Mon, 13 Apr 2009 15:11:57 +1200 Subject: [Image-SIG] proper type of image objects In-Reply-To: <200904131501.59270.g.kloss@massey.ac.nz> References: <200904131501.59270.g.kloss@massey.ac.nz> Message-ID: <200904131511.58080.g.kloss@massey.ac.nz> Sorry for the noise, found something after creating a new image *without* loading it, but using PIL.Image.new() which seems to work on all PIL image objects: >>> isinstance(a_pil_image, PIL.Image.Image) True Guy -- Guy K. Kloss Institute of Information and Mathematical Sciences Te Kura P?taiao o M?hiohio me P?ngarau Room 2.63, Quad Block A Building Massey University, Auckland, Albany Private Bag 102 904, North Shore Mail Centre voice: +64 9 414-0800 ext. 9585 fax: +64 9 441-8181 eMail: G.Kloss at massey.ac.nz http://iims.massey.ac.nz From ggpolo at gmail.com Mon Apr 13 12:08:14 2009 From: ggpolo at gmail.com (Guilherme Polo) Date: Mon, 13 Apr 2009 07:08:14 -0300 Subject: [Image-SIG] Tkinter and Antialiasing In-Reply-To: <49E28E3B.8030305@sbcglobal.net> References: <49E27C78.1020204@sbcglobal.net> <49E28E3B.8030305@sbcglobal.net> Message-ID: On Sun, Apr 12, 2009 at 9:58 PM, Wayne Watson wrote: > You are right, I should have dropped this into the Tkinter mail list. Thanks > for the info, but I think I'd like to stick to Tkinter for now. I do have a > way out of my dilemma. I'm trying to draw something like a compass, and I > don't necessarily need the lines emenating from the center to the edge of a > circle. I can just intersect the circle with maybe a 10-20 pixel line. Out > of curosity, I will re-post over in Tk-ville. > Apparently you just ignored me, fine. > Guilherme Polo wrote: >> >> On Sun, Apr 12, 2009 at 8:42 PM, Wayne Watson >> wrote: >> >>> >>> If I draw a fairly slanted line across an image using Tkinter, it looks >>> a bit jagged. Is this typical of Tkinter graphics, or is there an option >>> or mechanism that will antialias? >>> >>> >> >> I'm not sure if this is ontopic for image-sig, but.. >> >> Tkinter is not really responsible for the drawing, it just passes the >> responsibility to tk. The standard tk canvas is not going to give you >> pretty results, but there is an option if you want to continue using >> tk for this. Last time I checked you could use the tkpath extension >> (can be found at http://tclbitprint.sourceforge.net/), and maybe there >> are other extensions to do the same. >> >> >>> >>> Win XP, Python 2.5, Tkinter 8.4. >>> >>> >> >> >> >> > > -- > ? ? ? ? ?Wayne Watson (Watson Adventures, Prop., Nevada City, CA) > > ? ? ? ? ? ?(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) > ? ? ? ? ? ? Obz Site: ?39? 15' 7" N, 121? 2' 32" W, 2700 feet > ? ? ? ? ?All the neutrons, and protons in the human body occupy ? ? ? ? ?a > cube whose is 5.52*10**-6 meters. That adds up to a ? ? ? ? ?150 pound > person. It's not a surprise that we are mostly ? ? ? ? ?space. (Calculation > by WTW) > > > > -- -- Guilherme H. Polo Goncalves From fredrik at pythonware.com Mon Apr 13 14:08:40 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 13 Apr 2009 14:08:40 +0200 Subject: [Image-SIG] proper type of image objects In-Reply-To: <200904131501.59270.g.kloss@massey.ac.nz> References: <200904131501.59270.g.kloss@massey.ac.nz> Message-ID: <368a5cd50904130508u4174655fub8c99b73fea4d58e@mail.gmail.com> On Mon, Apr 13, 2009 at 5:01 AM, Guy K. Kloss wrote: > > Hi, > > I'm currently working on extending the ctypes based LCMS bindings, and I want > to support PIL image types natively inside the doTransform() method on a > Transform object. > > Anyway, for that task I need to distinguish between different valid object > types for the input buffer to decide which action to take. For NumPy arrays > that works nicely, but I don't know how to distinguish properly whether I'm > dealing with a PIL.Image type object. Below you can find some of the > tinkerings of the "obvious" candidates. > > So far it seems as if only the last one gives me a viable option, but it > doesn't strike me as being very pythonic, elegant or even clean in the code. > > Any suggestions? > > Guy > > > >>> type(a_numpy_array) > > >>> isinstance(a_numpy_array, numpy.ndarray) > True > >>> type(a_pil_image) > > >>> isinstance(a_pil_image, instance) > [...] > NameError: name 'instance' is not defined > >>> isinstance(inImage, PIL.Image) > [...] > TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and > types >>> PIL.Image >>> PIL.Image.Image >>> isinstance(inImage, PIL.Image.Image) True >>> PIL.Image.isImageType(inImage) True From fredrik at pythonware.com Mon Apr 13 22:55:15 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 13 Apr 2009 22:55:15 +0200 Subject: [Image-SIG] ANN: PIL 1.1.7 beta 1 (April 12, 2009) Message-ID: <368a5cd50904131355h7bdf2152yb502da1f06d5959a@mail.gmail.com> PIL 1.1.7 beta 1 for Python 2.X is now available. Source code can be downloaded from the Mercurial main repository: http://hg.effbot.org/pil-2009-raclette/src/pil-117b1-20090412 If you're using Mercurial, you can use "hg clone" to download a copy: hg clone -r pil-117b1-20090412 http://hg.effbot.org/pil-2009-raclette/ This release adds read support for interlaced PNG files, from Conrado Porto Lopes Gouv?a, and the usual collection of minor tweaks and fixes. The result should be pretty close to release candidate status. Subversion & tarball source kits will be made available later this week, as will Windows builds for various Python versions. From fredrik at pythonware.com Mon Apr 13 22:59:25 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 13 Apr 2009 22:59:25 +0200 Subject: [Image-SIG] ANN: PIL 1.1.7 beta 1 (April 12, 2009) In-Reply-To: <368a5cd50904131355h7bdf2152yb502da1f06d5959a@mail.gmail.com> References: <368a5cd50904131355h7bdf2152yb502da1f06d5959a@mail.gmail.com> Message-ID: <368a5cd50904131359u62a3538fka24f0fe07e4d95b0@mail.gmail.com> On Mon, Apr 13, 2009 at 10:55 PM, Fredrik Lundh wrote: > PIL 1.1.7 beta 1 for Python 2.X is now available. ?Source code can be > downloaded from the Mercurial main repository: > > ? http://hg.effbot.org/pil-2009-raclette/src/pil-117b1-20090412 Just noticed that Bitbucket has added a new downloads tab; you'll find a list of available archives here: http://hg.effbot.org/pil-2009-raclette/downloads/ From fredrik at pythonware.com Tue Apr 14 23:27:49 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 14 Apr 2009 23:27:49 +0200 Subject: [Image-SIG] ANN: PIL 1.1.7 beta 1 (April 12, 2009) In-Reply-To: <368a5cd50904131359u62a3538fka24f0fe07e4d95b0@mail.gmail.com> References: <368a5cd50904131355h7bdf2152yb502da1f06d5959a@mail.gmail.com> <368a5cd50904131359u62a3538fka24f0fe07e4d95b0@mail.gmail.com> Message-ID: <368a5cd50904141427u38a44cc2i9b9e4a639dc3e621@mail.gmail.com> On Mon, Apr 13, 2009 at 10:59 PM, Fredrik Lundh wrote: >> PIL 1.1.7 beta 1 for Python 2.X is now available. ?Source code can be >> downloaded from the Mercurial main repository: >> >> ? http://hg.effbot.org/pil-2009-raclette/src/pil-117b1-20090412 A tarball and a SVN "vendor drop" is now available: http://effbot.org/downloads/Imaging-1.1.7b1.tar.gz http://svn.effbot.org/public/tags/pil-1.1.7b1-20090412/ Also, builds for Windows are available here: http://effbot.org/downloads/#pil From zac256 at gmail.com Thu Apr 16 19:00:08 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 16 Apr 2009 10:00:08 -0700 Subject: [Image-SIG] PIL crash bug sharpening Message-ID: <333edbe80904161000j3562998flecde9d31240b79c2@mail.gmail.com> PIL will cause a crash in python.exe when sharpening very small images. Repro: img = PImage.new('RGB', (1, 1)) img = PImageEnhance.Sharpness(img).enhance(1.5) -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games From fetchinson at googlemail.com Thu Apr 16 19:07:52 2009 From: fetchinson at googlemail.com (Daniel Fetchinson) Date: Thu, 16 Apr 2009 10:07:52 -0700 Subject: [Image-SIG] PIL crash bug sharpening In-Reply-To: <333edbe80904161000j3562998flecde9d31240b79c2@mail.gmail.com> References: <333edbe80904161000j3562998flecde9d31240b79c2@mail.gmail.com> Message-ID: > PIL will cause a crash in python.exe when sharpening very small images. > > Repro: > > img = PImage.new('RGB', (1, 1)) > img = PImageEnhance.Sharpness(img).enhance(1.5) I can confirm this on linux x86_64, python 2.5.1, PIL 1.1.6. The above segfaults python. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown From fredrik at pythonware.com Thu Apr 16 19:34:40 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 16 Apr 2009 19:34:40 +0200 Subject: [Image-SIG] PIL crash bug sharpening In-Reply-To: <333edbe80904161000j3562998flecde9d31240b79c2@mail.gmail.com> References: <333edbe80904161000j3562998flecde9d31240b79c2@mail.gmail.com> Message-ID: <368a5cd50904161034n36f8a484u158ce8a19d650df8@mail.gmail.com> On Thu, Apr 16, 2009 at 7:00 PM, Zac Burns wrote: > PIL will cause a crash in python.exe when sharpening very small images. > > Repro: > > img = PImage.new('RGB', (1, 1)) > img = PImageEnhance.Sharpness(img).enhance(1.5) Thanks for reporting this. A workaround is available here: http://hg.effbot.org/pil-2009-raclette/changeset/d1c45b7eb7d7/ (the patch is against 1.1.7, but the Filter.c part should apply cleanly on 1.1.6) From zac256 at gmail.com Thu Apr 16 19:57:15 2009 From: zac256 at gmail.com (Zac Burns) Date: Thu, 16 Apr 2009 10:57:15 -0700 Subject: [Image-SIG] PIL crash bug sharpening In-Reply-To: <368a5cd50904161034n36f8a484u158ce8a19d650df8@mail.gmail.com> References: <333edbe80904161000j3562998flecde9d31240b79c2@mail.gmail.com> <368a5cd50904161034n36f8a484u158ce8a19d650df8@mail.gmail.com> Message-ID: <333edbe80904161057y31e6af5egb5921fb610a87cc1@mail.gmail.com> Thanks. -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games On Thu, Apr 16, 2009 at 10:34 AM, Fredrik Lundh wrote: > On Thu, Apr 16, 2009 at 7:00 PM, Zac Burns wrote: >> PIL will cause a crash in python.exe when sharpening very small images. >> >> Repro: >> >> img = PImage.new('RGB', (1, 1)) >> img = PImageEnhance.Sharpness(img).enhance(1.5) > > Thanks for reporting this. ?A workaround is available here: > > ? ?http://hg.effbot.org/pil-2009-raclette/changeset/d1c45b7eb7d7/ > > (the patch is against 1.1.7, but the Filter.c part should apply > cleanly on 1.1.6) > > > From huntermartin at mac.com Sat Apr 18 02:54:43 2009 From: huntermartin at mac.com (Hunter Martin) Date: Fri, 17 Apr 2009 19:54:43 -0500 Subject: [Image-SIG] (no subject) Message-ID: <3188C173-D2E0-43A3-A77F-7C34ECBBFE19@mac.com> Hello, I am trying to install PIL onto my Macbook. I am running the most update-to-date version of Leopard. I am following your instructions provided with 1.1.6. When I go to run python setup.py build_ext -i, I get the following info: running build_ext --- using frameworks at /System/Library/Frameworks building '_imaging' extension creating build creating build/temp.macosx-10.5-i386-2.5 creating build/temp.macosx-10.5-i386-2.5/libImaging gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused- madd -fno-common -dynamic -DNDEBUG -g -Os -Wall -Wstrict-prototypes - DMACOSX -I/usr/include/ffi -DENABLE_DTRACE -arch i386 -arch ppc -pipe - DHAVE_LIBZ -IlibImaging -I/System/Library/Frameworks/Python.framework/ Versions/2.5/include -I/usr/include -I/System/Library/Frameworks/ Python.framework/Versions/2.5/include/python2.5 -c _imaging.c -o build/ temp.macosx-10.5-i386-2.5/_imaging.o unable to execute gcc: No such file or directory error: command 'gcc' failed with exit status 1 When I run python selftest.py, I get the following: Traceback (most recent call last): File "selftest.py", line 11, in import ImageMath File "PIL/ImageMath.py", line 19, in import _imagingmath ImportError: No module named _imagingmath What am I doing wrong? Thank you. From jwt at OnJapan.net Sat Apr 18 05:19:01 2009 From: jwt at OnJapan.net (Jim Tittsler) Date: Sat, 18 Apr 2009 15:19:01 +1200 Subject: [Image-SIG] PIL In-Reply-To: <3188C173-D2E0-43A3-A77F-7C34ECBBFE19@mac.com> References: <3188C173-D2E0-43A3-A77F-7C34ECBBFE19@mac.com> Message-ID: <49E946A5.60305@OnJapan.net> On 04/18/2009 12:54 PM, Hunter Martin wrote: > I am trying to install PIL onto my Macbook. I am running the most > update-to-date version of Leopard. I am following your instructions > provided with 1.1.6. When I go to run python setup.py build_ext -i, I > get the following info: [...] > unable to execute gcc: No such file or directory > error: command 'gcc' failed with exit status 1 You don't appear to have Xcode (the developer tools) installed. You can download a copy from http://developer.apple.com/mac/ Alternatively you might want to take advantage of one of the pre-built PIL packages for OS X. http://wiki.python.org/moin/MacPython/UniversalLibrariesAndExtensions From schwehr at ccom.unh.edu Sat Apr 18 14:41:28 2009 From: schwehr at ccom.unh.edu (Kurt Schwehr) Date: Sat, 18 Apr 2009 08:41:28 -0400 Subject: [Image-SIG] EXIF tag reading fails for minimal tagged images Message-ID: <49E9CA78.7040205@ccom.unh.edu> This is with python 2.6, pil 1.1.6 on mac osx 10.5.6 with fink python/pil wget http://schwehr.org/blog/attachments/2009-04/20090201-1601-with-exif-gps.jpeg ipython import Image im = Image.open('20090201-1601-with-exif-gps.jpeg') In [29]: im._getexif() --------------------------------------------------------------------------- KeyError Traceback (most recent call last) /Users/schwehr/projects/src/healy/ in () /sw/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc in _getexif(self) 352 exif[key] = fixup(value) 353 # get exif extension --> 354 file.seek(exif[0x8769]) 355 info = TiffImagePlugin.ImageFileDirectory(head) 356 info.load(file) KeyError: 34665 However, jhead works... jhead 20090201-1601-with-exif-gps.jpeg File name : 20090201-1601-with-exif-gps.jpeg File size : 116441 bytes File date : 2009:04:16 07:17:11 Resolution : 1280 x 960 GPS Latitude : N 43d 12m 59.998s GPS Longitude: W 123d 1m 12s Comment : Sun Feb 01 16:00:32 2009 From fredrik at pythonware.com Sat Apr 18 16:29:38 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 18 Apr 2009 16:29:38 +0200 Subject: [Image-SIG] EXIF tag reading fails for minimal tagged images In-Reply-To: <49E9CA78.7040205@ccom.unh.edu> References: <49E9CA78.7040205@ccom.unh.edu> Message-ID: <368a5cd50904180729y4040c8b7x4cec0a3e6827af48@mail.gmail.com> On Sat, Apr 18, 2009 at 2:41 PM, Kurt Schwehr wrote: > This is with python 2.6, pil 1.1.6 on mac osx 10.5.6 with fink python/pil > > wget > http://schwehr.org/blog/attachments/2009-04/20090201-1601-with-exif-gps.jpeg > > ipython > import Image > im = Image.open('20090201-1601-with-exif-gps.jpeg') > > In [29]: im._getexif() > --------------------------------------------------------------------------- > KeyError ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Traceback (most recent call last) > > /Users/schwehr/projects/src/healy/ in () > > /sw/lib/python2.6/site-packages/PIL/JpegImagePlugin.pyc in _getexif(self) > ? 352 ? ? ? ? ? ? exif[key] = fixup(value) > ? 353 ? ? ? ? # get exif extension > > --> 354 ? ? ? ? file.seek(exif[0x8769]) > ? 355 ? ? ? ? info = TiffImagePlugin.ImageFileDirectory(head) > ? 356 ? ? ? ? info.load(file) > > KeyError: 34665 Thanks for the bug report. The problem is that this file contains a GPS IFD but not standard EXIF IFD. The following fix is against 1.1.7b2, but the JpegImagePlugin part should work against 1.1.6 too: http://hg.effbot.org/pil-2009-raclette/changeset/de084654231a/ From jdmain at comcast.net Sat Apr 18 16:54:34 2009 From: jdmain at comcast.net (J.D. Main) Date: Sat, 18 Apr 2009 08:54:34 -0600 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) Message-ID: <49E9954A.30210.664481F@jdmain.comcast.net> Hello, I have a desire to work with National Weather Service Radar Images. In the United State the NWS provides a service where GIF images are updated every 5 minutes or so with the latest snapshot from a dopler radar site Here's a URL explaining all this: http://radar.weather.gov/GIS.html In short these images are GIF files with a 256 color pallete. The "interesting" pixels in these images are red, green, yellow and blue. The pixels representing radar "noise" usually appear as brown, grey, and purple. My desire is to iterate over all pixels and remove the noise. The pseudo code would look something like this: for pixel in radar_image: if pixel is noise: turn pixel white else: do nothing I'm having a hard time with this. Can anyone provide some insight into a method? It would be greatly appreciated. Thanks! J.D. From d_berthelot at yahoo.com Sat Apr 18 20:50:52 2009 From: d_berthelot at yahoo.com (David Berthelot) Date: Sat, 18 Apr 2009 11:50:52 -0700 (PDT) Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <49E9954A.30210.664481F@jdmain.comcast.net> References: <49E9954A.30210.664481F@jdmain.comcast.net> Message-ID: <174972.29079.qm@web57607.mail.re1.yahoo.com> I do some pretty fancy image manipulation at the pixel level too. What I do is that I use numpy arrays to store images and perform all my math stuff on them. Example: import Image import numpy as N f = Image.open("image.gif") g = N.array(N.asarray(f)) print g.shape for y in xrange(g.shape[0]): for x in xrange(g.shape[1]): print "pixel",x,y,g[y,x] # You can change the pixel value, here I just increment the red channel by one if g[y,x,0] < 255: g[y,x,0] += 1 f2 = Image.fromarray(N.array(N.clip(g,0,255),'uint8')) f2.save("new_image.gif") Hope this helps, David ----- Original Message ---- From: J.D. Main To: image-sig at python.org Sent: Saturday, April 18, 2009 7:54:34 AM Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) Hello, I have a desire to work with National Weather Service Radar Images. In the United State the NWS provides a service where GIF images are updated every 5 minutes or so with the latest snapshot from a dopler radar site Here's a URL explaining all this: http://radar.weather.gov/GIS.html In short these images are GIF files with a 256 color pallete. The "interesting" pixels in these images are red, green, yellow and blue. The pixels representing radar "noise" usually appear as brown, grey, and purple. My desire is to iterate over all pixels and remove the noise. The pseudo code would look something like this: for pixel in radar_image: if pixel is noise: turn pixel white else: do nothing I'm having a hard time with this. Can anyone provide some insight into a method? It would be greatly appreciated. Thanks! J.D. _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig From fredrik at pythonware.com Sat Apr 18 22:25:54 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sat, 18 Apr 2009 22:25:54 +0200 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <49E9954A.30210.664481F@jdmain.comcast.net> References: <49E9954A.30210.664481F@jdmain.comcast.net> Message-ID: <368a5cd50904181325h570d5c39xbe18fef3e47fcebc@mail.gmail.com> On Sat, Apr 18, 2009 at 4:54 PM, J.D. Main wrote: > Here's a URL explaining all this: ?http://radar.weather.gov/GIS.html > > In short these images are GIF files with a 256 color pallete. ?The > "interesting" pixels in these images are red, green, yellow and blue. > > The pixels representing radar "noise" usually appear as brown, grey, and > purple. > > My desire is to iterate over all pixels and remove the noise. ?The pseudo > code would look something like this: > > for pixel in radar_image: > ? if pixel is noise: > ? ? ?turn pixel white > ? else: > ? ? ?do nothing > > I'm having a hard time with this. ?Can anyone provide some insight into a > method? ?It would be greatly appreciated. Given that GIF images are 8-bit images with a color palette (that is, the pixel values are indexes into a color palette), here's a better outline: im = Image.open("radar-image.gif") palette = im.getpalette() # prepare lookup table lut = range(256) for i in range(256): r, g, b = palette[i*3:i*3+3] if is_noise(r, g, b): lut[i] = 0 # or whatever index you want for the background # map all noise colors to 0, leave rest as is im = im.point(lut) The getpalette function returns the color palette as a 768-item list containing [red0, green0, blue0, red1, green1, ...]. The is_noise function checks if the given RGB value corresponds to a noise color (you have to write this one yourself). Note that if the "noise" colors occupy a given index range, you can skip the palette test and just set lut[i] to the background index if i is in that range. From jdmain at comcast.net Sun Apr 19 01:32:49 2009 From: jdmain at comcast.net (J.D. Main) Date: Sat, 18 Apr 2009 17:32:49 -0600 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <368a5cd50904181325h570d5c39xbe18fef3e47fcebc@mail.gmail.com> References: <49E9954A.30210.664481F@jdmain.comcast.net>, <368a5cd50904181325h570d5c39xbe18fef3e47fcebc@mail.gmail.com> Message-ID: <49EA0EC1.1975.83EC135@jdmain.comcast.net> Hi Frederik, Thanks for the help. I'll see if I can utilize the palette as you describe. If I can craft a good noise detection algorithm, I'll post my code back to the SIG. Best Regards, J.D. On Sat, Apr 18, 2009 at 4:54 PM, J.D. Main wrote: > Here's a URL explaining all this: ?http://radar.weather.gov/GIS.html > > In short these images are GIF files with a 256 color pallete. ?The > "interesting" pixels in these images are red, green, yellow and blue. > > The pixels representing radar "noise" usually appear as brown, grey, and > purple. > > My desire is to iterate over all pixels and remove the noise. ?The pseudo > code would look something like this: > > for pixel in radar_image: > ? if pixel is noise: > ? ? ?turn pixel white > ? else: > ? ? ?do nothing > > I'm having a hard time with this. ?Can anyone provide some insight into a > method? ?It would be greatly appreciated. Given that GIF images are 8-bit images with a color palette (that is, the pixel values are indexes into a color palette), here's a better outline: im = Image.open("radar-image.gif") palette = im.getpalette() # prepare lookup table lut = range(256) for i in range(256): r, g, b = palette[i*3:i*3+3] if is_noise(r, g, b): lut[i] = 0 # or whatever index you want for the background # map all noise colors to 0, leave rest as is im = im.point(lut) The getpalette function returns the color palette as a 768-item list containing [red0, green0, blue0, red1, green1, ...]. The is_noise function checks if the given RGB value corresponds to a noise color (you have to write this one yourself). Note that if the "noise" colors occupy a given index range, you can skip the palette test and just set lut[i] to the background index if i is in that range. From Chris.Barker at noaa.gov Tue Apr 21 01:34:02 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Mon, 20 Apr 2009 16:34:02 -0700 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <174972.29079.qm@web57607.mail.re1.yahoo.com> References: <49E9954A.30210.664481F@jdmain.comcast.net> <174972.29079.qm@web57607.mail.re1.yahoo.com> Message-ID: <49ED066A.6050504@noaa.gov> David Berthelot wrote: > What I do is that I use numpy arrays to store images and perform all my math stuff on them. numpy is good for this stuff, particularly if it gets more complicated, but a few comments" > Example: > import Image > import numpy as N > f = Image.open("image.gif") > g = N.array(N.asarray(f)) note: numpy.asarray returns a read-only array, so calling array() on it makes a copy, so that you can change it. You could use N.asarray(f).copy() as well. Since these are 8-bit palleted images, what you get is a uint8 array, not an rbg array. > for y in xrange(g.shape[0]): > for x in xrange(g.shape[1]): the glory (or, one of the glories) or numpy is that you don't have to loop, you can operate in the whole array as a unit. As Fredrik said, You'd have to look at the Pallet to see which color is which, but you can do: noise_color = 4 white = 0 g[g == noise_color] = white and presto -- every noise pixel is now white. Enclosed is a test script that demos some of this. By the way, I tried setting the palette of the new image like so: im2.putpalette(im.palette) and it mostly worked, but white can turned into magenta -- can anyone tell me why/ Also, the new gif is twice as big as the old -- is it not compressed the same way? -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov -------------- next part -------------- A non-text attachment was scrubbed... Name: test_gif.py Type: application/x-python Size: 1033 bytes Desc: not available URL: From jdmain at comcast.net Tue Apr 21 18:12:42 2009 From: jdmain at comcast.net (J.D. Main) Date: Tue, 21 Apr 2009 10:12:42 -0600 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <49ED066A.6050504@noaa.gov> References: <49E9954A.30210.664481F@jdmain.comcast.net>, <174972.29079.qm@web57607.mail.re1.yahoo.com>, <49ED066A.6050504@noaa.gov> Message-ID: <49ED9C1A.28201.161EE386@jdmain.comcast.net> Hey guys, First of all, thanks for the help on this. I have been a bit preoccupied with another project but I hope to craft a demonstation of 'clean' radar soon. Christopher - thanks for the sample script! I'll most definitely lift as much of that as I can! It's great that the Image-SIG is so active. I have been extolling the virtues of PIL and Python in general to my friends for a long time now. This sort of community support proves that I've been right all along! J.D. From Chris.Barker at noaa.gov Tue Apr 21 01:12:54 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Mon, 20 Apr 2009 16:12:54 -0700 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <174972.29079.qm@web57607.mail.re1.yahoo.com> References: <49E9954A.30210.664481F@jdmain.comcast.net> <174972.29079.qm@web57607.mail.re1.yahoo.com> Message-ID: <49ED0176.7000506@noaa.gov> David Berthelot wrote: > What I do is that I use numpy arrays to store images and perform all my math stuff on them. numpy is good for this stuff, particularly if it gets more complicated, but a few comments" > Example: > import Image > import numpy as N > f = Image.open("image.gif") > g = N.array(N.asarray(f)) note: numpy.asarray returns a read-only array, so calling array() on it makes a copy, so that you can change it. You could use N.asarray(f).copy() as well. Since these are 8-bit palleted images, what you get is a uint8 array, not an rbg array. > for y in xrange(g.shape[0]): > for x in xrange(g.shape[1]): the glory (or, one of the glories) or numpy is that you don't have to loop, you can operate in the whole array as a unit. As Fredrik said, You'd have to look at the Pallet to see which color is which, but you can do: noise_color = 4 white = 0 g[g == noise_color] = white and presto -- every noise pixel is now white. Enclosed is a test script (and sample image) that demos some of this. By the way, I tried setting the palette of the new image like so: im2.putpalette(im.palette) and it mostly worked, but white can turned into magenta -- can anyone tell me why/ Also, the new gif is twice as big as the old -- is it not compressed the same way? -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov -------------- next part -------------- A non-text attachment was scrubbed... Name: test_gif.py Type: application/x-python Size: 1033 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ARX_N0R_0.gif Type: image/gif Size: 30687 bytes Desc: not available URL: From jdmain at comcast.net Wed Apr 22 05:12:59 2009 From: jdmain at comcast.net (J.D. Main) Date: Tue, 21 Apr 2009 21:12:59 -0600 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <49ED066A.6050504@noaa.gov> References: <49E9954A.30210.664481F@jdmain.comcast.net>, <174972.29079.qm@web57607.mail.re1.yahoo.com>, <49ED066A.6050504@noaa.gov> Message-ID: <49EE36DB.20674.187B6493@jdmain.comcast.net> An HTML attachment was scrubbed... URL: From jdmain at comcast.net Wed Apr 22 18:30:43 2009 From: jdmain at comcast.net (J.D. Main) Date: Wed, 22 Apr 2009 10:30:43 -0600 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) Message-ID: <49EEF1D3.15987.1B55BE7C@jdmain.comcast.net> An HTML attachment was scrubbed... URL: From paj at pajhome.org.uk Tue Apr 21 04:11:49 2009 From: paj at pajhome.org.uk (Paul Johnston) Date: Tue, 21 Apr 2009 09:11:49 +0700 Subject: [Image-SIG] Resizing Photos Message-ID: Hi, I'm currently using PIL to resize photos down to a thumbnail. Something I've noticed though, is that whatever software Facebook use too do the same, produces better-quality thumbnails. Are there any tweaks I can apply to PIL to get better resizing? Or any idea what software FB may be using? Paul -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists+Image_SIG at hoech.org Wed Apr 22 21:29:41 2009 From: lists+Image_SIG at hoech.org (=?ISO-8859-1?Q?Florian_H=F6ch?=) Date: Wed, 22 Apr 2009 21:29:41 +0200 Subject: [Image-SIG] Resizing Photos In-Reply-To: References: Message-ID: <49EF7025.6040903@hoech.org> Hi, the anti-alias filter gives best results imho. import PIL yourimage.resize((w, h), PIL.Image.ANTIALIAS)) Regards, Florian H?ch Paul Johnston schrieb: > Hi, > > I'm currently using PIL to resize photos down to a thumbnail. Something > I've noticed though, is that whatever software Facebook use too do the > same, produces better-quality thumbnails. > > Are there any tweaks I can apply to PIL to get better resizing? Or any > idea what software FB may be using? > > Paul > > > ------------------------------------------------------------------------ > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From fredrik at pythonware.com Wed Apr 22 21:31:10 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 22 Apr 2009 21:31:10 +0200 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <49ED066A.6050504@noaa.gov> References: <49E9954A.30210.664481F@jdmain.comcast.net> <174972.29079.qm@web57607.mail.re1.yahoo.com> <49ED066A.6050504@noaa.gov> Message-ID: <368a5cd50904221231v5e04990j85adb8644143d45@mail.gmail.com> On Tue, Apr 21, 2009 at 1:34 AM, Christopher Barker wrote: > the glory (or, one of the glories) or numpy is that you don't have to > loop, you can operate in the whole array as a unit. Or use PIL's "point" method, which does this in no time at all without having to roundtrip all the data through yet another library... > Also, the new gif is twice as big as the old -- is it not compressed the > same way? The LZW patent expired in 2004, but Unisys still claims to have patents that cover some uses of it, and nobody's yet contributed a patent-free replacement for the alternative compression method used by PIL. GIF is a dead format anyway; I'd recommend using PNG instead. From kevincastiglione at gmail.com Thu Apr 23 01:24:34 2009 From: kevincastiglione at gmail.com (Kevin Castiglione) Date: Wed, 22 Apr 2009 16:24:34 -0700 Subject: [Image-SIG] pencil sketches Message-ID: hi guys i want to generate pencil sketch sort of effect on images with faces in images. is it possible to do this effect in PIL? thanks From paj at pajhome.org.uk Thu Apr 23 03:45:05 2009 From: paj at pajhome.org.uk (Paul Johnston) Date: Thu, 23 Apr 2009 08:45:05 +0700 Subject: [Image-SIG] Resizing Photos In-Reply-To: References: Message-ID: Hi, Scratch that - I found the ANTIALIAS mode and the thumbnails are now much better quality. Thanks for a great lib! Paul On Tue, Apr 21, 2009 at 9:11 AM, Paul Johnston wrote: > Hi, > > I'm currently using PIL to resize photos down to a thumbnail. Something > I've noticed though, is that whatever software Facebook use too do the same, > produces better-quality thumbnails. > > Are there any tweaks I can apply to PIL to get better resizing? Or any idea > what software FB may be using? > > Paul > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eismb at hotmail.com Thu Apr 23 00:58:59 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Wed, 22 Apr 2009 22:58:59 +0000 Subject: [Image-SIG] grayscale image: find darkest pixel and delete lighter ones Message-ID: Hi! I wonder if it is possible to do something like the following with the Python Imaging library: for pixel in image: get how close to black it is register what would be the darkest shade found in the image delete pixels lighter than the darkest. I'm asking because I scanned a bunch of pages from a book to .jpg. The images are in grayscale, and some pages have tables with gray background "underneath" black text, and I wanted to get rid of the background. Thanks, Eduardo _________________________________________________________________ Descubra seu lado desconhecido com o novo Windows Live! http://www.windowslive.com.br -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Thu Apr 23 15:42:22 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Thu, 23 Apr 2009 15:42:22 +0200 Subject: [Image-SIG] grayscale image: find darkest pixel and delete lighter ones In-Reply-To: References: Message-ID: <368a5cd50904230642r6fc60f6cvf4e0a6c8cff1c215@mail.gmail.com> On Thu, Apr 23, 2009 at 12:58 AM, Eduardo Ismael wrote: > Hi! > I wonder if it is possible to do something like the following with the > Python Imaging library: > > for pixel in image: > ??? get how close to black it is > register what would be the darkest shade found in the image > delete pixels lighter than the darkest. to get the darkest color in the image, use: lo, hi = im.getextrema() you can then create a lookup table that maps everything above lo plus a small margin to white: lut = [0]*256 # all black for ix in range(lo + 10, 256): lut[ix] = 255 # make everything from lo+10 to 255 white and use the "point" method to translate the whole image: im = im.point(lut) tweak as necessary. From jcupitt at gmail.com Thu Apr 23 18:21:56 2009 From: jcupitt at gmail.com (jcupitt at gmail.com) Date: Thu, 23 Apr 2009 17:21:56 +0100 Subject: [Image-SIG] grayscale image: find darkest pixel and delete lighter ones In-Reply-To: References: Message-ID: <522c6460904230921s734dcbfdmf7b9b611c040373f@mail.gmail.com> 2009/4/22 Eduardo Ismael : > I'm asking because I scanned a bunch of pages from a book to .jpg. The > images are in grayscale, and some pages have tables with gray background > "underneath" black text, and I wanted to get rid of the background. You'll probably find that the gray is a half-tone: zoom in and you'll see it's a pattern of tiny dots rather than a smooth gray. This is quite hard to remove well. One solution is to blur the image to remove the dots (you need a blur radius that's about twice the dot spacing, and you need a really high res scan), then find all pixels with about that grey level, and set all those pixels in the unblurred image to white. You'll find it doesn't work too well along the edges of text, and you may need to start using morphologies to shrink or grow the mask a bit. And even then it won't be great. You'd probably need to filter in Fourier space to really remove it, and that needs a hge amount of CPU and memory (minutes per page). John From jdmain at comcast.net Sat Apr 25 00:45:06 2009 From: jdmain at comcast.net (J.D. Main) Date: Fri, 24 Apr 2009 16:45:06 -0600 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <368a5cd50904221231v5e04990j85adb8644143d45@mail.gmail.com> References: <49E9954A.30210.664481F@jdmain.comcast.net>, <49ED066A.6050504@noaa.gov>, <368a5cd50904221231v5e04990j85adb8644143d45@mail.gmail.com> Message-ID: <49F1EC92.22353.26F9464F@jdmain.comcast.net> Hi Fredrik, You're right about GIF being dead but that's what the Weather Service uses. GIF image transparency always works though and that's what I need for this application. I'm placing the Radar images over the top of GIS map layers. Question: I tried to use the point method and kept getting errors. I guess I wasn't using proper syntax. How would you do it? By the way, PIL is very handy. Thanks! J.D. From cannon.el at gmail.com Fri Apr 24 22:40:19 2009 From: cannon.el at gmail.com (Laura & Edward Cannon) Date: Fri, 24 Apr 2009 13:40:19 -0700 Subject: [Image-SIG] pencil sketches In-Reply-To: References: Message-ID: Theoretically yes, easily no. On Wed, Apr 22, 2009 at 4:24 PM, Kevin Castiglione < kevincastiglione at gmail.com> wrote: > hi guys > i want to generate pencil sketch sort of effect on images with faces in > images. > is it possible to do this effect in PIL? > thanks > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From eismb at hotmail.com Sat Apr 25 07:14:49 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Sat, 25 Apr 2009 05:14:49 +0000 Subject: [Image-SIG] Removing specific range of colors from scanned image Message-ID: Hi, I scanned a color page from a book and I would like to remove specific colors from it. The page was scanned at 300dpi. Suppose I wanted to remove the blue color of the image; because the quality of the color is not even, I had the blue color in different levels, apparently from (185, 208, 231) to (207, 240, 255) - I used "Little RGB Color Picker" to find that out. I tried the following: [code] im = Image.open("C:\Scan_119.jpg") im.show() pixels = im.load() width, height = im.size for x in range(width): for y in range(height): if pixels[x, y] >= (185, 208, 231): if pixels[x, y] <= (207, 240, 255): pixels[x, y] = (255, 255, 255) [\code] But it had little success removing the blue color - I suppose due to the complexity of stablishing a range between two tuples of 3 values. How can I efficiently set a color range to be found or removed with PIL? Is there an algorithm to find such range? Thanks, Eduardo _________________________________________________________________ Fa?a j? uma busa e ganhe um wink do Messenger. Est? esperando o que? ? gr?tis! http://www.ibud.com.br/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From eismb at hotmail.com Sat Apr 25 15:00:39 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Sat, 25 Apr 2009 13:00:39 +0000 Subject: [Image-SIG] using getcolors( ) properly Message-ID: Hi, I had no success using im.getcolors(). I now there is something you have to do to avoid getting None as a result, but I could not understand the following from the manual: "To make sure you get all colors in an image, you can pass in size[0]*size[1]" Can anyone give an example of passing in "size[0]*size[1]"? _________________________________________________________________ Messenger 2009: Instale j?! http://download.live.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From eismb at hotmail.com Sun Apr 26 22:51:22 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Sun, 26 Apr 2009 20:51:22 +0000 Subject: [Image-SIG] PIL - representing shades of colors in a linear way Message-ID: Is it possible to represent all the RGB different colors in a linear way, instead of by a tuple (R, G, B)? I am asking because I want to delete all shades of blue in an image, like (0, 0, 255) and (51, 0, 255), for example. The problem is that if I set a range using < and >, (see below) it is going to affect other colors in between, like (51, 0, 0), which is far from being blue. here is the code that is not working properly: for x in range(width): for y in range(height): if pixels[x, y] >= (0, 0, 255): if pixels[x, y] <= (51, 0, 255): pixels[x, y] = (255, 255, 255) If I could represent all the shades of a particular color in a linear way, then using < and > would work. Also, the images I am working with were scanned so that's the reason way the pixels don't have an even color. I am open to other solutions as well. Thanks, Eduardo _________________________________________________________________ Messenger 2009: Instale j?! http://download.live.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From eismb at hotmail.com Sun Apr 26 22:53:40 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Sun, 26 Apr 2009 20:53:40 +0000 Subject: [Image-SIG] PIL - problem with crop() Message-ID: Hi! I have a bunch of .jpg images of 2866 x 4047. When I right-click on them and use the "Convert to Adobe PDF" option from Acrobat, an Acrobat window opens showing the document with great quality and zoom of 121% - and if I zoom down to 100%, it looks like the original quality. However, I would like to crop the bottom of all pages before conveting to PDF, so i get back to the original and use "im.crop((0, 0, 2866, 3760))". Now, if I use the method above to convert to PDF, the PDF will open at 21,9% - the image got much bigger! - and if I zoom up to 100%, it gets awful. I understand PIl is not only cropping the image, but also affecting its quality. Any suggestions on how to avoid that? Here is the complete script: import os, Image preCropFolder = "C:\\PDF\\preCropFolder" postCropFolder = "C:\\PDF\\postCropFolder" inputImages = os.listdir(preCropFolder) for file in inputImages: eachImage = preCropFolder + "\\" + file im = Image.open(eachImage) im = im.crop((0, 0, 2866, 3760)) # original is 2866 x 4047 eachImage = postCropFolder + "\\" + file _________________________________________________________________ Novo Windows Live: Messenger 2009 e muito mais. Descubra! http://www.windowslive.com.br -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcupitt at gmail.com Mon Apr 27 12:56:00 2009 From: jcupitt at gmail.com (jcupitt at gmail.com) Date: Mon, 27 Apr 2009 11:56:00 +0100 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: References: Message-ID: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> 2009/4/25 Eduardo Ismael : > I scanned a color page from a book and I would like to remove specific > colors from it. The best solution is to calculate a colour difference metric. This is rather like the 'magic wand' in most paint programs. RGB isn't the best colour space for this, but it would sort-of work. The idea is: imagine that your three colour values are coordinates in a cube. You want to find pixels whose value is close to the position of a point in the blue corner of this cube, in other words, something like: for pixel in image: if distance (image[pixel], blue) < 10: image[pixel] = white The simplest distance function is just pythagoras, ie. def distance (a, b): vector = a - b return (vector.red ** 2 + vector.green ** 2 + vector.blue ** 2) ** 0.5 You can do this efficiently by processing at the image level rather than by looping over pixels (always incredibly slow). So: calculate an image where each pixel is the distance function for that point, then threshold and use that mask to set sections of your original image to white. John From fredrik at pythonware.com Mon Apr 27 13:44:31 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 27 Apr 2009 13:44:31 +0200 Subject: [Image-SIG] using getcolors( ) properly In-Reply-To: References: Message-ID: <368a5cd50904270444n60701b9chea2e504bc1256648@mail.gmail.com> On Sat, Apr 25, 2009 at 3:00 PM, Eduardo Ismael wrote: > I had no success using im.getcolors(). I now there is something you have to > do to avoid getting None as a result, but I could not understand the > following from the manual: > > "To make sure you get all colors in an image, you can pass in > size[0]*size[1]" > > Can anyone give an example of passing in "size[0]*size[1]"? "size" refers to the size attribute of the image object. to prevent unexpected memory/cpu blowup, getcolors() expects you to specify the maximum number of colors you want. the default is 256 colors (8 bits); the worst case is obviously the number of pixels in the image, which you can get by multiplying the width by the height. im = .... some image ... size = im.size colors = im.getcolors(size[0]*size[1]) From mark.wendell at gmail.com Mon Apr 27 15:00:32 2009 From: mark.wendell at gmail.com (Mark Wendell) Date: Mon, 27 Apr 2009 07:00:32 -0600 Subject: [Image-SIG] pencil sketches In-Reply-To: References: Message-ID: If what you mean by 'pencil sketch' is some sort of algorithmic redrawing of an image as a series of 'strokes' that look like they were hand-drawn, then like the Cannons said, theoretically yes, but the challenge is this: you'll need to come up with an algorithm that decides where each stroke goes based on some kind of 'feature analysis' of the imagery. You might want to look for contours in the image, for example. Then you'll need to decide, given the contours, how and where to place lines that look like pencil strokes. This can be done by picking pixels at random and following along a contour, or by any number of other random or deterministic methods. You'll have to worry about how long strokes are, what color and 'texture' they have, how well they follow contours or other features, and a myriad other aspects. PIL is a general-purpose imaging and drawing toolset. As such, it doesn't do all this together for you, it just provides the low-level calls you'd need to assemble something like this. The weakest part of PIL, I'd imagine, is the drawing tools if you want to have a papery texture to the pencil strokes. In any case, this is a fun but non-trivial task. I'd recommend doing some googling on topics like "non photorealistic rendering". Mark On Fri, Apr 24, 2009 at 2:40 PM, Laura & Edward Cannon wrote: > > Theoretically yes, easily no. > > On Wed, Apr 22, 2009 at 4:24 PM, Kevin Castiglione wrote: >> >> hi guys >> i want to generate pencil sketch sort of effect on images with faces in images. >> is it possible to do this effect in PIL? >> thanks >> _______________________________________________ >> Image-SIG maillist ?- ?Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig > > > _______________________________________________ > Image-SIG maillist ?- ?Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > -- -- Mark Wendell mark.wendell at gmail.com From fredrik at pythonware.com Mon Apr 27 15:19:52 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon, 27 Apr 2009 15:19:52 +0200 Subject: [Image-SIG] Remove Noise from a National Weather Service Radar Image (.gif) In-Reply-To: <49F1EC92.22353.26F9464F@jdmain.comcast.net> References: <49E9954A.30210.664481F@jdmain.comcast.net> <49ED066A.6050504@noaa.gov> <368a5cd50904221231v5e04990j85adb8644143d45@mail.gmail.com> <49F1EC92.22353.26F9464F@jdmain.comcast.net> Message-ID: <368a5cd50904270619s5c2b316do93e88ca2408d7bd0@mail.gmail.com> On Sat, Apr 25, 2009 at 12:45 AM, J.D. Main wrote: > Hi Fredrik, > > You're right about GIF being dead but that's what the Weather Service uses. > GIF image transparency always works though and that's what I need for this > application. ?I'm placing the Radar images over the top of GIS map layers. > > Question: ?I tried to use the point method and kept getting errors. ?I guess I > wasn't using proper syntax. ?How would you do it? Didn't I post a code outline earlier? What errors are you getting? From g.kloss at massey.ac.nz Mon Apr 27 21:24:40 2009 From: g.kloss at massey.ac.nz (Guy K. Kloss) Date: Tue, 28 Apr 2009 07:24:40 +1200 Subject: [Image-SIG] PIL - problem with crop() In-Reply-To: References: Message-ID: <200904280724.40481.g.kloss@massey.ac.nz> On Mon, 27 Apr 2009 08:53:40 Eduardo Ismael wrote: > Now, if I use the method above to convert to PDF, the PDF will open at > 21,9% - the image got much bigger! - and if I zoom up to 100%, it gets > awful. I understand PIl is not only cropping the image, but also affecting > its quality. As far as I'm assuming it is *not* tinkering with its quality. I'm assuming that it is changing the resolution (in dpi == dots per inch) inside the JPEG header. Adobe Acrobat is a programme that has its history in the graphic arts industry, and there resolution is *not* just X pixels by Y pixels, but also towards absolute sizes of the image in output. So setting the display to 100% will try to yield the image's representation in terms of absolute size on your screen together with the (estimated) screen resolution (again in dpi). So this did not change the physical number of pixels, but just the attached meta information of the resolution in the image's header. Hope that helps to understand the effect, Guy -- Guy K. Kloss Institute of Information and Mathematical Sciences Te Kura P?taiao o M?hiohio me P?ngarau Room 2.63, Quad Block A Building Massey University, Auckland, Albany Private Bag 102 904, North Shore Mail Centre voice: +64 9 414-0800 ext. 9585 fax: +64 9 441-8181 eMail: G.Kloss at massey.ac.nz http://iims.massey.ac.nz From g.kloss at massey.ac.nz Mon Apr 27 21:33:24 2009 From: g.kloss at massey.ac.nz (Guy K. Kloss) Date: Tue, 28 Apr 2009 07:33:24 +1200 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> Message-ID: <200904280733.25125.g.kloss@massey.ac.nz> On Mon, 27 Apr 2009 22:56:00 jcupitt at gmail.com wrote: > RGB isn't the best colour space for this, but it would sort-of work. Another issue is that RGB is (usually when encountered "in the wild") the sRGB colour space. sRGB as well as most other RGB colour spaces is *not* a linear colour encoding per channel. They have been encoded with a geometrical function with an exponent of (in the case of sRGB) about 2.2. This is a historical effect to compensate for the non-linearity of CRT (cathode ray tube) based screens. If you want to be at least "sort of" linear, you need to undo the gamma compensation first: c' = c ** (1 / gamma) gamma: the gamma coefficient, usually in the case of sRGB = 2.2 c': linearised RGB colour channel c: un-linearised (s)RGB colour channel Now you can perform quantitative sensible computations on the R'G'B' colour tuples, like comparing colour distance as the Euclidean distance mentioned in John's post. Guy -- Guy K. Kloss Institute of Information and Mathematical Sciences Te Kura P?taiao o M?hiohio me P?ngarau Room 2.63, Quad Block A Building Massey University, Auckland, Albany Private Bag 102 904, North Shore Mail Centre voice: +64 9 414-0800 ext. 9585 fax: +64 9 441-8181 eMail: G.Kloss at massey.ac.nz http://iims.massey.ac.nz From jcupitt at gmail.com Tue Apr 28 10:14:38 2009 From: jcupitt at gmail.com (jcupitt at gmail.com) Date: Tue, 28 Apr 2009 09:14:38 +0100 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> Message-ID: <522c6460904280114n3b612912h85fc498b7f68672a@mail.gmail.com> Hi Eduardo, 2009/4/28 Eduardo Ismael : > Would you please make comments on what I could do to improve the code below? You could make it hundreds of times faster if you calculate with images, not pixels. But maybe it's fast enough already? It depends on your needs. CIELAB would be a better colour space than RGB, but I don't think PIL supports CIELAB colour space, so you'd need to look into another image processing system, like numpy or vips. John From eismb at hotmail.com Tue Apr 28 05:31:02 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Tue, 28 Apr 2009 03:31:02 +0000 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> Message-ID: Thank you very much for your feedback, John. It works wonders!!! Would you please make comments on what I could do to improve the code below? im = Image.open("C:\Scan_119.jpg") pixels = im.load() width, height = im.size def distance (a, b): return ((a[0]- b[0])** 2 + (a[1]- b[1])** 2 + (a[-1]- b[-1]) ** 2) ** 0.5 blue = (205, 241, 255) # a value I am presuming would be the average blue in the image for x in range(width): for y in range(height): if distance(pixels[x, y], blue) < 50: pixels[x, y] = (255, 255, 255) I guess I got the main idea, but please tell me if there is anything I could do to improve it. Also, I don't think I followed your advice on "processing at the image level rather than by looping over pixels" Would you correct it for me? By the way, thanks to your explanation of the color cube approach, I was able to come up with this other script: im = Image.open("C:\Scan_119.jpg") pixels = im.load() width, height = im.size for x in range(width): for y in range(height): if pixels[x, y][0] <= 210: # Red above 210 tended not to create blue # Green could be ignored in this case, i guess if pixels[x, y][-1] >= 170: # Blue under 170 seemed to be around the image's blue pixels[x, y] = (255, 255, 255) which affected what I would call purple a bit, but it was quite precise otherwise. Well, I guess it just needs some adjusting. I came up with R210 and B170 after looking at a color cube I adapted. What method you suggest I should stick to - in other words, which one seems to bring more accuracy? Also, If not RGB, which color space would be the best? > From: jcupitt at gmail.com > Date: Mon, 27 Apr 2009 11:56:00 +0100 > Subject: Re: [Image-SIG] Removing specific range of colors from scanned image > To: eismb at hotmail.com > CC: image-sig at python.org > > 2009/4/25 Eduardo Ismael : > > I scanned a color page from a book and I would like to remove specific > > colors from it. > > The best solution is to calculate a colour difference metric. This is > rather like the 'magic wand' in most paint programs. > > RGB isn't the best colour space for this, but it would sort-of work. > The idea is: imagine that your three colour values are coordinates in > a cube. You want to find pixels whose value is close to the position > of a point in the blue corner of this cube, in other words, something > like: > > for pixel in image: > if distance (image[pixel], blue) < 10: > image[pixel] = white > > The simplest distance function is just pythagoras, ie. > > def distance (a, b): > vector = a - b > return (vector.red ** 2 + vector.green ** 2 + vector.blue ** 2) ** 0.5 > > You can do this efficiently by processing at the image level rather > than by looping over pixels (always incredibly slow). So: calculate an > image where each pixel is the distance function for that point, then > threshold and use that mask to set sections of your original image to > white. > > John _________________________________________________________________ Novo Windows Live: Messenger 2009 e muito mais. Descubra! http://www.windowslive.com.br -------------- next part -------------- An HTML attachment was scrubbed... URL: From eismb at hotmail.com Tue Apr 28 05:47:23 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Tue, 28 Apr 2009 03:47:23 +0000 Subject: [Image-SIG] PIL - problem with crop() In-Reply-To: References: Message-ID: Thank you, Kevin - the image got much better. JPG accepts the "quality" tag (ex.: quality=95). Still, as someone pointed out, it seems I should try other formats like TIFF or PNG. Eduardo CC: image-sig at python.org From: kevin at cazabon.com To: eismb at hotmail.com Subject: Re: [Image-SIG] PIL - problem with crop() Date: Mon, 27 Apr 2009 06:58:36 -0400 are you setting the resolution when re-saving as a PDF in PIL? That would explain the scaling issue, and likely the quality too. PIL now supports resolution settings for most common file formats - add a dpi=300 tag when saving, for example: im.save("test.pdf", dpi=300) Kevin. On 26 Apr 2009, at 16:53, Eduardo Ismael wrote:Hi! I have a bunch of .jpg images of 2866 x 4047. When I right-click on them and use the "Convert to Adobe PDF" option from Acrobat, an Acrobat window opens showing the document with great quality and zoom of 121% - and if I zoom down to 100%, it looks like the original quality. However, I would like to crop the bottom of all pages before conveting to PDF, so i get back to the original and use "im.crop((0, 0, 2866, 3760))". Now, if I use the method above to convert to PDF, the PDF will open at 21,9% - the image got much bigger! - and if I zoom up to 100%, it gets awful. I understand PIl is not only cropping the image, but also affecting its quality. Any suggestions on how to avoid that? Here is the complete script: import os, Image preCropFolder = "C:\\PDF\\preCropFolder" postCropFolder = "C:\\PDF\\postCropFolder" inputImages = os.listdir(preCropFolder) for file in inputImages: eachImage = preCropFolder + "\\" + file im = Image.open(eachImage) im = im.crop((0, 0, 2866, 3760)) # original is 2866 x 4047 eachImage = postCropFolder + "\\" + file Quer saber qual produto Windows Live combina melhor com o seu perfil? Clique aqui e descubra! _______________________________________________ Image-SIG maillist - Image-SIG at python.org http://mail.python.org/mailman/listinfo/image-sig _________________________________________________________________ Emoticons e Winks super diferentes para o Messenger. Baixe agora, ? gr?tis! http://specials.br.msn.com/ilovemessenger/pacotes.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From eismb at hotmail.com Tue Apr 28 05:49:12 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Tue, 28 Apr 2009 03:49:12 +0000 Subject: [Image-SIG] using getcolors( ) properly In-Reply-To: <368a5cd50904270444n60701b9chea2e504bc1256648@mail.gmail.com> References: <368a5cd50904270444n60701b9chea2e504bc1256648@mail.gmail.com> Message-ID: Thanks, Fredrik - it finally works. > From: fredrik at pythonware.com > Date: Mon, 27 Apr 2009 13:44:31 +0200 > Subject: Re: [Image-SIG] using getcolors( ) properly > To: eismb at hotmail.com > CC: image-sig at python.org > > On Sat, Apr 25, 2009 at 3:00 PM, Eduardo Ismael wrote: > > > I had no success using im.getcolors(). I now there is something you have to > > do to avoid getting None as a result, but I could not understand the > > following from the manual: > > > > "To make sure you get all colors in an image, you can pass in > > size[0]*size[1]" > > > > Can anyone give an example of passing in "size[0]*size[1]"? > > "size" refers to the size attribute of the image object. > > to prevent unexpected memory/cpu blowup, getcolors() expects you to > specify the maximum number of colors you want. the default is 256 > colors (8 bits); the worst case is obviously the number of pixels in > the image, which you can get by multiplying the width by the height. > > im = .... some image ... > size = im.size > colors = im.getcolors(size[0]*size[1]) > > _________________________________________________________________ Messenger 2009: Instale j?! http://download.live.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From patrick.tresset at yahoo.fr Tue Apr 28 14:30:39 2009 From: patrick.tresset at yahoo.fr (Patrick Tresset) Date: Tue, 28 Apr 2009 12:30:39 +0000 (GMT) Subject: [Image-SIG] pencil sketches Message-ID: <205533.42618.qm@web28007.mail.ukl.yahoo.com> Hello, ?As far as I can remember, you can use from python all the GIMP classes, ?I am not talking about the GIMP plug-in scripting.? You could look at www.aikon-gold.com (phase one). There are? links to a couple of papers I have written on the site. I hope this is useful. I'll be happy to answer further questions. PatrickT p.tresset at gold.ac.uk --- En date de?: Mar 28.4.09, image-sig-request at python.org a ?crit?: ???2. Re: pencil sketches (Mark Wendell) ?? ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcupitt at gmail.com Tue Apr 28 17:31:49 2009 From: jcupitt at gmail.com (jcupitt at gmail.com) Date: Tue, 28 Apr 2009 16:31:49 +0100 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> <522c6460904280114n3b612912h85fc498b7f68672a@mail.gmail.com> Message-ID: <522c6460904280831y72e24883ie76e4d272babcbb7@mail.gmail.com> 2009/4/28 Eduardo Ismael : > I'm having trouble thinking out of the "for pixel in image" loop. Is it > possible to calculate with images and not pixels with PIL? Yes, but the range of operations is a little limited. Numpy would be easier, if you know that. I know vips well (I'm one of the maintainers) so I tried in that. On my machine (2.7 GHz amd64), this runs in about 3 seconds and needs 20mb of RAM for a 5,000 x 5,000 pixel TIFF: ---------------- from vipsCC import * filename = "bench/wtc_tiled_small.tif" # set all pixels within threshold of blue to 255 blue = [157, 196, 230] threshold = 10 im = VImage.VImage (filename) # calculate (im - blue) # b = a.lin (x, y) finds (b = a * x + y) for each pixel # we have to invert our blue values to get subtract diff = im.lin ([1,1,1], [x * -1 for x in blue]) # square each pixel sq = diff.multiply (diff) # break into three bands, then sum # vips has a split operator, but it's not wrapped in Python, # sadly r = sq.extract_band (0) g = sq.extract_band (1) b = sq.extract_band (2) sum = r.add (b.add(b)) # sqrt each pixel sq = sum.pow (0.5) # now find pixels within a certain distance of our blue point # we get an 8-bit mono image where 255 is "within threshold" mask = sq.less (threshold) # make the image we get the replacement pixels from # we need an image the same size as im, but with [255, 255, 255] for each # pixel # make a black image, add 255, then clip to 8-bit uchar black = VImage.VImage.black (im.Xsize (), im.Ysize (), 3) white = black.lin (1, 255).clip () # and use the mask to pick white or image pixels result = mask.ifthenelse (replace, im) result.write ("test.tif") ----------------- vips has cielab, so you can try that colour space as well. This takes about 5s/20mb. -------------- from vipsCC import * filename = "bench/wtc_tiled_small.tif" # set all pixels within threshold of blue to 255 blue = [157, 196, 230] threshold = 10 im = VImage.VImage (filename) # make a CIELAB image of the blue colour black = VImage.VImage.black (im.Xsize (), im.Ysize (), 3) blue_lab_im = black.lin ([1,1,1], blue).clip ().sRGB2XYZ ().XYZ2Lab () # turn our image to CIELAB as well lab_im = im.sRGB2XYZ ().XYZ2Lab () # find the colour difference diff = lab_im.dE_fromLab (blue_lab_im) # threshold to get a mask image mask = diff.less (threshold) # make a white rgb image white = black.lin (1, 255).clip () # and use the mask to pick white or image pixels result = mask.ifthenelse (white, im) result.write ("test.tif") -------------- J From eismb at hotmail.com Tue Apr 28 16:13:20 2009 From: eismb at hotmail.com (Eduardo Ismael) Date: Tue, 28 Apr 2009 14:13:20 +0000 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: <522c6460904280114n3b612912h85fc498b7f68672a@mail.gmail.com> References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> <522c6460904280114n3b612912h85fc498b7f68672a@mail.gmail.com> Message-ID: Thanks, John - I'll have a look at numpy and vips (and CIELAB) right away. I'm having trouble thinking out of the "for pixel in image" loop. Is it possible to calculate with images and not pixels with PIL? Eduardo > From: jcupitt at gmail.com > Date: Tue, 28 Apr 2009 09:14:38 +0100 > Subject: Re: [Image-SIG] Removing specific range of colors from scanned image > To: eismb at hotmail.com > CC: image-sig at python.org > > Hi Eduardo, > > 2009/4/28 Eduardo Ismael : > > Would you please make comments on what I could do to improve the code below? > > You could make it hundreds of times faster if you calculate with > images, not pixels. But maybe it's fast enough already? It depends on > your needs. > > CIELAB would be a better colour space than RGB, but I don't think PIL > supports CIELAB colour space, so you'd need to look into another image > processing system, like numpy or vips. > > John _________________________________________________________________ Novo Windows Live: Messenger 2009 e muito mais. Descubra! http://www.windowslive.com.br -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Tue Apr 28 18:21:12 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 28 Apr 2009 18:21:12 +0200 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> <522c6460904280114n3b612912h85fc498b7f68672a@mail.gmail.com> Message-ID: <368a5cd50904280921y18f4e373uf3547a3e35f431c2@mail.gmail.com> On Tue, Apr 28, 2009 at 4:13 PM, Eduardo Ismael wrote: > Thanks, John - I'll have a look at numpy and vips (and CIELAB) right away. > > I'm having trouble thinking out of the "for pixel in image" loop. Is it > possible to calculate with images and not pixels with PIL? Sure - the trick is to figure out how to express your problem in terms of the basic operations provided by the Image object itself, by the ImageChops or ImageOps modules (which should be merged some day), etc. And in 1.1.6 and later, there's also the ImageMath module. http://effbot.org/imagingbook/imagemath.htm To do a distance calculation, you could do something like: target = (red, green, blue) distance = 10 # calculate a distance mask R, G, B = target r, g, b = im.split() distance3 = distance ** 3 mask = ImageMath.eval( "convert(((abs(r - R)*abs(g - G)*abs(b - B)) < distance3)*255, 'L')", **locals()) # paste in some nice color on pixels that are "close" to the target color im.paste("white", mask) (no time to do benchmarking and detailed testing, but the above should be fairly efficient) From Scott.Daniels at Acm.Org Tue Apr 28 20:35:59 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 28 Apr 2009 11:35:59 -0700 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> Message-ID: Eduardo Ismael wrote: > Thank you very much for your feedback, John. It works wonders!!! > > Would you please make comments on what I could do to improve the code below? > def distance (a, b): > return ((a[0]- b[0])** 2 + (a[1]- b[1])** 2 + (a[-1]- b[-1]) ** 2) > ** 0.5 The square root here is not free. A standard trick is to realize that, if you are going to test distance(...) < constant, you can, instead, calculate distance_squared: def distance_squared(a, b): return sum((ac - bc)**2 for ac, bc in zip(a, b)) and compare it to constant_squared. So that your code later: > for x in range(width): > for y in range(height): > if distance_squared(pixels[x, y], blue) < 2500: > pixels[x, y] = (255, 255, 255) While this trick won't make that code sufficiently fast, it is a good trick to know. > I guess I got the main idea, but please tell me if there is anything I > could do to improve it. Also, I don't think I followed your advice on > "processing at the image level rather than by looping over pixels" Would > you correct it for me? > > By the way, thanks to your explanation of the color cube approach, I was > able to come up with this other script: > ... Also, If not RGB, which color space would be the best? HLS (Hue, Lightness, Saturation) is an interesting space, with the hue picked out for you (as long as you avoid the extrema in lightness and the near-zero saturation points). --Scott David Daniels Scott.Daniels at Acm.Org From Scott.Daniels at Acm.Org Tue Apr 28 20:58:00 2009 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 28 Apr 2009 11:58:00 -0700 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: <368a5cd50904280921y18f4e373uf3547a3e35f431c2@mail.gmail.com> References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> <522c6460904280114n3b612912h85fc498b7f68672a@mail.gmail.com> <368a5cd50904280921y18f4e373uf3547a3e35f431c2@mail.gmail.com> Message-ID: Fredrik Lundh wrote: > On Tue, Apr 28, 2009 at 4:13 PM, Eduardo Ismael wrote: >> Thanks, John - I'll have a look at numpy and vips (and CIELAB) right away. >> >> I'm having trouble thinking out of the "for pixel in image" loop. Is it >> possible to calculate with images and not pixels with PIL? > > Sure - the trick is to figure out how to express your problem in terms > of the basic operations provided by the Image object itself, by the > ImageChops or ImageOps modules (which should be merged some day), etc. > > And in 1.1.6 and later, there's also the ImageMath module. > > http://effbot.org/imagingbook/imagemath.htm > > To do a distance calculation, you could do something like: > > target = (red, green, blue) > distance = 10 > > # calculate a distance mask > R, G, B = target > r, g, b = im.split() > distance3 = distance ** 3 > > mask = ImageMath.eval( > "convert(((abs(r - R)*abs(g - G)*abs(b - B)) < distance3)*255, 'L')", > **locals()) > > # paste in some nice color on pixels that are "close" to the target color > im.paste("white", mask) Warning: this distance function is the product of the three elements, so an exact match on red, green, or blue will look like a match on all. Try something like this: distance2 = 3 * distance ** 2 mask = ImageMath.eval("convert((((r-R)**2 + (g-G)**2 + (b-B)**2) " " < distance2) * 255, 'L')", **locals()) --Scott David Daniels Scott.Daniels at Acm.Org From fredrik at pythonware.com Tue Apr 28 21:18:23 2009 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 28 Apr 2009 21:18:23 +0200 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> <522c6460904280114n3b612912h85fc498b7f68672a@mail.gmail.com> <368a5cd50904280921y18f4e373uf3547a3e35f431c2@mail.gmail.com> Message-ID: <368a5cd50904281218n3ff25197tea6524ef4eb147e0@mail.gmail.com> On Tue, Apr 28, 2009 at 8:58 PM, Scott David Daniels wrote: > Warning: this distance function is the product of the three elements, > so an exact match on red, green, or blue will look like a match on all. > > Try something like this: > ? ? distance2 = 3 * distance ** 2 > ? ? mask = ImageMath.eval("convert((((r-R)**2 + (g-G)**2 + (b-B)**2) " > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?" < distance2) * 255, 'L')", > ? ? ? ? ? ? ? ? ? ? ? ? ? **locals()) Yeah, brain was not fully engaged when I wrote that. Sorry for that, and thanks for fixing it. From jcupitt at gmail.com Tue Apr 28 21:33:25 2009 From: jcupitt at gmail.com (jcupitt at gmail.com) Date: Tue, 28 Apr 2009 20:33:25 +0100 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: <368a5cd50904280921y18f4e373uf3547a3e35f431c2@mail.gmail.com> References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> <522c6460904280114n3b612912h85fc498b7f68672a@mail.gmail.com> <368a5cd50904280921y18f4e373uf3547a3e35f431c2@mail.gmail.com> Message-ID: <522c6460904281233k210410cfp61d5f890fdcc1948@mail.gmail.com> 2009/4/28 Fredrik Lundh : > ? ?mask = ImageMath.eval( > ? ? ? ?"convert(((abs(r - R)*abs(g - G)*abs(b - B)) < distance3)*255, 'L')", > ? ? ? ?**locals()) > > ? ?# paste in some nice color on pixels that are "close" to the target color > ? ?im.paste("white", mask) > > (no time to do benchmarking and detailed testing, but the above should > be fairly efficient) Yes it's pretty quick. I didn't realise ImageMath was so fast, thank you for the example. John From Chris.Barker at noaa.gov Wed Apr 29 00:19:15 2009 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Tue, 28 Apr 2009 15:19:15 -0700 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: References: <522c6460904270356p6be1f8bbue55872a7745e464d@mail.gmail.com> Message-ID: <49F780E3.7010204@noaa.gov> Eduardo Ismael wrote: > im = Image.open("C:\Scan_119.jpg") > pixels = im.load() > width, height = im.size > > def distance (a, b): > return ((a[0]- b[0])** 2 + (a[1]- b[1])** 2 + (a[-1]- b[-1]) ** 2) > ** 0.5 I"m not sure there is any need to compute the sqrt here -- you can work in units of "distance" squared, instead, since you are doing thresholds. > blue = (205, 241, 255) # a value I am presuming would be the average > blue in the image That's not very blue! > Also, I don't think I followed your advice on > "processing at the image level rather than by looping over pixels" Would > you correct it for me? See the recent thread "Remove Noise from a National Weather Service Radar Image" to see how to convert to/from numpy arrays for this sort of thing. I prefer that approach to imagemath, but that may be because I am very familiar with numpy. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker at noaa.gov From g.kloss at massey.ac.nz Wed Apr 29 00:43:35 2009 From: g.kloss at massey.ac.nz (Guy K. Kloss) Date: Wed, 29 Apr 2009 10:43:35 +1200 Subject: [Image-SIG] Removing specific range of colors from scanned image In-Reply-To: References: Message-ID: <200904291043.35533.g.kloss@massey.ac.nz> On Wed, 29 Apr 2009 06:35:59 Scott David Daniels wrote: > HLS (Hue, Lightness, Saturation) is an interesting space, with the hue > picked out for you (as long as you avoid the extrema in lightness and > the near-zero saturation points). And you need to handle the transition of the hue through the boundaries of its extremes. Guy -- Guy K. Kloss Institute of Information and Mathematical Sciences Te Kura P?taiao o M?hiohio me P?ngarau Room 2.63, Quad Block A Building Massey University, Auckland, Albany Private Bag 102 904, North Shore Mail Centre voice: +64 9 414-0800 ext. 9585 fax: +64 9 441-8181 eMail: G.Kloss at massey.ac.nz http://iims.massey.ac.nz