Skip to content

Instantly share code, notes, and snippets.

@FienSoP
Created January 16, 2019 09:58
Show Gist options
  • Save FienSoP/49b61a7afdcb992fef0c8ef1b2b3364c to your computer and use it in GitHub Desktop.
Save FienSoP/49b61a7afdcb992fef0c8ef1b2b3364c to your computer and use it in GitHub Desktop.
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