[Image-SIG] Array to Image transformations

Frédéric Mantegazza frederic.mantegazza at gbiloba.org
Wed Feb 27 07:23:37 CET 2008


On mardi 26 février 2008, Joao S. O. Bueno wrote:

> On Thu 21 Feb 2008 05:47:22 Sahar Vilan wrote:

> > Can anyone help me with transformation from numpy array to image (at
> > PIL library)?
> > I want to change an array (at numpy) into an image (at Image) in order
> > to rotate the image and save it in standard image format.
>
> Sorry for the long delay.
> These convertions in python among data and image representation indeed
> require some experimentation.
>
> (In my todo list, wiht low priority, I have a python module that would
> seamlessly translate image data across various image handling
> bindings/ibraries and numerical types).
>
> Fortunatey, in this case it is rather simple:
>
> For numpy.array -> python image, you do something like:
>
> a = numpy.array ("\x0"  (WIDTH  * HEIGHT  * 3), "B")
> #code to create imag data inside array
> # (...)
> i  = Image.new("RGB", (WIDTH, HEIGHT))
>
> i.fromstring(a.tostring())
> i.save(filename)

Hello,

I'm also very interested by such features, because I think it could be a 
nice way to use color management libraries. For example, the little cms 
python wrapper could handle arrays (which it does not yet), and then, PIL 
could convert image from/to arrays.

> i.fromstring(a.tostring())

What is the performances of such transformations?

-- 
   Frédéric

   http://www.gbiloba.org


More information about the Image-SIG mailing list