from linfilters import *
from pylab import imread, ones, plot, semilogy, savefig, show
from scipy.ndimage.interpolation import zoom
from time import time
from sys import argv

repeat = 1
w = (3, 11)

f = zoom(imread('cameraman.png'), .25)
methods = [linfilter1, linfilter2, linfilter3, linfilter4]
timings = [[] for i in methods]

x = range(w[0], w[1] + 1, 2)

for i, method in enumerate(methods):
    for j in x:
        weight = ones((j, j)) / (j ** 2)
        t = 0

        for k in xrange(repeat):
            start = time()
            method(f, weight)
            t += time() - start

        timings[i].append(t / repeat)

for times in timings:
    plot(x, times, 'o-')

semilogy()

if len(argv) > 1:
    savefig(argv[1])

show()

#subplot(1, 3, 1)
#imshow(a)
#f = zoom(a, .25)
#g = linfilter1(f, ones((5, 5)) / 25)
#subplot(1, 3, 2)
#imshow(f)
#subplot(1, 3, 3)
#imshow(g)
#show()
