Skip to content

Instantly share code, notes, and snippets.

@joefutrelle
Forked from andrewgiessel/gist:4635563
Created January 5, 2016 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joefutrelle/526e1f8aac4252a3ec26 to your computer and use it in GitHub Desktop.
Save joefutrelle/526e1f8aac4252a3ec26 to your computer and use it in GitHub Desktop.
simple numpy based 2d gaussian function
import numpy as np
def makeGaussian(size, fwhm = 3, center=None):
""" Make a square gaussian kernel.
size is the length of a side of the square
fwhm is full-width-half-maximum, which
can be thought of as an effective radius.
"""
x = np.arange(0, size, 1, float)
y = x[:,np.newaxis]
if center is None:
x0 = y0 = size // 2
else:
x0 = center[0]
y0 = center[1]
return np.exp(-4*np.log(2) * ((x-x0)**2 + (y-y0)**2) / fwhm**2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment