import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

dog = mpimg.imread('hundKlein.png')
convolutionMatrix  = np.array([ [ 1,  0 , -1], [0, 0, 0], [-1, 0, 1]] )
dogPadding = np.zeros( (dog.shape[0]+2, dog.shape[1]+2) )
dogPadding[1:dog.shape[0]+1,1:dog.shape[1]+1] = dog
dogConv = np.zeros_like(dogPadding)
for i in range(0,dog.shape[0]):
    for j in range(0,dog.shape[1]):
        dogConv[i+1,j+1] = np.sum((convolutionMatrix*dogPadding[i:i+3,j:j+3]))
        
plt.figure()
plt.imshow(dogPadding, cmap='gray')
plt.figure()
plt.imshow(dogConv, cmap='gray')

skriptBeispiel = np.zeros((7,7))
skriptBeispiel[1,1:6] = np.array([1, 0, 1, 2, 0])
skriptBeispiel[2,1:6] = np.array([1, 0, 1, 2, 3])
skriptBeispiel[3,1:6] = np.array([0, 0, 1, 2, 3])
skriptBeispiel[4,1:6] = np.array([0, 0, 0, 1, 2])
skriptBeispiel[5,1:6] = np.array([0, 0, 1, 2, 2])
skriptCon = np.zeros_like(skriptBeispiel)

convolutionMatrix  = np.array([ [ 1,  0 , -1], [0, 0, 0], [-1, 0, 1]] )
for i in range(0,5):
    for j in range(0,5):
        skriptCon[i+1,j+1] = np.sum((convolutionMatrix*skriptBeispiel[i:i+3,j:j+3]))