The key parameter is σ, which controls the extent of the kernel and consequently the degree of smoothing (and how long the algorithm takes to execute). More aggressive than the mean filter, the Gaussian filter deals with random noise more effectively (Figures 1d and 2d). But it still simply mixes the noise into the result and smooths indiscriminately across edges. Again, it is imperative to remove spikes before applying this filter.
It's important that the Gaussian kernel is not too small — it must be large enough to 'fade out' without sharp edges. Edges have large bandwidth, so they introduce aliasing artifacts into the result after convolution.
The optimal value for σ is between about 0.8 and 1.0.
Implementation in Python
We can make a Gaussian kernel in Python:
def gaussian_kernel(size, size_y=None): size = int(size) if not size_y: size_y = size else: size_y = int(size_y) x, y = numpy.mgrid[-size:size+1, -size_y:size_y+1] g = numpy.exp(-(x**2/float(size)+y**2/float(size_y))) return g / g.sum() # Make the Gaussian by calling the function gaussian_kernel_array = gaussian_kernel(5) plt.imshow(gaussian_kernel_array, cmap=plt.get_cmap('jet'), interpolation='nearest') plt.colorbar() plt.show()
But we don't really need to — we can just use the SciPy signal processing library:
import scipy.ndimage gaussian = scipy.ndimage.filters.gaussian_filter(noisy_horizon, 3.0) plt.imshow(gaussian, aspect=0.5, vmin=vmin, vmax=vmax) plt.show()
- The discrete Gaussian kernel — Wikipedia article