Skip to content

Instantly share code, notes, and snippets.

@soof-golan
Last active February 4, 2022 18:34
Show Gist options
  • Save soof-golan/bc6b4392773a2b5481d8da69237042b6 to your computer and use it in GitHub Desktop.
Save soof-golan/bc6b4392773a2b5481d8da69237042b6 to your computer and use it in GitHub Desktop.
Support gists for my game-of-life blog post
[[1, 1, 1],
[1, 0, 1],
[1, 1, 1]]
def gaussian_kernel(kernel_size=21, nsig=3):
x = np.linspace(-nsig, nsig, kernel_size+1)
kern1d = np.diff(scipy.stats.norm.cdf(x))
kern2d = np.outer(kern1d, kern1d)
return kern2d/kern2d.sum()
def gaussian_blur(image: np.ndarray, kernel_size) -> np.ndarray:
kernel = gaussian_kernel(kernel_size)
return scipy.signal.convolve2d(image, kernel, 'same')
def sharpen(image: np.ndarray, kernel_size) -> np.ndarray:
return image - gaussian_blur(image) >= 0
def threshold(image: np.ndarray, val) -> np.ndarray:
return image - val >= 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment