Skip to content

Instantly share code, notes, and snippets.

Created January 16, 2019 09:58
What would you like to do?
Function that generate a Gaussian kernel of specific size and specific sigma
import numpy as np
def gaussian_kernel(size, sigma=1):
size = int(size) // 2
x, y = np.mgrid[-size:size+1, -size:size+1]
normal = 1 / (2.0 * np.pi * sigma**2)
g = np.exp(-((x**2 + y**2) / (2.0*sigma**2))) * normal
return g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment