[Image-SIG] Array to Image transformations
Carlos da Silva Santos
carlos.s.santos at gmail.com
Wed Feb 27 12:12:40 CET 2008
There are currently two PEPs related to this kind of problem. One is
lead by Travis Oliphant of numpy and is about establishing a buffer
protocol for data interchange. The second one is specifically related
to passing image data between applications/toolkits.
http://www.python.org/dev/peps/pep-3118/
http://www.python.org/dev/peps/pep-0368/
So I guess in the near future we will get rid of string conversions.
Carlos
On Wed, Feb 27, 2008 at 6:23 AM, Frédéric Mantegazza
<frederic.mantegazza at gbiloba.org> wrote:
> 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
>
>
> _______________________________________________
> Image-SIG maillist - Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig
>
More information about the Image-SIG
mailing list