Recall the definition of convolution of integrable functions. In the case of good enough functions in real spaces, one is able to perform this operation by passing to the Fourier domain, multiplying, and coming back through the inverse Fourier transform. In the setting of digital signals one can also profit from this principle, but by using instead the discrete and inverse discrete Fourier transforms. With the aid of the fft algorithms to calculate the discrete Fourier transform, convolution via the frequency domain can be faster than directly convolving the time domain signals (scipy.ndimage.convolve in sage), and the final result is the same except maybe at the borders of the image. Some care must be taken when producing the convolution this way, since zero-padding needs to be applied.

The following example shows several ways to proceed, and offers some intuition on how these approaches differ to each other:

 result1 real(result2) real(result3[1:7,1:7]) real(result4[1:7,1:7])

[Note: Both result1 and result2 are matrices with size $$6\times 6,$$ while the matrices result3 and result4, which are identical, have size $$8\times 8.$$]

Another word of advise: one might feel tempted to create a Gaussian of the same size and shape of the original image. For example, if the original image has size $$512 \times 512,$$ to create the Gaussian $$G_{16}$$ one could proceed in sage as follows:

The procedure of convolution of a noisy version of an image with this kernel could be done as follows:

 original: image image + noise convImageGt

Granted: It accomplishes the requested operation, but at the expense of too many computations and storing unnecessary data—especially in cases where the original image contains millions of pixels!

Note the structure of the Gaussian kernel $$G_{1}$$ (below, left). This function is effectively zero more than about three standard deviations from the mean, so it does not make sense to store more than a small center window (below, right). We therefore collect the important values in a small matrix and use it as a kernel instead, at the time of computing the convolution.

$$\texttt{Gt} = \dfrac{1}{273} \begin{pmatrix} 1&4&7&4&1\\ 4&16&26&16&4\\ 7&26&41&26&7\\ 4&16&26&16&4\\ 1&4&7&4&1 \end{pmatrix}$$