Re: [Image-SIG] PIL crashes windows 7 (blue screen)
On Mon, Sep 16, 2013 at 6:01 AM, Charles Cazabon charlesc-pyimage...@pyropus.ca wrote: Grabbing seems to work great for a while, but after some time, the process comes to a crash. Nothing a user-space program does should be able to crash the OS kernel. quite true, but this is Windows ( ;-) ) Anyway, the video driver is a more likely culprit, but it it is PIL (or something PIL is calling), and it only crashes after a bunch of calls in one process, then a major kludge would be to run the grabbing code in a separate process with the subprocess module. IN any case, it might be useful to do to debug. Or, even simpler write a simple batch file or python script that calls another pyton script that grabs thte screen, one grab at a time in one process, but run it a hundreds or times and see what happens. -Chris The behaviour you're describing sounds like a resource leak of some type, probably in kernel-space. The most likely culprit, I think, is the driver for your graphics hardware. Try upgrading your graphics drivers to the most recent WHQL-certified version for your hardware. Charles -- -- Charles Cazabon charlesc-pyimage...@pyropus.ca Software, consulting, and services available at http://pyropus.ca/ -- ___ Image-SIG maillist - Image-SIG@python.org https://mail.python.org/mailman/listinfo/image-sig -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org https://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Unsubscribe
Is there any way to set these parameters using environment variables? Pillow is being installed as a dependency for my library so it would be easier if users could set up something beforehand... Also, it's a pretty common practice for setup.py files to look in standard locations for includes -- i.e. marcports and fink locations on OS-X, maybe we should add the homebrew locations as well (though doesn't homebrew use use/local ? I'd think that would already be on the standard list. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
[Image-SIG] Initializing a 'P' image
HI folks, I'm creating, then drawing to, a P paletted image. I like how ImageDraw will let you set the colors as you drawm and it will automaticaly get added to teh palette. However, I can't see how to initialize the image with a given background (fill) color: In [35]: Image.new('P', (10,10), color=(255,255,255)) TypeError: an integer is required I can set color to 0 (Or, presumabley any other 8-bit integer), but then there is no color added to the palette, so it will get whatever I happend to draw first. So I've ended up doing this: self.image = Image.new('P', size, color=0) drawer = ImageDraw.Draw(self.image) # couldn't find a better way to initilize the colors right. drawer.rectangle(((0,0), size), fill=self.background_color) but that sure feels kludgy -- have I missed something? Of course, I could manage the palette myself, but that's uglier... -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] PIL and converting an image to and from a string value
On Fri, Apr 27, 2012 at 6:21 AM, Charles Cazabon charlesc-pyimage...@pyropus.ca wrote: I am stuck however, in figuring out how to take the string data and converting it back to an image that I can put into the canvas widget. See the PIL handbook, where it says If you have an entire image file in a string, wrap it in a StringIO object, and use open to load it. Actually, I don't think that's what the OP wants. A couple notes: 1) string is a confusing term -- generally it means text, but in python (2.*) it means an arrbitrary sequence of bytes, that can be interpreteed as text depending on context -- that is why there is now a string object and a bytes object. IN py2, bytes and string are the same, but it's handy to use bytes for future compatibility with py3, and for clarity in your code. So in this case, we are talking about bytes objects. (side note: make sure you are storing bytes objects in your DB properly -- as a binary blob, so that it doens't mess with the data) Now the real point: you can store an image in two ways (at least) in a bytes object: 1) essentially a binary dump of what would be in an encoced file (PNG, whatever). This is would you d get if you did: the_image_bytes = file(an_image.png, 'rb').read() 2) a binary dump of the bytes in memeory of the image object, without encoding or compression -- this is waht you get whn you do: the_image_bytes = a_pil_image.tostring() The STringIO suggestion refers to the former, but I thikn the OP was dealing with the later. In the later case, you can re-construct teh image object with: Image.fromstring(mode, size, data) = image so: a_pil_image = Image.fromstring('RGB', (300, 500), the_image_bytes) note that you'll need to keep track of what the made and size of the image are -- PIL can't figure that out just from the data. Depending on your needs, you may in fact want to store the PNG-encoded bytes in the DB, and decode them when you pull them out, using the StringIO strick. HTH, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Macinthos PIC files
On Tue, Apr 10, 2012 at 1:48 PM, Elmar Werling el...@net4werling.de wrote: Am 10.04.2012 21:46, schrieb Chris Barker: On Tue, Apr 10, 2012 at 12:11 PM, elmar werlingel...@net4werling.de wrote: I have pictures in Macinthos PIC/PICT format (HDR image (image/x-hdr),see appendix. Can anyone suggest a simple way to convert the pictures into JPEG-format? Wow! OS-X Preview doesn't even know what to so with it -- this may be tough! Image Magik identifies it, but thinks the header is invalid: $ identify example.pic example.pic PICT 640x480 640x480+0+0 8-bit DirectClass 24.6KB 0.010u 0:00.019 identify: improper image header `/var/folders/Dc/Dc6nkuThGN0thxlW3QBBVXu0AwA/-Tmp-/magick-ZTHN3MI2' @ error/pict.c/ReadPICTImage/881. Are you sure that file is good? -Chris Yea, file is good. Just changed to Windows / IrfanView and converted it to JPEG (see appendix) maybe it got corrupted in download -- Id give ImageMagick a try, and also maybe the python-mac list (or other mac list)m for ideas. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Help for to do a script
1) please don't multi-post like this -- this is really a tutor question. i.e. your problem is very basic python On Fri, Mar 16, 2012 at 11:52 AM, Boris Vladimir Comi gle...@comunidad.unam.mx wrote: I detect a class of atmospheric phenomena known as Mesoscale Convective Systems (MCS). To accomplish this, I have a database of satellites by 2004, every half hour. These data were downloaded from the server: unidata2.ssec.wisc.edu and data format is: 200404271515.goes12ir (Area Format) For this kind of work, you probably: 1) don't want to use Jython, unless there is a Java libary that will do most of the work that you want to use 2) do want to use numpy/scipy -- and likely the ndimage package: http://numpy.scipy.org/ http://www.scipy.org/SciPyPackages/Ndimage File /home/mcidasv/JYTHON/TIR.py, line 22 count = count + 1; debuggin hint -- when the error is not obvious, ALWAYS look at the proceeding line(s) of code: for j in xrange(ad.getElements()): if (data[0][i][j] 199.5 and (data[0][i][j] 200.5 count = count + 1; the if needs two more end-parentheses, and a colon. Also -- don't use semi-colons at the end of line -- they will just confuse you. Get a good Python-aware editor -- it will help catch these really simple kinds of syntax errors for you. Good luck, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] fromarray rotates image
putting the image-sig list back on the thread... On Tue, Jan 31, 2012 at 8:38 AM, Cousoulis, Paul pcousou...@meso-scale.com wrote: I'm sorry but I still think there is a bug. I still don't think so: explanation below. By the way, there is another problem with your example -- I get an all-black second image. I think you need to specify the image mode when you create the new image: newimage = Image.fromarray(npArray, mode=image1.mode) though that still makes a mess of it! -- more debugging to be done here -- see below In [4]: print image1.size (516, 356) In [5]: npArray = np.array(image1.getdata()) In [6]: print npArray.shape (183696L,) OK so far In [7]: npArray.shape = image1.size In [8]: print npArray.shape (516L, 356L) here I would swap -- as numpy naturally stores data the other way: and now it works: In [8]: run pil-numpy-test.py PIL.TiffImagePlugin.TiffImageFile image mode=L size=516x356 at 0x3A86468 input image size: (516, 356) numpy image shape before: (183696,) numpy image shape after: (356, 516) PIL.Image.Image image mode=L size=516x356 at 0x176C1E8 new image size (516, 356) (though the colors are still screwed up -- I don't know what's up with that...) I can see how you'd expect it to work the way you had it, but I think the problem is that you are mixing two ways to push raw data to/froim numpy arrays: npArray = np.array(image1.getdata()) is using PIL's getdata() to put the raw data in a string, then turning that into a numpy array (oh, and that may be the source of teh data mess up too...np.array is expecting a sequence of numbers or something, not raw data -- you want: OOPS, actually, getdata returns something else altogether: getdata im.getdata() = sequence Returns the contents of an image as a sequence object containing pixel values. The sequence object is flattened, so that values for line one follow directly after the values of line zero, and so on. Note that the sequence object returned by this method is an internal PIL data type, which only supports certain sequence operations, including iteration and basic sequence access. To convert it to an ordinary sequence (e.g. for printing), use list(im.getdata()). so it should be: npArray = np.fromstring(image1.tostring(), dtype=np.uint8) npArray.shape = (image1.size[1], image1.size[0] ) and that now works -- correct size, and correct final image. However: newimage = Image.fromarray(npArray) is using the numpy array protocol, which is a bit different than fromstring/tostring -- it carries shape information -- hence the need to specify the shape of the numpy array as I did. you can use that protocol both ways: npArray = np.asarray(image1) which then preserved size info. Here's my new version: from PIL import Image import numpy as np image1 = Image.open(LineGraph.tif) print image1 print input image size:, image1.size npArray = np.asarray(image1) print numpy image shape after:, npArray.shape newimage = Image.fromarray(npArray, mode=image1.mode) print newimage print new image size, newimage.size newimage.save(LineGraph2.tif) NOTE: if you do fromstring/tostring (or tobuffer) consistently, then it doesn't matter what shape you make the numpy array: image1 = Image.open(LineGraph.tif) print image1 print input image size:, image1.size npArray = np.fromstring(image1.tostring(), dtype=np.uint8) print numpy image shape:, npArray.shape newimage = Image.fromstring(image1.mode, image1.size, npArray.tostring()) print newimage print new image size, newimage.size newimage.save(LineGraph2.tif) But that's less efficient, and messier. NOTE: it might have been nicer if the array protocol were used such that the array created was fortran-order, and thus (w,h) in shape, but so it goes. HTH, -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Help installing PIL
On 9/16/11 3:23 PM, Bruce Johnson wrote: On Sep 14, 2011, at 7:45 PM, Isaac Feldman wrote: I am trying to install PIL 1.7.7 on Mac OS X 10.6 running python 2.7.2 No, it's because you don't have gcc-4.0 or at least don't have it on your $PATH. You need to have Apple's Developer Tools installed or build up a dev environment with MacPorts to do this. It's simplest to just install Apples dev tools: http://developer.apple.com/ Correct, though PIL requires some dependencies as well, so it's not that simple. What is simple is to use Russel Owen's unofficial binaries: http://www.astro.washington.edu/users/rowen/python/ for python2.7, you want: PIL-1.1.7-python.org-32bit-py2.7-macosx10.3.dmg That is the build for the 32 bit PPC+Intel build of python from python.org. Unless you really need 64 bit, that's the one I recommend. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Locate The Center of WhiteDot from a Image
On 1/7/2011 8:26 PM, Narendra Sisodiya wrote: If you need more math, numpy can help. Somethign like: a = np.asarray(PIL_image) background_color = 0 rows, cols = np.where(a background_color) # background color a uint32 BB = (rows.min(), rows.max(), cols.min(), cols.max()) I am unable to get what that code means ? May you explain how I can use above code with getbbox ? Or the above code using NumPy is alternate of getbbox method ? It's an alternative. IF yes, then which will be the faster ? The only way to know is to try it, but I suspect the PIL getbox() is a bit faster, as I image it does it all in one C loop. numpy is doing it in a couple loops. The reason to use numpy is if you want to do something more complex that is not directly supported by PIL. you might want to look at the scip ndimage toolbox it has some useful stuff: http://www.scipy.org/SciPyPackages/Ndimage though perhaps you've solved you problem. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Installing libjpeg
Mark Twenhafel wrote: Try adding print Image.core.__file__ to your script and make sure that the output is what you expect. what was the result of that? At this point, my working hypothesis is that I did not install libjpeg correctly. I'm working on OS X Tiger. What I did was download jpegsrc.v8a.tar.gz; double-click in my download window in Firefox to untar; move the untarred jpeg-8 folder to /Application; open Terminal and cd'ed to /Applications/jpeg-8; finally, I ran ./configure, make, and make install. It could be--and I don't know--that this install procedure did not correctly add libjpeg to my Python 2.6 installation no it wouldn't have done that. or that I need to rebuild site-packages/PIL/_imaging.so in order to link-in libjpeg. indeed you do. Belated point of clarification: I subsequently installed PIL using the these instructions: $ cd Imaging-1.1.7 $ python setup.py build_ext -i $ python selftest.py that should have built a new PIL, but it won't have installed it. Did the selftest run OK? I just noticed that the file site-packages/PIL/_imaging.so was created last October. which is why you are getting an old one here. If so, would be be possible or likely that this was built using the version of libjpeg that didn't install on my machine? yup. If this is correct, what is the best way to proceed? My first inclination is to delete the directory site-packages/PIL and reinstall. yup -- you may not even need to delete, but it won't hurt. Take a look for a new _imaging.so that you should have just built. If you really want to know what it's linked to, try: $ otool -L _imaging.so But you might just do: setup.py install and see if it now works. We really do need to get a Mac binary built! -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Mac support for PIL
Fredrik Lundh wrote: Do you have the necessary support libraries on your machine? (see the README file). There are prebuilt versions out there too; maybe some Mac hackers can chime in and point you to the latest and greatest. I'd ask on the pyhthonmac SIG list. Maybe someone there has or will produce a binary ( I have NO time for it right now! ) If you do want to do it yourself, the easiest way to get the libs is macports. Bill Janssen wrote: Works for me. I build libjpeg, libpng, libfreetype, etc. from source first, and install them, then build PIL. Haven't tried it with 10.6.3, though. Bill, any chance you could put together a binary installer -- it would be a nice service to the community. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Image to matrix
Alex Torquato S. Carneiro wrote: I'm doing a project in Python. It's a capture and process a image, I'm using PIL for images and scipy (together numpy) I'm needing to convert a image in a matrix type, can anyone help me? The latest version of PIL supports this directly, you can do: M = numpy.asarray(PIL_Image) http://effbot.org/zone/pil-changes-116.htm -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/ORR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] doubles?
Ghalib Suleiman wrote: I want to convert my image to doubles, such that each entry in the R,G,B tuple is a double lying in the range [0,1] (this will be then passed onto NumPy for some arithmetic). why not pass the data to numpy, then convert -- that will be a lot easier. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/ORR/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Auto level with PIL?
Thanks Stefano, this make sit much more clear what's going on. I'll give this code a try. -chris -- Christopher Barker, Ph.D. Oceanographer NOAA/ORR/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] Something other than .show()
Joseph Quigley wrote: What else can I use besides .show() to display the image? PIL can be used with any number of the various GUI toolkits available for Python. Here's some info about using it with wxPython: http://wiki.wxpython.org/index.cgi/WorkingWithImages It would be pretty quick to whip up an alternative to show() with wxPython and probably any of the other major toolkits. (GTK, QT, etc.) -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/ORR/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] GUI with Transparency
Christian M. Jensen wrote: Does anyone know of a GUI toolkit that supports alpha blending using PNGs? What is it you want to do with them? wxPython can load and display PNGs with alpha, but there is no way to create them with wxPython, and I don't know if you can put them on top of each other. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/ORR/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception [EMAIL PROTECTED] ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig