27 May
2009
27 May
'09
3:33 p.m.
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?