Skip to content

Instantly share code, notes, and snippets.

@thomasaarholt thomasaarholt/gaussian.py
Last active Sep 10, 2019

Embed
What would you like to do?
Fastest found method of generating a gaussian kernel of size n x nand standard deviation std.
import numpy as np
from scipy import signal
def gaussian_kernel(n, std, normalised=False):
'''
Generates a n x n matrix with a centered gaussian
of standard deviation std centered on it. If normalised,
its volume equals 1.'''
gaussian1D = signal.gaussian(n, std)
gaussian2D = np.outer(gaussian1D, gaussian1D)
if normalised:
gaussian2D /= (2*np.pi*(std**2))
return gaussian2D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.