I'm trying to convolve an image using a gaussian filter and I've learnt that using FFTs is the fastest way to do so. I've tried convolving the image with the gaussian filter but the results haven't turned out so well..
gaussian=[[0.003, 0.013, 0.022, 0.013, 0.003],\
[0.013, 0.059, 0.097, 0.059, 0.013],\
[0.022, 0.097, 0.159, 0.097, 0.022],\
[0.013, 0.059, 0.097, 0.059, 0.013],\
[0.003, 0.013, 0.022, 0.013, 0.003]]
gaussian1=np.array(gaussian)
# load in an image, convert to grayscale if needed
image = imageio.imread('input.jpg',as_gray=True)
# take the fourier transform of the image
fft2 = fftpack.fftshift(fftpack.fft2(image))
gaussian_np= fftpack.fftshift(fftpack.fft2(gaussian))
#temp array to save the results
temp_array=np.ones((fft2.shape[0],fft2.shape[1]))
for x in range(fft2.shape[0]-4): #range upto -4 because of 5x5 kernel
for y in range(fft2.shape[1]-4):
temp=fft2[x:5+x,y:5+y] #slices 5x5 grid from fft of image
convolution=np.multiply(temp,gaussian_np)
temp_array[x:5+x,y:5+y]=convolution
#convert results back
ifft2 = abs(fftpack.ifft2(fftpack.ifftshift(temp_array)))