[Image-SIG] PIL vs Numpy in raster calculations

cp lubensch.proletariat.inc at gmail.com
Fri May 29 17:07:59 CEST 2009


> Script 3 is probably as fast as you can get with numpy -- it's probably 
> slower than the PIL version because it does need to copy memory one way 
> or the other.

After all this talk and tests I definitely agree with you. This is the only
logical explanation of why numpy is faster than PIL when dealing with small
images, but slower when trying to calculate statistics of large images. 

I also received a message from a user of the numpy list. He suggested 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".

I couldn't find something that supports this, do you know anything about it?
If it is true, then it might provide an additional explanation for the
phenomenon, although I believe that the impact it should be limited. 
Concluding, I believe that on the basis of speed, the following are important:
Statistics calculations for images larger than 200x200 pixels? Go with PIL
Repeated statistics calculations for images smaller than 200x200 pixels? Go with
numpy. 




More information about the Image-SIG mailing list