[Numpy-discussion] Numpy vs PIL in image statistics

cp lubensch.proletariat.inc@gmail....
Wed May 27 10:33:56 CDT 2009


Testing the PIL vs numpy in calculating the mean value of each color channel of
an image I timed the following.

impil = Image.open("10.tif")
imnum = asarray(impil)

#in PIL
for i in range(1,10):
    stats = ImageStat.Stat(impil)
    stats.mean    

# for numpy
for i in range(1,10):
    imnum.reshape(-1,3).mean(axis=0) 

The image I tested initially is 2000x2000 RGB tif ~11mb in size. I set a timer
in each for loop and measured the performance of numpy 7 times slower than PIL.
When I did the the same with an 10x10 RGB tif and with 1000 cycles in for, numpy
was 25 times faster than PIL. Why is that? Does mean or reshape, make a copy? 



More information about the Numpy-discussion mailing list