Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Created May 11, 2023 05:32
Show Gist options
  • Save joshuakfarrar/2005f2f7a767cb068b2b098a261daeb7 to your computer and use it in GitHub Desktop.
Save joshuakfarrar/2005f2f7a767cb068b2b098a261daeb7 to your computer and use it in GitHub Desktop.
import numpy as np
# Input image: 5x5 grayscale image
image = np.array([[10, 20, 30, 40, 50],
[60, 70, 80, 90, 100],
[110, 120, 130, 140, 150],
[160, 170, 180, 190, 200],
[210, 220, 230, 240, 250]])
# Filter or Kernel: 3x3
filter = np.array([[0, 1, 2],
[2, 2, 0],
[0, 1, 2]])
# Dimensions of the output feature map
output_dim = image.shape[0] - filter.shape[0] + 1
print("Output dimensions:")
print(output_dim)
# Initialize the output feature map
output = np.zeros((output_dim, output_dim))
# Convolve the filter over the image
for i in range(output_dim):
for j in range(output_dim):
output[i][j] = np.sum(image[i:i+3, j:j+3] * filter)
print("Output feature map:")
print(output)
@joshuakfarrar
Copy link
Author

const step = w => x => y => z => {
  if (z <= y) return w;
  else return x;
};
const heavyside = step(0)(1)(0);
const sign = step(-1)(1)(0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment