[Numpy-discussion] array interface, PIL and PyGame

Perry Greenfield perry at stsci.edu
Tue Jul 11 13:28:31 CDT 2006


On Jul 11, 2006, at 2:04 PM, Travis Oliphant wrote:

>>
> We will all welcome Fredrik's comments.  But, I think he is  
> exaggerating
> the situation a bit.
>
> It is true that the Imaging structure of PIL is a more general memory
> model for 2-d arrays.  My understanding is that it basically allows  
> for
> an array of pointers to memory where each pointer points to a  
> different
> line (or chunk) in the image (kind of like a C-array).
>
> So, basically, the problem is that you may have an image that  
> cannot be
> described as a single block of memory or a singly-strided array.  I
> believe, thought,  that sometimes you do have a PIL image that is
> basically a single chunk of memory.
>
> So, while a general-purpose "memory-sharing" situation might be
> difficult.  I think some sharing (of each chunk for example) could be
> done.
>
> Even still, the array interface (the Python side) does technically
> handle the PIL case because the default is to use the sequence  
> interface
> to access elements of the array.
>
> It would be nice if Fredrik were more willing to help establish a
> standard, though.  Calling it "not close" but giving no alternative is
> not helpful.

To expand on this a bit, I think Fredrik is misreading the intent of  
the array interface somewhat. It's not that we are promising that the  
array data structure will suit his every need. Far from it. It's that  
it allows him (or us) to provide convenience functions that allow  
accessing data in PIL without jumping through lots of annoying hoops.  
It should be possible to convert PIL image data to arrays easily.  
Does that mean that all associated information is propagated as part  
of the array object? Of course not. But this information is  
obtainable by other means anyway.

Even in the case where different chunks of an image are in different  
memory locations and there is no simple way of avoiding copying the  
data, so what? I still much prefer the data be copied to an array so  
that numpy functionality can be applied to the array and have to  
avoid calling a sequence of operations to convert the data to a  
string and then to an array. At least one copy is avoided, but  
avoiding copying isn't the entire justification. Think of it this  
way, if PIL strength is that it can convert images between many  
different formats (no doubt, copying data in the process) then arrays  
should be one of the supported formats, no?

Perry





More information about the Numpy-discussion mailing list