[Numpy-discussion] Quicker image transfer, tobuffer?
Filip Wasilewski
filip at ftv.pl
Tue Jul 11 17:31:56 EDT 2006
Hi Travis,
this is a great example of the __array_interface__ usage.
I have spotted some problems after patching the Image.py module and
trying to display an array created from Image in matplotlib.
First issue is a minor one. There is a difference in axis order between
ndarray and PIL:
def _conv_type_shape(im):
shape = im.size[::-1]
typ, extra = _MODE_CONV[im.mode]
if extra is None:
return shape, typ
shape += (extra,)
return shape, typ
The second seems to be more complex and may be a more general. The
memory of string created by self.tostring() seems to be deallocated
before array is created (v 0.9.9.2788, win).
Everything works fine after storing the reference to data, but this
probably should be done somewhere else:
def __get_array_interface__(self):
new = {}
shape, typestr = _conv_type_shape(self)
new['shape'] = shape
new['typestr'] = typestr
new['data'] = self.tostring()
self._str_data = new['data'] # a dirty hack
return new
best,
fw
More information about the NumPy-Discussion
mailing list