Skip to content

Instantly share code, notes, and snippets.

@agnesmm agnesmm/a3g3.py Secret
Created Sep 19, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.