Revision: 5258
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5258&view=rev
Author: jdh2358
Date: 2008-05-25 05:51:50 -0700 (Sun, 25 May 2008)
Log Message:
-----------
added pil support to imread
Modified Paths:
--------------
branches/v0_91_maint/lib/matplotlib/image.py
Modified: branches/v0_91_maint/lib/matplotlib/image.py
===================================================================
--- branches/v0_91_maint/lib/matplotlib/image.py 2008-05-25 12:50:29 UTC
(rev 5257)
+++ branches/v0_91_maint/lib/matplotlib/image.py 2008-05-25 12:51:50 UTC
(rev 5258)
@@ -609,13 +609,29 @@
Return value is a MxNx4 array of 0-1 normalized floats
+ matplotlib can only read PNGs natively, but if PIL is installed,
+ it will use it to load the image and return an RGBA if possible
+ which can be used with imshow
"""
+
+ def pilread():
+ 'try to load the image with PIL or return None'
+ try: import Image
+ except ImportError: return None
+ image = Image.open( fname )
+ return pil_to_array(image)
+
+
handlers = {'png' :_image.readpng,
}
basename, ext = os.path.splitext(fname)
ext = ext.lower()[1:]
+
if ext not in handlers.keys():
- raise ValueError('Only know how to handled extensions: %s' %
handlers.keys())
+ im = pilread()
+ if im is None:
+ raise ValueError('Only know how to handle extensions: %s; with PIL
installed matplotlib can handle more images' % handlers.keys())
+ return im
handler = handlers[ext]
return handler(fname)
@@ -632,6 +648,6 @@
raise RuntimeError('Unknown image mode')
x_str = im.tostring('raw',im.mode,0,-1)
- x = npy.fromstring(x_str,npy.uint8)
+ x = np.fromstring(x_str,np.uint8)
x.shape = im.size[1], im.size[0], 4
return x
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins