[Image-SIG] Array to Image transformations
Christopher Barker
Chris.Barker at noaa.gov
Wed Feb 27 18:48:09 CET 2008
Carlos da Silva Santos wrote:
> 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.
Actually, we already have, for numpy and PIL anyway:
# Added “fromarray” function, which takes an object implementing the
NumPy array interface and creates a PIL Image from it. (from Travis
Oliphant).
# Added NumPy array interface support (__array_interface__) to the Image
class (based on code by Travis Oliphant). This allows you to easily
convert between PIL image memories and NumPy arrays:
import numpy, Image
i = Image.open('lena.jpg')
a = numpy.asarray(i) # a is readonly
i = Image.fromarray(a)
See:
http://effbot.org/zone/pil-changes-116.htm
No data copying at all!
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Image-SIG
mailing list