Created
August 2, 2019 07:15
-
-
Save Multihuntr/a1c5105b55e712847f798026da6e9793 to your computer and use it in GitHub Desktop.
Numpy gaussian smoothing
This file contains hidden or 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
# Super simple 1D smoothing with just numpy. Just smooths a few sharp edges. | |
import math | |
import numpy as np | |
def gaussian_kernel(n=5): | |
x = np.arange(n)/n | |
g = math.e ** -(x**2/((n - 2)**2)) # drop the constant factor at the start | |
return g/g.sum() # normalise so it sums to 1 | |
def gaussian_smooth(x, n=5, passes=2): | |
for x in range(passes): | |
x = np.convolve(x, gaussian_kernel(n)) | |
return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment