Last active
June 30, 2023 20:31
simple numpy based 2d gaussian function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
I think that the return must be:
return np.exp(-((x-x0)**2 + (y-y0)**2) / fwhm**2)
without the part: "4*np.log(2)"
According the equation. See: https://en.wikipedia.org/wiki/Gaussian_function