Skip to content

Instantly share code, notes, and snippets.

@MartinMatta
Created July 27, 2020 15:24
Show Gist options
  • Select an option

  • Save MartinMatta/e7da99fceb82307a32612e4f4f8d9a83 to your computer and use it in GitHub Desktop.

Select an option

Save MartinMatta/e7da99fceb82307a32612e4f4f8d9a83 to your computer and use it in GitHub Desktop.
import numpy as np
def getGaussianKernel(size=3, sigma=1):
center = (int)(size/2)
kernel = np.zeros((size, size))
for x in range(-center, center+1):
for y in range(-center, center+1):
x1 = 2*np.pi*sigma**2
x2 = np.exp(-((x**2 + y**2) / (2*sigma**2)))
kernel[x+center, y+center] = (1/x1) * x2
return kernel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment