Created
September 26, 2019 15:57
-
-
Save kwinkunks/769e39e8314b5479842a77b18e4e3eda to your computer and use it in GitHub Desktop.
Implementing a 3 x 3 boxcar filter over a 2D image in pure NumPy
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 | |
arr = np.random.randint(0, 256, (200, 200), dtype=np.uint8) | |
def func(arr1d): | |
kernel = np.ones(3) / 3 | |
return np.convolve(arr1d, kernel, mode='same') | |
first_pass = np.apply_along_axis(func, axis=0, arr=arr) | |
final_result = np.apply_along_axis(func, axis=1, arr=first_pass) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment