I'm generating a few filters for use with implementing Fast Fourier Transform blur and sharpen operations on images. The filters are correctly generated, however the computations last very long.
The way I'm currently generating the filters is by iterating over the dimensions of the desired filter, item by item. I understand that I need to use Numpy in order to solve this problem, but I can't figure out how exactly. Here is my code for generating the Gaussian filter:
def gaussian_filter(mode, size, cutoff):
filterImage = np.zeros(size, np.float64)
cutoffTerm = 2 * (cutoff ** 2)
v = np.asarray([size[0] // 2, size[1] // 2])
for px in range(0, size[0]):
for py in range(0, size[1]):
u = np.asarray([px, py])
Duv = np.linalg.norm(u - v)
distance = -1 * (Duv ** 2)
result = pow(np.e, distance / cutoffTerm)
if mode == 'low':
filterImage.itemset((px, py), result)
elif mode == 'high':
filterImage.itemset((px, py), 1 - result)
return filterImage
Generating the filter of size 1920 x 1080 takes 70.36 seconds, which is completely unacceptable. Any ideas would be much appreciated.