[Numpy-discussion] Numpy vs PIL in image statistics
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Fri May 29 04:36:41 EDT 2009
cp wrote:
>> I don't know anything about PIL and its implementation, but I would not
>> be surprised if the cost is mostly accessing items which are not
>> contiguous in memory and bounds checking ( to check where you are in the
>> subimage). Conditional inside loops often kills performances, and the
>> actual computation (one addition/item for naive average implementation)
>> is negligeable in this case.
>>
>
> This would definitely be the case in sub-images. However, coming back to my
> original question, how do you explain that although PIL is extremely fast in
> large images (2000x2000), numpy is much faster when it comes down to very small
> images (I tested with 10x10 image files)?
>
I've heard rumors that PIL stores it's images as pointers-to-rows (or
cols), i.e. to access a new row you need to dereference a pointer. NumPy
on the other hand always stores its memory in blocks. When N grows
larger, the N pointer lookups needed in PIL doesn't matter, but they do
for low N.
Dag Sverre
More information about the NumPy-Discussion
mailing list