Created
May 11, 2023 05:32
-
-
Save joshuakfarrar/2005f2f7a767cb068b2b098a261daeb7 to your computer and use it in GitHub Desktop.
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 | |
# 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) |
Author
joshuakfarrar
commented
May 11, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment