On 31 May 2010 19:49, rugspin <piet_par...@web.de> wrote:

>
> I have a small problem how to convert an image from matplotlib to PIL
>
> right now doing somthing like this:
> ------------------------------------------
> from scipy import *
> from pylab import *
> from PIL import Image
>
> a = arange(16384).reshape(128,128)
> imsave( "test.png", a, cmap=cm.summer,vmin=0,vmax=16383)
> b = Image.open("test.png" )
> ------------------------------------------
>

The Image.fromarray function should do what you want. For example,

import numpy as np   # note: use of "from foo import *"
import Image             # is discouraged where possible

a = np.arange(128)[None,:] * np.ones(128)[:,None]
b = Image.fromarray(a)
c = np.asarray(b)
np.all(c == a)
  -> True

I hope that helps,

Angus.
-- 
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh
------------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to