Skip to content

Instantly share code, notes, and snippets.

@agnesmm

agnesmm/a3g3.py Secret

Created September 19, 2017 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agnesmm/12920dc34f52e8db0c82adfc905b16b9 to your computer and use it in GitHub Desktop.
Save agnesmm/12920dc34f52e8db0c82adfc905b16b9 to your computer and use it in GitHub Desktop.
import cv2
import matplotlib.pyplot as plt
import numpy as np
path = '/Users/agnesmustar/data/random_images/cars.jpg'
im = cv2.resize(cv2.imread(path, cv2.IMREAD_GRAYSCALE), (500, 300))
def convolutional_layer(im, W):
m = im.shape[0] - 2
n = im.shape[1] - 2
transformed_image = np.zeros((m,n))
for i in range(m):
for j in range(n):
patch = im[i:i+3, j:j+3]
transformed_image[i,j] = np.multiply(patch, W).sum()
return transformed_image
W = np.array([[-2,-2,-2],[-2,10,-2],[-2,-2,-2]])
transformed_image = convolutional_layer(im, W)
plt.imshow(transformed_image, cmap='gray')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment