From karsten.hiddemann at mathematik.uni-dortmund.de Wed Jul 2 11:30:20 2008 From: karsten.hiddemann at mathematik.uni-dortmund.de (Karsten Hiddemann) Date: Wed, 02 Jul 2008 11:30:20 +0200 Subject: [Image-SIG] Filtering out all but black pixels for OCR In-Reply-To: <000601c8da19$1f969920$08a305cf@Parents> References: <000601c8da19$1f969920$08a305cf@Parents> Message-ID: <486B4AAC.9040109@mathematik.uni-dortmund.de> Mike Meisner schrieb: > I'd like to use PIL to prep an image file to improve OCR quality. > > Specifically, I need to filter out all but black pixels from the image > (i.e., convert all non-black pixels to white while retaining the black > pixels). You could do something like the following: from PIL import Image img = Image.open("sample.png") (xdim, ydim) = img.size # this assumes that no alpha-channel is set black = (0, 0, 0) white = (255, 255, 255) if Image.VERSION >= "1.1.6": data = img.load() for y in range(ydim-1, 0, -1): for x in range(xdim): if data[x,y] != black: data[x,y] = white else: data = img.getdata() for y in range(ydim-1, 0, -1): for x in range(xdim): if data[x+y*xdim] != black: data[x+y*xdim] = white img.save("sample-filtered.png") From jcupitt at gmail.com Wed Jul 2 13:10:12 2008 From: jcupitt at gmail.com (jcupitt at gmail.com) Date: Wed, 2 Jul 2008 12:10:12 +0100 Subject: [Image-SIG] Filtering out all but black pixels for OCR In-Reply-To: <000601c8da19$1f969920$08a305cf@Parents> References: <000601c8da19$1f969920$08a305cf@Parents> Message-ID: <522c6460807020410g6b1f35fdxf33d732510fe7397@mail.gmail.com> 2008/6/29 Mike Meisner : > I'd like to use PIL to prep an image file to improve OCR quality. > > Specifically, I need to filter out all but black pixels from the image > (i.e., convert all non-black pixels to white while retaining the black > pixels). I realise you asked for PIL, but vips (another image processing library with a Python interface) can do this rather easily: ------- from vipsCC import * try: a = VImage.VImage ("some/image/file.format") b = a.notequal ([0,0,0]) b.write ("some/other/image/file.whatever") except VError.VError, e: e.perror (sys.argv[0]) ------- vips uses 0/255 to represent false/true, so the result of the notequal () method is an image which has 255 for all pixels which are not equal to [0,0,0], and zero for all pixels which are equal to [0,0,0]. This is assuming a 3-band image, of course. See: http://www.vips.ecs.soton.ac.uk/ The vips Python interface does not currently work on windows, might be a problem I guess. John From ned at nedbatchelder.com Wed Jul 2 13:43:59 2008 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 02 Jul 2008 07:43:59 -0400 Subject: [Image-SIG] Filtering out all but black pixels for OCR In-Reply-To: <486B4AAC.9040109@mathematik.uni-dortmund.de> References: <000601c8da19$1f969920$08a305cf@Parents> <486B4AAC.9040109@mathematik.uni-dortmund.de> Message-ID: <486B69FF.4020502@nedbatchelder.com> If your image is single-channel (mode "L"), then you can use the eval function: img = Image.open("onechannel.png") # at each pixel, if it isn't zero, make it 255.. better = Image.eval(img, lambda p: 255 * (int(p != 0))) better.save("bilevel.png") --Ned. http://nedbatchelder.com Karsten Hiddemann wrote: > Mike Meisner schrieb: >> I'd like to use PIL to prep an image file to improve OCR quality. >> >> Specifically, I need to filter out all but black pixels from the >> image (i.e., convert all non-black pixels to white while retaining >> the black pixels). > > You could do something like the following: > > from PIL import Image > > img = Image.open("sample.png") > (xdim, ydim) = img.size > # this assumes that no alpha-channel is set > black = (0, 0, 0) > white = (255, 255, 255) > > if Image.VERSION >= "1.1.6": > data = img.load() > for y in range(ydim-1, 0, -1): > for x in range(xdim): > if data[x,y] != black: > data[x,y] = white > else: > data = img.getdata() > for y in range(ydim-1, 0, -1): > for x in range(xdim): > if data[x+y*xdim] != black: > data[x+y*xdim] = white > > img.save("sample-filtered.png") > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > > > -- Ned Batchelder, http://nedbatchelder.com From karsten.hiddemann at mathematik.uni-dortmund.de Wed Jul 2 13:47:45 2008 From: karsten.hiddemann at mathematik.uni-dortmund.de (Karsten Hiddemann) Date: Wed, 02 Jul 2008 13:47:45 +0200 Subject: [Image-SIG] Filtering out all but black pixels for OCR In-Reply-To: <486B69FF.4020502@nedbatchelder.com> References: <000601c8da19$1f969920$08a305cf@Parents> <486B4AAC.9040109@mathematik.uni-dortmund.de> <486B69FF.4020502@nedbatchelder.com> Message-ID: <486B6AE1.8020807@mathematik.uni-dortmund.de> Ned Batchelder schrieb: > If your image is single-channel (mode "L"), then you can use the eval > function: > > img = Image.open("onechannel.png") > # at each pixel, if it isn't zero, make it 255.. > better = Image.eval(img, lambda p: 255 * (int(p != 0))) > better.save("bilevel.png") Ok, that's probably faster. In my code, instead of doing "y in range(ydim-1, 0, -1)" you could use "y in range(ydim)" instead, too, it was just taken from a program of mine where I needed to invert the orientation of the image. Fredrik has written something about the performance on pixel access with some timings here: http://effbot.org/zone/pil-pixel-access.htm Cheers, Karsten From mikem at blazenetme.net Wed Jul 2 16:58:21 2008 From: mikem at blazenetme.net (Mike Meisner) Date: Wed, 2 Jul 2008 10:58:21 -0400 Subject: [Image-SIG] Filtering out all but black pixels for OCR References: <000601c8da19$1f969920$08a305cf@Parents> <486B4AAC.9040109@mathematik.uni-dortmund.de> <486B69FF.4020502@nedbatchelder.com> Message-ID: <000c01c8dc54$126e6f10$08a305cf@Parents> Thank you all. This is very helpful. Mike ----- Original Message ----- From: "Ned Batchelder" To: "Karsten Hiddemann" Cc: "Mike Meisner" ; Sent: Wednesday, July 02, 2008 7:43 AM Subject: Re: [Image-SIG] Filtering out all but black pixels for OCR > If your image is single-channel (mode "L"), then you can use the eval > function: > > img = Image.open("onechannel.png") > # at each pixel, if it isn't zero, make it 255.. > better = Image.eval(img, lambda p: 255 * (int(p != 0))) > better.save("bilevel.png") > > --Ned. > http://nedbatchelder.com > > Karsten Hiddemann wrote: >> Mike Meisner schrieb: >>> I'd like to use PIL to prep an image file to improve OCR quality. >>> >>> Specifically, I need to filter out all but black pixels from the >>> image (i.e., convert all non-black pixels to white while retaining >>> the black pixels). >> >> You could do something like the following: >> >> from PIL import Image >> >> img = Image.open("sample.png") >> (xdim, ydim) = img.size >> # this assumes that no alpha-channel is set >> black = (0, 0, 0) >> white = (255, 255, 255) >> >> if Image.VERSION >= "1.1.6": >> data = img.load() >> for y in range(ydim-1, 0, -1): >> for x in range(xdim): >> if data[x,y] != black: >> data[x,y] = white >> else: >> data = img.getdata() >> for y in range(ydim-1, 0, -1): >> for x in range(xdim): >> if data[x+y*xdim] != black: >> data[x+y*xdim] = white >> >> img.save("sample-filtered.png") >> _______________________________________________ >> Image-SIG maillist - Image-SIG at python.org >> http://mail.python.org/mailman/listinfo/image-sig >> >> >> > > -- > Ned Batchelder, http://nedbatchelder.com > > > > From pydev at rscorp.ab.ca Wed Jul 2 18:44:15 2008 From: pydev at rscorp.ab.ca (Scott SA) Date: Wed, 2 Jul 2008 10:44:15 -0600 Subject: [Image-SIG] Image-SIG Digest, Vol 63, Issue 1 In-Reply-To: Message-ID: On 7/2/08, image-sig-request at python.org (image-sig-request at python.org) wrote: >I'd like to use PIL to prep an image file to improve OCR quality. > >Specifically, I need to filter out all but black pixels from the image (i.e., >convert all non-black pixels to white while retaining the black pixels). > >Can someone please direct me to the appropriate PIL function/method to >accomplish this along with a brief description of the correct arguments to use? I don't have the arguments to use, but the process is a bit more involved to enhance a bi-level image obtained through grayscale in order to get the best results (IMO). The best results I have seen are by applying a moderately strong 'S' curve with sharp shoulders, then applying two passes of unsharp masking, one with a large aperture and a subsequent with a lower-intensity and smaller aperture, then finally maping the to bit-level required by OCR (usually a threshold into a bitmap). Another trick, if you have the time is to scan at a higher resolution (in integer increments i.e. 2x, 3x, 4x so interpolation doesn't interfere), process the image as described then reduce the resolution to the optimum OCR res. I have to admit, this is from a while ago, I'm not sure what the current state of affairs is with OCR software (been 10 years, if a day, since I used any). Scott From donn.ingle at gmail.com Thu Jul 3 16:21:19 2008 From: donn.ingle at gmail.com (Donn) Date: Thu, 3 Jul 2008 16:21:19 +0200 Subject: [Image-SIG] "Point in polygon" test? In-Reply-To: <281938.49415.qm@web52104.mail.re2.yahoo.com> References: <281938.49415.qm@web52104.mail.re2.yahoo.com> Message-ID: <200807031621.19233.donn.ingle@gmail.com> > Hi! Does PIL have already implemented a method to return true/false > according as a provided point is inside a provided polygon? Thanks! I went through this a while back. The code pasted (sorry) is from a GTK and pyCairo point of view, but the algorithm you need is in the function hitTest. HTH \d #! /usr/bin/env python import pygtk pygtk.require('2.0') import gtk, gobject, cairo from gtk import gdk # Create a GTK+ widget on which we will draw using Cairo class Screen(gtk.DrawingArea): # Draw in response to an expose-event __gsignals__ = { "expose-event": "override" } def __init__(self): super(Screen,self).__init__() # gtk.Widget signals self.connect("button_press_event", self.button_press) self.connect("button_release_event", self.button_release) self.connect("motion_notify_event", self.motion_notify) # More GTK voodoo : unmask events self.add_events(gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.POINTER_MOTION_MASK) # Handle the expose-event by drawing def do_expose_event(self, event): # Create the cairo context cr = self.window.cairo_create() self.hitpath = None #Is set later # Restrict Cairo to the exposed area; avoid extra work cr.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) cr.clip() self.draw(cr, *self.window.get_size()) def makeHitPath(self,cairopath): ## Make a simpler list of tuples ## Internally, a cairo path looks like this: ## (0, (10.0, 10.0)) ## (1, (60.0, 10.0)) ## (1, (60.0, 60.0)) ## (1, (35.0, 60.0)) ## (1, (35.0, 35.0)) ## (1, (10.0, 35.0)) ## (1, (10.0, 60.0)) ## (1, (-40.0, 60.0)) ## (3, ()) #want to ignore this one ## (0, (10.0, 10.0)) self.hitpath = [] for sub in cairopath: if sub[1]: #kick out the close path () empty tuple self.hitpath.append(sub[1]) #list of tuples def draw(self, cr, width, height): # Fill the background with gray cr.set_source_rgb(0.5, 0.5, 0.5) cr.rectangle(0, 0, width, height) cr.fill() def hitTest(self,*p): ## Code lifted from http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ ## converted to Python. I won't pretend I grok it at all, just glad it works! ## Not sure how well it works yet, it might have edge flaws. px = p[0] py = p[1] counter = i = xinters = 0 p1 = p2 = () p1 = self.hitpath[0] N = len(self.hitpath) # Mathemagic loop-de-loop for i in range(0,N): p2 = self.hitpath[i % N] if py > min( p1[1] , p2[1] ): if py <= max( p1[1], p2[1] ): if px <= max( p1[0], p2[0] ): if p1[1] != p2[1]: xinters = ( py - p1[1] ) * ( p2[0] - p1[0] ) / ( p2[1] - p1[1] ) + p1[0] if p1[0] == p2[0] or px <= xinters: counter += 1 p1 = p2 if counter % 2 == 0: return "outside" return "inside" def button_press(self,widget,event): pass def button_release(self,widget,event): pass def motion_notify(self,widget,event): pass # GTK mumbo-jumbo to show the widget in a window and quit when it's closed def run(Widget): window = gtk.Window() window.connect("delete-event", gtk.main_quit) widget = Widget() widget.show() window.add(widget) window.present() gtk.main() class Shapes(Screen): #Override the press event def button_press(self,widget,event): print self.hitTest(event.x, event.y) def draw(self, cr, width, height): x = y = 10 sx = sy = 50 cr.move_to(x,y) cr.line_to(x+sx,y) cr.line_to(x+sx,y+sy) cr.line_to(x+(sx/2),y+sy) cr.line_to(x+(sx/2),y+(sy/2)) cr.line_to(x,y+(sy/2)) cr.line_to(x,y+sy) cr.line_to(x-sx,y+sy) cr.close_path() cr.set_source_rgb(1,0,0) self.makeHitPath(cr.copy_path_flat()) #record the path to use as a hit area. cr.fill() #consumes the path, so get it before the fill run(Shapes) From douglas at paradise.net.nz Fri Jul 4 08:22:15 2008 From: douglas at paradise.net.nz (Douglas Bagnall) Date: Fri, 4 Jul 2008 18:22:15 +1200 Subject: [Image-SIG] Filtering out all but black pixels for OCR In-Reply-To: <486B6AE1.8020807@mathematik.uni-dortmund.de> References: <000601c8da19$1f969920$08a305cf@Parents> <486B4AAC.9040109@mathematik.uni-dortmund.de> <486B69FF.4020502@nedbatchelder.com> <486B6AE1.8020807@mathematik.uni-dortmund.de> Message-ID: Karsten Hiddemann schrieb: > Fredrik has written something about the performance on pixel access with > some timings here: http://effbot.org/zone/pil-pixel-access.htm As that page also mentions, PIL images have the point method for doing this kind of thing. see http://effbot.org/imagingbook/image.htm#tag-Image.Image.point It is much faster and simpler than doing it in python, and slightly more idiomatic than Image.eval (which runs the same code internally). img = Image.open("onechannel.png") better = img.point([0] + [255] * 255) better.save("bilevel.png") You could also use point to perform apply the kind of sigmoid function that Scott suggested as part of a more OCR solution. Douglas From fredrik at pythonware.com Fri Jul 4 19:14:00 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 04 Jul 2008 19:14:00 +0200 Subject: [Image-SIG] Image.crop with bbox off image In-Reply-To: <20d04d890806171048o149210e3i73f126e1accdf0ae@mail.gmail.com> References: <20d04d890806171048o149210e3i73f126e1accdf0ae@mail.gmail.com> Message-ID: Gautham Narayan wrote: > I'm having trouble understanding the behaviour of Image.crop (PIL > 1.1.6 w/ python 2.5.1) when the bbox is outside the limits of the > image. So something like, > b = a.crop(x1,y1,x2,y2) > with x1 and y1 < 0 say. > > Sometimes I get a purely black border (which is good), sometimes I get > the image edges and patterns that are not in the image beyond. Is > there some way I can specify a crop that is off the image in at least > one coordinate and consistently have the region that is off the image > padded with 0s? Otherwise is there another alternative to checking if > the bbox is off the image and setting the remaining values to zero? I think the clamping in the 'crop' method messes up in some cases; to get more reliable behaviour, you might want to try the transform(EXTENT) method instead. From fredrik at pythonware.com Fri Jul 4 19:21:20 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 04 Jul 2008 19:21:20 +0200 Subject: [Image-SIG] Filtering out all but black pixels for OCR In-Reply-To: <486B69FF.4020502@nedbatchelder.com> References: <000601c8da19$1f969920$08a305cf@Parents> <486B4AAC.9040109@mathematik.uni-dortmund.de> <486B69FF.4020502@nedbatchelder.com> Message-ID: Ned Batchelder wrote: > If your image is single-channel (mode "L"), then you can use the eval > function: > > img = Image.open("onechannel.png") > # at each pixel, if it isn't zero, make it 255.. > better = Image.eval(img, lambda p: 255 * (int(p != 0))) > better.save("bilevel.png") if you want to avoid the clever lambda, you can use "point" instead, with a precalculated lookup table: # build lookup table (you can do this once, at the module level) lut = [255] * 256 # make everything white lut[0] = 0 # except things that are already pure black ... better = img.point(lut) # for each image From jim_hill_au-forums at yahoo.com.au Mon Jul 7 07:30:26 2008 From: jim_hill_au-forums at yahoo.com.au (jim_hill_au) Date: Mon, 07 Jul 2008 15:30:26 +1000 Subject: [Image-SIG] The _imaging extension was built for another version of Python Message-ID: <4871A9F2.80201@yahoo.com.au> On 2006-03-12, Fredrik Lundh wrote: > it sure looks as if Python's picking up some _imaging.pyd file > that doesn't match the Python interpreter you're using. > > have you verified that you don't have some old _imaging file > lying around somewhere ? I just ran into this problem when first using PythonCard, and would like to put this solution on record: The new version of _imaging.pyd is in x:\Python\Lib\site-packages\PIL but in x:\Python\DLLs I found older versions of both _imaging.pyd and _imagingft.pyd, dated 2004-12-10. removing these solved the problem. -- jim From edwards8 at gmail.com Tue Jul 8 23:36:14 2008 From: edwards8 at gmail.com (Shaun Edwards) Date: Tue, 8 Jul 2008 14:36:14 -0700 Subject: [Image-SIG] MemoryError Message-ID: <76d7b8f10807081436k7b0a7d7asef955bb2639b136a@mail.gmail.com> Hello, I'm still a bit new to all of this, and am extremely happy with PIL. However, I'm ending up with a slight memory issue. I'm converting large tif files (ranging from 400 - 1500 mb in size) to much smaller jpg files, in large batches. I open the tif file, resize it, and convert it to jpg. I then use the garbagecollector module in python to clear the memory. However, after running 30-40 of these files through the script, it fails on me, with a MemoryError. The script is attached. I'm curious if you might have any information, tips, or advice that would assist me in getting it to work. -- ~Shaun -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: image_convertor.py Type: text/x-python Size: 1613 bytes Desc: not available URL: From G.Kloss at massey.ac.nz Tue Jul 8 23:51:51 2008 From: G.Kloss at massey.ac.nz (Guy K. Kloss) Date: Wed, 9 Jul 2008 09:51:51 +1200 Subject: [Image-SIG] MemoryError In-Reply-To: <76d7b8f10807081436k7b0a7d7asef955bb2639b136a@mail.gmail.com> References: <76d7b8f10807081436k7b0a7d7asef955bb2639b136a@mail.gmail.com> Message-ID: <200807090951.51702.G.Kloss@massey.ac.nz> On Wed, 09 Jul 2008 9:36:14 am Shaun Edwards wrote: > Hello, I'm still a bit new to all of this, and am extremely happy with PIL. > ?However, I'm ending up with a slight memory issue. ?I'm converting large > tif files (ranging from 400 - 1500 mb in size) to much smaller jpg files, > in large batches. ?I open the tif file, resize it, and convert it to jpg. > ?I then use the garbagecollector module in python to clear the memory. > ?However, after running 30-40 of these files through the script, it fails > on me, with a MemoryError. ?The script is attached. ?I'm curious if you > might have any information, tips, or advice that would assist me in getting > it to work. It might be good to use the subprocess module for individual conversion jobs for two reasons: * Each sub-process that ends will automatically free all memory again * You can launch several sub-processes to run in parallel on multi-core machines. Therefore you may gain some speed as well. This does of course not resolve the GC problems in their cause, but it should help, be a quick way out of it and additionally give the benefit of speed increases on today's rather more ubiquitous multi-core systems. Guy [1] http://docs.python.org/lib/module-subprocess.html -- Guy K. Kloss Institute of Information and Mathematical Sciences Te Kura Putaiao o Mohiohio me Pangarau 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://www.massey.ac.nz/~gkloss/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part. URL: From Scott.Daniels at Acm.Org Wed Jul 9 04:55:02 2008 From: Scott.Daniels at Acm.Org (Scott David Daniels) Date: Tue, 08 Jul 2008 19:55:02 -0700 Subject: [Image-SIG] MemoryError In-Reply-To: <76d7b8f10807081436k7b0a7d7asef955bb2639b136a@mail.gmail.com> References: <76d7b8f10807081436k7b0a7d7asef955bb2639b136a@mail.gmail.com> Message-ID: Shaun Edwards wrote: > Hello, I'm still a bit new to all of this, and am extremely happy with > PIL. However, I'm ending up with a slight memory issue.... ... > ## For each file in every subdirectory, see if it's a tif file > for root, dir, files in os.walk(path): > for name in files: > filename, ext = os.path.splitext(name) > if ext == ".tif": > print 'Opening ' + name > os.chdir(path) This is a mistake. os.walk does _not_ like you to chdir > im = Image.open(root + '/' + name) Better would be: im = Image.open(os.path.join(root, name)) .... I'd suggest something more like: for root, dir, files in os.walk(path): names = [name for name in in files if filename.endswith(".tif")] dest_dir = None for name in names: im = Image.open(os.path.join(root, name)) if dest_dir is None: dest_dir = os.path.join('c' + root[1:], 'jpegs') try: os.makedirs(dest_dir) except WindowsError, why: print why dest_dir = x, y = im.size print 'Saving' im.resize((int(x*.66), int(y*.66)), Image.ANTIALIAS).save( os.path.join(dest_dir, savedfile,) quality=85) --Scott David Daniels Scott.Daniels at Acm.Org From anewc2 at gmail.com Wed Jul 9 21:03:43 2008 From: anewc2 at gmail.com (Amos Newcombe) Date: Wed, 9 Jul 2008 15:03:43 -0400 Subject: [Image-SIG] Installation woe: _imaging module missing after "successful" install from source Message-ID: I am having trouble installing PIL 1.1.6 on a new MacBook Pro (with 10.5.3). I got the source code version and ran "python setup.py build_ext -i" and it seemed to go well, passing the self test. But when I try to run my program, as soon as it calls Image.copy() I get this trace: File "/Library/Python/2.5/site-packages/PIL/Image.py", line 718, in copy self.load() File "/Library/Python/2.5/site-packages/PIL/ImageFile.py", line 155, in load self.load_prepare() File "/Library/Python/2.5/site-packages/PIL/ImageFile.py", line 223, in load_prepare self.im = Image.core.new(self.mode, self.size) File "/Library/Python/2.5/site-packages/PIL/Image.py", line 36, in __getattr__ raise ImportError("The _imaging C module is not installed") ImportError: The _imaging C module is not installed And all this happens because at a crucial point in Image.py (line 58), an import statement fails to find the _imaging module. I thought setup.py was supposed to take care of that. Then I find the binary package "http://www.pythonmac.org/packages/py25-fat/dmg/PIL-1.1.6-py2.5-macosx10.4-2007-05-18.dmg" from pythonmac.org, and I try that, only to fail with this message: "You cannot install PIL 1.1.6 on this volume. PIL requires System Python 2.5 to install." I don't know how "System Python 2.5" differs from the Python 2.5 that just came on this new MacBook Pro, the one that starts out Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> But the end result is, I am striking out here installing PIL. What can I do? From karsten.hiddemann at mathematik.uni-dortmund.de Wed Jul 9 22:24:37 2008 From: karsten.hiddemann at mathematik.uni-dortmund.de (Karsten Hiddemann) Date: Wed, 09 Jul 2008 22:24:37 +0200 Subject: [Image-SIG] Installation woe: _imaging module missing after "successful" install from source In-Reply-To: References: Message-ID: <48751E85.6010701@mathematik.uni-dortmund.de> Amos Newcombe schrieb: > Then I find the binary package > "http://www.pythonmac.org/packages/py25-fat/dmg/PIL-1.1.6-py2.5-macosx10.4-2007-05-18.dmg" > from pythonmac.org, and I try that, only to fail with this message: > > "You cannot install PIL 1.1.6 on this volume. PIL requires System > Python 2.5 to install." > > I don't know how "System Python 2.5" differs from the Python 2.5 that > just came on this new MacBook Pro, the one that starts out > > Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13) > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > > But the end result is, I am striking out here installing PIL. What can I do? Have you had a look at the rest of this mailing list? This is a frequently asked question. You either install the official Python 2.5 from python.org or you use the OS X PIL package by Christopher Barker. From Chris.Barker at noaa.gov Wed Jul 9 23:39:36 2008 From: Chris.Barker at noaa.gov (Christopher Barker) Date: Wed, 09 Jul 2008 14:39:36 -0700 Subject: [Image-SIG] Installation woe: _imaging module missing after "successful" install from source In-Reply-To: <48751E85.6010701@mathematik.uni-dortmund.de> References: <48751E85.6010701@mathematik.uni-dortmund.de> Message-ID: <48753018.1030905@noaa.gov> Karsten Hiddemann wrote: > Amos Newcombe schrieb: >> Then I find the binary package >> "http://www.pythonmac.org/packages/py25-fat/dmg/PIL-1.1.6-py2.5-macosx10.4-2007-05-18.dmg" >> >> from pythonmac.org, and I try that, only to fail with this message: >> >> "You cannot install PIL 1.1.6 on this volume. PIL requires System >> Python 2.5 to install." >> >> I don't know how "System Python 2.5" differs from the Python 2.5 that >> just came on this new MacBook Pro, the one that starts out Actually, that is an inaccurate error message -- what you need is the python.org python, not the one installed by Apple (yes, I would expect that "system Python 2.5" would be Apple's but that installer pre-dates 10.5 >> But the end result is, I am striking out here installing PIL. What can >> I do? > > Have you had a look at the rest of this mailing list? This is a > frequently asked question. You either install the official Python 2.5 > from python.org or you use the OS X PIL package by Christopher Barker. actually, It's not mine, and it's the one that requires the python.org package anyway. So your choices are: Either install the python.org python or find and compile all the dependencies, then compile PIL. Search this list and the web for pointers on how to do that. -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 svvampy at gmail.com Thu Jul 10 09:55:13 2008 From: svvampy at gmail.com (Eric O'Donnell) Date: Thu, 10 Jul 2008 17:55:13 +1000 Subject: [Image-SIG] Color problems with larger images In-Reply-To: <3a88a8190807092358s69ccb700i876a2fc7125c1208@mail.gmail.com> References: <3a88a8190807092358s69ccb700i876a2fc7125c1208@mail.gmail.com> Message-ID: <3a88a8190807100055i56ee43e5t54c5a77395a16945@mail.gmail.com> Hi, I'm getting some weird colour artifacts when I open larger images with PIL. Can't seem to find anything relevant in the archives. The code to replicate is pretty simple so I should just post that. #begin code block from PIL import Image, ImageWin filename = "Sumida_river05s3200.jpg" #http://upload.wikimedia.org/wikipedia/commons/c/c7/Sumida_river05s3200.jpg im = Image.open(filename) im.load() print im.mode w = ImageWin.ImageWindow(im) w.mainloop() #end code block The image is about 1.7 megabytes. I'm using PIL 1.1.6 with Python 2.5 on WindowsXP. If I shrink the image to half size in the GIMP, the colour distortion decreases. Shrink the original to a quarter size and the artifacts disappear. I thought this might be associated with CMYK problems from the archives, but none of the patches in the list changed the behavior, although they did fix the CMYK images linked. The image looks normal with other viewers. Any advice would be greatly appreciated. Thanks, Eric. From lists+Image_SIG at hoech.org Thu Jul 10 13:30:26 2008 From: lists+Image_SIG at hoech.org (=?ISO-8859-1?Q?Florian_H=F6ch?=) Date: Thu, 10 Jul 2008 13:30:26 +0200 Subject: [Image-SIG] Color problems with larger images In-Reply-To: <3a88a8190807100055i56ee43e5t54c5a77395a16945@mail.gmail.com> References: <3a88a8190807092358s69ccb700i876a2fc7125c1208@mail.gmail.com> <3a88a8190807100055i56ee43e5t54c5a77395a16945@mail.gmail.com> Message-ID: <4875F2D2.8060309@hoech.org> Yes, I can reproduce this using your example. Seems to happen only to images larger than real screen estate and looks like some kind of "palettization" (is that even a word?) error. But I think it's only a problem of ImageWin, not PIL in general. If you want to simply display the image, maybe im.show() is an option which will use the default image viewer of the OS? Regards, Florian H?ch Eric O'Donnell schrieb: > Hi, > > I'm getting some weird colour artifacts when I open larger images with > PIL. Can't seem to find anything relevant in the archives. > > The code to replicate is pretty simple so I should just post that. > > #begin code block > from PIL import Image, ImageWin > > filename = "Sumida_river05s3200.jpg" > #http://upload.wikimedia.org/wikipedia/commons/c/c7/Sumida_river05s3200.jpg > > im = Image.open(filename) > im.load() > print im.mode > > w = ImageWin.ImageWindow(im) > w.mainloop() > #end code block > > > The image is about 1.7 megabytes. > > I'm using PIL 1.1.6 with Python 2.5 on WindowsXP. > > If I shrink the image to half size in the GIMP, the colour distortion > decreases. Shrink the original to a quarter size and the artifacts > disappear. I thought this might be associated with CMYK problems from > the archives, but none of the patches in the list changed the > behavior, although they did fix the CMYK images linked. The image > looks normal with other viewers. > > Any advice would be greatly appreciated. > > Thanks, > Eric. > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig From olivier.schwander at ens-lyon.fr Thu Jul 10 16:41:24 2008 From: olivier.schwander at ens-lyon.fr (Olivier Schwander) Date: Thu, 10 Jul 2008 16:41:24 +0200 Subject: [Image-SIG] handbook mistake Message-ID: <20080710144124.GD22379@asie> Hello, I am not sure to understand this section of http://www.pythonware.com/library/pil/handbook/imagestat.htm pixel stat.mean (Attribute). Average pixel level. It seems to be a little mistake :) Cheers, Olivier From svvampy at gmail.com Fri Jul 11 03:00:33 2008 From: svvampy at gmail.com (Eric O'Donnell) Date: Fri, 11 Jul 2008 11:00:33 +1000 Subject: [Image-SIG] Color problems with larger images In-Reply-To: <4875F2D2.8060309@hoech.org> References: <3a88a8190807092358s69ccb700i876a2fc7125c1208@mail.gmail.com> <3a88a8190807100055i56ee43e5t54c5a77395a16945@mail.gmail.com> <4875F2D2.8060309@hoech.org> Message-ID: <3a88a8190807101800h1444e79o246ec1f76b7314fa@mail.gmail.com> I'm actually using PIL to create a DIB that I draw to a printer device context to print an image. I get the same colour distortion on the print. I've had a further look at the palette. When I call the query_palette* method on the ImageWindow dib, the return value is -1, indicating that the image needs to be redrawn. My attempts to do this have not borne fruit. #code w = ImageWin.ImageWindow(im) print w.image.query_palette(w.hwnd) # returns -1 w.image.paste(im) print w.image.query_palette(w.hwnd) # still returns -1 w.mainloop() #end code Is there some way to force an adaptive color palette when I open the image? Converting the image afterwards does not seem to change things. *documented as dib.palette() in the latest(?) documentation, http://effbot.org/imagingbook/ Thanks, Eric. 2008/7/10 Florian H?ch : > Yes, I can reproduce this using your example. Seems to happen only to images > larger than real screen estate and looks like some kind of "palettization" > (is that even a word?) error. But I think it's only a problem of ImageWin, > not PIL in general. If you want to simply display the image, maybe im.show() > is an option which will use the default image viewer of the OS? > > Regards, > > Florian H?ch > > Eric O'Donnell schrieb: >> >> Hi, >> >> I'm getting some weird colour artifacts when I open larger images with >> PIL. Can't seem to find anything relevant in the archives. >> >> The code to replicate is pretty simple so I should just post that. >> >> #begin code block >> from PIL import Image, ImageWin >> >> filename = "Sumida_river05s3200.jpg" >> >> #http://upload.wikimedia.org/wikipedia/commons/c/c7/Sumida_river05s3200.jpg >> >> im = Image.open(filename) >> im.load() >> print im.mode >> >> w = ImageWin.ImageWindow(im) >> w.mainloop() >> #end code block >> >> >> The image is about 1.7 megabytes. >> >> I'm using PIL 1.1.6 with Python 2.5 on WindowsXP. >> >> If I shrink the image to half size in the GIMP, the colour distortion >> decreases. Shrink the original to a quarter size and the artifacts >> disappear. I thought this might be associated with CMYK problems from >> the archives, but none of the patches in the list changed the >> behavior, although they did fix the CMYK images linked. The image >> looks normal with other viewers. >> >> Any advice would be greatly appreciated. >> >> Thanks, >> Eric. From wrybread at gmail.com Tue Jul 8 05:18:22 2008 From: wrybread at gmail.com (Alec Bennett) Date: Mon, 7 Jul 2008 20:18:22 -0700 Subject: [Image-SIG] Sepia with the PIL? Message-ID: I'm wondering if there's some snazzy way to get sepia image conversion with PIL? I'm currently getting black and white like this, which works great: enhancer.enhance(0) Thanks for any help. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Tue Jul 15 12:41:18 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 15 Jul 2008 12:41:18 +0200 Subject: [Image-SIG] Sepia with the PIL? In-Reply-To: References: Message-ID: Alec Bennett wrote: > I'm wondering if there's some snazzy way to get sepia image conversion > with PIL? I'm currently getting black and white like this, which works > great: > > enhancer.enhance(0) > > Thanks for any help. Simple sepia toning is usually made by converting the image to grayscale, and then attaching a brownish palette to the image. See e.g. http://en.wikipedia.org/wiki/List_of_software_palettes#Color_gradient_palettes To do this in PIL, convert the image to mode "L", and use putpalette to attach a suitable palette to the image. Something like this might work: from PIL import Image, ImageOps def make_linear_ramp(white): ramp = [] r, g, b = white for i in range(255): ramp.extend((r*i/255, g*i/255, b*i/255)) return ramp # make sepia ramp (tweak color as necessary) sepia = make_linear_ramp((255, 240, 192)) im = Image.open("somefile.jpg") # convert to grayscale if im.mode != "L": im = im.convert("L") # optional: apply contrast enhancement here, e.g. im = ImageOps.autocontrast(im) # apply sepia palette im.putpalette(sepia) im.save("outfile.jpg") From glathoud at yahoo.fr Tue Jul 15 13:09:50 2008 From: glathoud at yahoo.fr (Guillaume Lathoud) Date: Tue, 15 Jul 2008 11:09:50 +0000 (GMT) Subject: [Image-SIG] PIL Image.getcolors() returns None Message-ID: <17767.6972.qm@web26507.mail.ukl.yahoo.com> Hello, here is an issue with PIL 1.1.6 on a Windows XP platform: import Image im = Image.open( 'pil-1.1.6-Image-getcolors.png' ) im.show() # Displays the image correctly. print im.getcolors() # Bug: displays "None". I am happy to send the attached png to anyone interested, in case it is filtered out by the mailing list server. Best regards, Guillaume Lathoud _____________________________________________________________________________ Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr -------------- next part -------------- A non-text attachment was scrubbed... Name: pil-1.1.6-Image-getcolors.png Type: image/png Size: 10820 bytes Desc: not available URL: From fredrik at pythonware.com Tue Jul 15 13:25:37 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 15 Jul 2008 13:25:37 +0200 Subject: [Image-SIG] PIL Image.getcolors() returns None In-Reply-To: <17767.6972.qm@web26507.mail.ukl.yahoo.com> References: <17767.6972.qm@web26507.mail.ukl.yahoo.com> Message-ID: Guillaume Lathoud wrote: > Hello, here is an issue with PIL 1.1.6 on a Windows XP platform: > > import Image > im = Image.open( 'pil-1.1.6-Image-getcolors.png' ) > im.show() # Displays the image correctly. > print im.getcolors() # Bug: displays "None". The quickest way to fix this bug is to double-check the documentation: http://effbot.org/tag/PIL.Image.Image.getcolors Note the section that begins with "If the maxcolors value is exceeded, the method stops counting and returns None." From glathoud at yahoo.fr Tue Jul 15 14:02:01 2008 From: glathoud at yahoo.fr (Guillaume Lathoud) Date: Tue, 15 Jul 2008 12:02:01 +0000 (GMT) Subject: [Image-SIG] PIL Image.getcolors() returns None In-Reply-To: Message-ID: <476702.53127.qm@web26506.mail.ukl.yahoo.com> ok thanks, sorry about that. --- En date de?: Mar 15.7.08, Fredrik Lundh a ?crit?: > De: Fredrik Lundh > Objet: Re: [Image-SIG] PIL Image.getcolors() returns None > ?: image-sig at python.org > Date: Mardi 15 Juillet 2008, 13h25 > Guillaume Lathoud wrote: > > > Hello, here is an issue with PIL 1.1.6 on a Windows XP > platform: > > > > import Image > > im = Image.open( > 'pil-1.1.6-Image-getcolors.png' ) > > im.show() # Displays the image correctly. > > print im.getcolors() # Bug: displays > "None". > > The quickest way to fix this bug is to double-check the > documentation: > > http://effbot.org/tag/PIL.Image.Image.getcolors > > Note the section that begins with "If the maxcolors > value is exceeded, > the method stops counting and returns None." > > > > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig _____________________________________________________________________________ Envoyez avec Yahoo! Mail. Une boite mail plus intelligente http://mail.yahoo.fr From sienkiew at stsci.edu Tue Jul 15 23:18:35 2008 From: sienkiew at stsci.edu (Mark Sienkiewicz) Date: Tue, 15 Jul 2008 17:18:35 -0400 Subject: [Image-SIG] bug: selftest.py fails Message-ID: <487D142B.80000@stsci.edu> http://www.pythonware.com/products/pil/ says this is the place to send bug reports for PIL. Imaging-1.1.6 selftest.py fails, even after a successful build. Observed on Solaris 10, Python 2.5.2, GCC 4.1.1 Red Hat Enterprise 4 Linux, Python 2.5.1, GCC 3.4.6 # location of correct libraries % setenv LDFLAGS -L/usr/stsci/Python-2.5.2/lib/ % python setup.py build ... -------------------------------------------------------------------- PIL 1.1.6 BUILD SUMMARY -------------------------------------------------------------------- version 1.1.6 platform sunos5 2.5.2 (r252:60911, Jul 10 2008, 19:47:53) [GCC 4.1.1] -------------------------------------------------------------------- --- TKINTER support ok --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE2 support ok -------------------------------------------------------------------- To check the build, run the selftest.py script. ... % python selftest.py 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 Looking in selftest.py, it appears that it expects to find _imagingmath by inserting "." and "PIL" on sys.path, but _imagingmath is not in either of those places. % find . -name '_imagingmath*' ./_imagingmath.c ./build/lib.solaris-2.10-sun4u-2.5/_imagingmath.so ./build/temp.solaris-2.10-sun4u-2.5/_imagingmath.o You can make it work by % python setup.py install --install-lib=$wherever % setenv PYTHONPATH $wherever % rm -rf PIL % ln -s $wherever/PIL . % python selftest.py I install too much software to read all the mailing lists, so if you have questions please contact me directly. Mark Sienkiewicz From fredrik at pythonware.com Tue Jul 15 23:45:29 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue, 15 Jul 2008 23:45:29 +0200 Subject: [Image-SIG] bug: selftest.py fails In-Reply-To: <487D142B.80000@stsci.edu> References: <487D142B.80000@stsci.edu> Message-ID: <487D1A79.5010303@pythonware.com> Mark Sienkiewicz wrote: > Imaging-1.1.6 selftest.py fails, even after a successful build. > > Observed on > Solaris 10, Python 2.5.2, GCC 4.1.1 > Red Hat Enterprise 4 Linux, Python 2.5.1, GCC 3.4.6 > % python selftest.py > 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 > > Looking in selftest.py, it appears that it expects to find _imagingmath > by inserting "." and "PIL" on sys.path, but _imagingmath is not in > either of those places. $ more README ... 5. Build the library. We recommend that you do an in-place build, and run the self test before installing. $ cd Imaging-1.1.6 $ python setup.py build_ext -i $ python selftest.py When the build finishes, a summary report is shown. Make sure that the optional components you need are included. ... From bigmattyh at gmail.com Tue Jul 15 20:24:01 2008 From: bigmattyh at gmail.com (Matt Howell) Date: Tue, 15 Jul 2008 13:24:01 -0500 Subject: [Image-SIG] Trim borders? Message-ID: <344947280807151124u3366c1ffk635a72aadb5df24c@mail.gmail.com> Is there a straightforward way to trim off the borders of an image, using PIL? ImageMagick has a similar function called trim(), that looks at the 4 corner-pixels of the image, figures out what color the border is, and then trims out rows and columns from the image's edges until it reaches a portion of the image that doesn't match the border color. (I believe the function also has a variable tolerance setting, where you can specify a range of color where the matched border color would be considered to be a part of the border.) I see that there's a crop() function in PIL, but as you can see, the key to the trim() function is that the library automatically figures out where the border is and crops the image accordingly. Thanks for the help. -- Matt Howell -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at matthowell.com Fri Jul 18 05:17:22 2008 From: matt at matthowell.com (Matt Howell) Date: Thu, 17 Jul 2008 22:17:22 -0500 Subject: [Image-SIG] Using PIL to automatically trim borders from an image Message-ID: <344947280807172017j3b436fe2p42504d07daee2318@mail.gmail.com> Is there a straightforward way to use PIL to trim off the borders of an image? I'm thinking of something equivalent to the trim() function in ImageMagick. It looks at the 4 corner pixels, figures out what color the border is, and then trims out rows and columns from the image's edges that match the border color. So, as a use case, you could upload an image with some arbitrary amount of whitespace around the main content of the image, and trim out all that extra space. I don't see any equivalent built-in functionality in the PIL documentation -- crop() seems to come closest but it lacks the extra logic needed. I'm not opposed to writing the logic myself, but I'd like to avoid reinventing the wheel, if I can. :) Thanks for any ideas you can provide. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Sun Jul 20 13:02:41 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Sun, 20 Jul 2008 13:02:41 +0200 Subject: [Image-SIG] Using PIL to automatically trim borders from an image In-Reply-To: <344947280807172017j3b436fe2p42504d07daee2318@mail.gmail.com> References: <344947280807172017j3b436fe2p42504d07daee2318@mail.gmail.com> Message-ID: Matt Howell wrote: > Is there a straightforward way to use PIL to trim off the borders of an > image? > > I'm thinking of something equivalent to the trim() function in > ImageMagick. It looks at the 4 corner pixels, figures out what color > the border is, and then trims out rows and columns from the image's > edges that match the border color. So, as a use case, you could upload > an image with some arbitrary amount of whitespace around the main > content of the image, and trim out all that extra space. > > I don't see any equivalent built-in functionality in the PIL > documentation -- crop() seems to come closest but it lacks the extra > logic needed. I'm not opposed to writing the logic myself, but I'd like > to avoid reinventing the wheel, if I can. :) there's no built-in function to do this, but it's fairly easy to do this by combining a few builtins; given an image and a border color, you can do something like: from PIL import ImageChops def trim(im, border): bg = Image.new(im.mode, im.size, border) diff = ImageChops.difference(im, bg) bbox = diff.getbbox() if bbox: return im.crop(bbox) else: # found no content raise ValueError("cannot trim; image was empty") for details, see: http://effbot.org/tag/PIL.ImageChops.difference http://effbot.org/tag/PIL.Image.Image.getbbox (adding a color argument to getbbox could be pretty useful, I think) writing code to determine a suitable border color (e.g. by inspecting the corners or the border row/columns) is left as an exercise. From bob at glumol.com Tue Jul 22 04:54:06 2008 From: bob at glumol.com (Sylvain Baubeau) Date: Tue, 22 Jul 2008 11:54:06 +0900 Subject: [Image-SIG] Layer names in PSD files Message-ID: <1C9BFF79-8F32-476F-9461-4D528A029BE2@glumol.com> Hello, I needed to be able to retrieve the names of the layers in a PSD files. But PsdImagePlugin.py didn't do the job so I wrote this very small patch. There was a FIXME in PsdImagePlugin.py regarding the name of layers. I was wondering if this part was present some time ago and was removed for some reason. Cheers Sylvain Baubeau -------------- next part -------------- A non-text attachment was scrubbed... Name: psd-layer-names.patch Type: application/octet-stream Size: 1055 bytes Desc: not available URL: From nospamus at gmail.com Sun Jul 20 15:46:15 2008 From: nospamus at gmail.com (Bryan Hughes) Date: Sun, 20 Jul 2008 09:46:15 -0400 Subject: [Image-SIG] Webhost that supports PIL (and Django)? Message-ID: <57d24c990807200646w459ba822ob3c19e74fa5cdc79@mail.gmail.com> Can anyone recommend an affordable webhost that supports both Django and PIL? Thank you! -------------- next part -------------- An HTML attachment was scrubbed... URL: From fredrik at pythonware.com Wed Jul 23 00:27:40 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed, 23 Jul 2008 00:27:40 +0200 Subject: [Image-SIG] Webhost that supports PIL (and Django)? In-Reply-To: <57d24c990807200646w459ba822ob3c19e74fa5cdc79@mail.gmail.com> References: <57d24c990807200646w459ba822ob3c19e74fa5cdc79@mail.gmail.com> Message-ID: Bryan Hughes wrote: > Can anyone recommend an affordable webhost that supports both Django and > PIL? I use webfaction, which is reasonably cheap, have excellent Python and Django support (you get your own Apache instance proxied behind a main server), and seems to have PIL installed on all their machines: http://www.webfaction.com/ I'm sure there are others. From mgajda at embl-hamburg.de Thu Jul 24 19:42:51 2008 From: mgajda at embl-hamburg.de (Gajda Michal) Date: Thu, 24 Jul 2008 19:42:51 +0200 Subject: [Image-SIG] Reading 16-bit grayscale... Message-ID: <1216921371.11834.82.camel@canopus.EMBL-Hamburg.DE> Hi, I'm trying to add CBF support to PIL, but I cannot read 16-bit grayscale image. That is surprising as I still have 16-bit TIFF files, that cannot be read by ImageMagick, but PIL parses them beautifully. The following code gives an error of 'unrecognized image mode'. --------------------------------------------------------------- class CBFImageFile(ImageFile.ImageFile): format = "CBF" format_description = "Crystallographic Binary Format" def _open(self): # size in pixels (width, height) self.size = (2463, 195) self.mode = "F;16" # data descriptor offset = 2421 self.tile = [ ("raw", (0, 0) + self.size, offset, (self.mode, 0, 1)) ] Image.register_open("CBF", CBFImageFile) Image.register_extension("CBF", ".cbf") img = Image.open(textfile) img.rotate(45).show() -- Regards Michal From cannon.el at gmail.com Thu Jul 24 22:43:28 2008 From: cannon.el at gmail.com (Laura & Edward Cannon) Date: Thu, 24 Jul 2008 13:43:28 -0700 Subject: [Image-SIG] new version/features Message-ID: I had noticed that it has been a while since 1.1.6. Do we have an ETA for a new version of the library? Thanks, Edward From andy at andrewingram.net Fri Jul 25 00:44:38 2008 From: andy at andrewingram.net (Andrew Ingram) Date: Thu, 24 Jul 2008 23:44:38 +0100 Subject: [Image-SIG] PIL 1.1.6 (OSX Leopard and Windows XP) Image.rotate causes very pixelated results Message-ID: <488905D6.2040607@andrewingram.net> Hi, I'm trying to get a website to dynamically serve transformed versions of uploaded images, initially rotations but also perspective transforms and decal overlays. I'm using PIL and I'm loading images files in, the mode of the images is RGB. The problem is that when I try to rotate the images the result is highly pixelated regardless of the resample option I pass: m2 = im.rotate(15,resample=Image.NEAREST,expand=1) gives (visibly) identical results to m2 = im.rotate(15,resample=Image.BILINEAR,expand=1) or m2 = im.rotate(15,resample=Image.BICUBIC,expand=1) What I am hoping for the same nature of rotations you might see if using photoshop. I appreciate photoshop probably employs some patented algorithms but i'd expect to get a result that's somewhat smooth and non-jaggy at the very least. Am I doing something completely wrong, is PIL capable of what I want or should I be using something else with python for this kind of image work? Regards, Andrew Ingram From cannon.el at gmail.com Fri Jul 25 03:36:58 2008 From: cannon.el at gmail.com (Laura & Edward Cannon) Date: Thu, 24 Jul 2008 18:36:58 -0700 Subject: [Image-SIG] PIL 1.1.6 (OSX Leopard and Windows XP) Image.rotate causes very pixelated results Message-ID: Regarding rotating images, try Image.ANTIALIAS as the filter, I find that that gives the best results. Another trick that can help is resizing the image to double the size, rotating, then resizing to a smaller size. From pander at users.sourceforge.net Fri Jul 25 09:35:13 2008 From: pander at users.sourceforge.net (Pander) Date: Fri, 25 Jul 2008 09:35:13 +0200 (CEST) Subject: [Image-SIG] new version/features In-Reply-To: References: Message-ID: <3131.192.87.93.55.1216971313.squirrel@mjopr.nl> Hi all, Now focus is on a new release, please have a look at: http://mail.python.org/pipermail/image-sig/2008-June/005060.html Regards, Pander On Thu, July 24, 2008 22:43, Laura & Edward Cannon wrote: > I had noticed that it has been a while since 1.1.6. Do we have an ETA > for a new version of the library? > Thanks, Edward > _______________________________________________ > Image-SIG maillist - Image-SIG at python.org > http://mail.python.org/mailman/listinfo/image-sig > From fredrik at pythonware.com Fri Jul 25 10:03:21 2008 From: fredrik at pythonware.com (Fredrik Lundh) Date: Fri, 25 Jul 2008 10:03:21 +0200 Subject: [Image-SIG] new version/features In-Reply-To: References: Message-ID: Laura & Edward Cannon wrote: > I had noticed that it has been a while since 1.1.6. Do we have an ETA > for a new version of the library? Not really; it mostly depends on how well the current version works with 2.6. If 2.6 requires immediate fixes, expect a release in the beginning of September (in parity with 2.6rc1). If 2.6 doesn't require fixes, there will most likely be a "patch catchup" round in august/september, and an official 1.1.7 release after that. (but now I'm off for a vacation. see you all in mid-august ;-)