# Build a Filter
# Core implementation example — ackleywill.com

import numpy as np

image = np.array([[0., 0., 0.], [0., 255., 0.], [0., 0., 0.]])
kernel = np.ones((3, 3)) / 9
padded = np.pad(image, 1, mode="constant")
raw = np.zeros_like(image)

for row in range(image.shape[0]):
    for col in range(image.shape[1]):
        patch = padded[row:row + 3, col:col + 3]
        raw[row, col] = np.sum(patch * kernel)

# Unflipped kernel: cross-correlation, as used in many CNN APIs.
display = np.clip(raw, 0, 255).astype(np.uint8)
print(raw)
