From: <jd...@us...> - 2008-05-29 20:29:55
|
Revision: 5308 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5308&view=rev Author: jdh2358 Date: 2008-05-29 13:29:54 -0700 (Thu, 29 May 2008) Log Message: ----------- Merged revisions 5304-5306 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_91_maint ........ r5304 | jdh2358 | 2008-05-29 13:25:15 -0500 (Thu, 29 May 2008) | 1 line added clippath support for ps ........ r5305 | jdh2358 | 2008-05-29 13:25:58 -0500 (Thu, 29 May 2008) | 1 line added clippath support for ps ........ r5306 | jdh2358 | 2008-05-29 15:17:32 -0500 (Thu, 29 May 2008) | 1 line imread via pil now returns lumininance or rgb if possible ........ Modified Paths: -------------- trunk/matplotlib/API_CHANGES trunk/matplotlib/CHANGELOG trunk/matplotlib/examples/pylab/image_demo3.py trunk/matplotlib/lib/matplotlib/image.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Name: svnmerge-integrated - /branches/v0_91_maint:1-5299 + /branches/v0_91_maint:1-5307 Modified: trunk/matplotlib/API_CHANGES =================================================================== --- trunk/matplotlib/API_CHANGES 2008-05-29 20:18:41 UTC (rev 5307) +++ trunk/matplotlib/API_CHANGES 2008-05-29 20:29:54 UTC (rev 5308) @@ -1,4 +1,8 @@ + matplotlib.image.imread now no longer always returns RGBA -- if + the image is luminance or RGB, it will return a MxN or MxNx3 array + if possible. Also uint8 is no longer always forced to float. + Rewrote the cm.ScalarMappable callback infrastructure to use cbook.CallbackRegistry rather than custom callback handling. Amy users of add_observer/notify of the cm.ScalarMappable should uae @@ -197,6 +201,9 @@ END OF TRANSFORMS REFACTORING + + + 0.91.2 Released For csv2rec, checkrows=0 is the new default indicating all rows Modified: trunk/matplotlib/CHANGELOG =================================================================== --- trunk/matplotlib/CHANGELOG 2008-05-29 20:18:41 UTC (rev 5307) +++ trunk/matplotlib/CHANGELOG 2008-05-29 20:29:54 UTC (rev 5308) @@ -1,3 +1,10 @@ +2008-05-29 matplotlib.image.imread now no longer always returns RGBA + -- if the image is luminance or RGB, it will return a MxN + or MxNx3 array if possible. Also uint8 is no longer always + forced to float. + +2008-05-29 Implement path clipping in PS backend - JDH + 2008-05-29 Fixed two bugs in texmanager.py: improved comparison of dvipng versions fixed a bug introduced when get_grey method was added Modified: trunk/matplotlib/examples/pylab/image_demo3.py =================================================================== --- trunk/matplotlib/examples/pylab/image_demo3.py 2008-05-29 20:18:41 UTC (rev 5307) +++ trunk/matplotlib/examples/pylab/image_demo3.py 2008-05-29 20:29:54 UTC (rev 5308) @@ -3,14 +3,15 @@ try: import Image except ImportError, exc: - raise SystemExit("PIL must be loaded to run this example") + raise SystemExit("PIL must be installed to run this example") lena = Image.open('../data/lena.jpg') dpi = rcParams['figure.dpi'] figsize = lena.size[0]/dpi, lena.size[1]/dpi figure(figsize=figsize) - +ax = axes([0,0,1,1], frameon=False) +ax.set_axis_off() im = imshow(lena, origin='lower') #savefig('image_demo3') Modified: trunk/matplotlib/lib/matplotlib/image.py =================================================================== --- trunk/matplotlib/lib/matplotlib/image.py 2008-05-29 20:18:41 UTC (rev 5307) +++ trunk/matplotlib/lib/matplotlib/image.py 2008-05-29 20:29:54 UTC (rev 5308) @@ -650,11 +650,15 @@ """ return image file in fname as numpy array - Return value is a MxNx4 array of 0-1 normalized floats + return value is a numpy array. For grayscale images, the return + array is MxN. For RGB images, the return value is MxNx3. For + RGBA images the return value is MxNx4 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 + it will use it to load the image and return an array (if possible) which can be used with imshow + + TODO: support RGB and grayscale return values in _image.readpng """ def pilread(): @@ -682,15 +686,39 @@ def pil_to_array( pilImage ): + """ + load a PIL image and return it as a numpy array of uint8. For + grayscale images, the return array is MxN. For RGB images, the + return value is MxNx3. For RGBA images the return value is MxNx4 + """ + def toarray(im) + 'return a 1D array of floats' + x_str = im.tostring('raw',im.mode,0,-1) + x = np.fromstring(x_str,np.uint8) + return x + if pilImage.mode in ('RGBA', 'RGBX'): - im = pilImage # no need to convert images in rgba format + im = pilImage # no need to convert images + elif pilImage.mode=='L': + im = pilImage # no need to luminance images + # return MxN luminance array + x = toarray(im) + x.shape = im.size[1], im.size[0] + return x + elif pilImage.mode=='RGB': + #return MxNx3 RGB array + im = pilImage # no need to RGB images + x = toarray(im) + x.shape = im.size[1], im.size[0], 3 + return x + else: # try to convert to an rgba image try: im = pilImage.convert('RGBA') except ValueError: raise RuntimeError('Unknown image mode') - x_str = im.tostring('raw',im.mode,0,-1) - x = np.fromstring(x_str,np.uint8) + # return MxNx4 RGBA array + x = toarray(im) 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. |