Last active
February 4, 2022 18:34
-
-
Save soof-golan/bc6b4392773a2b5481d8da69237042b6 to your computer and use it in GitHub Desktop.
Support gists for my game-of-life blog post
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
[[1, 1, 1], | |
[1, 0, 1], | |
[1, 1, 1]] |
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
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 |
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
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