2D Convolution From Scratch
Difficulty: Medium · Concept: Vision Fundamentals — Convolution as Classical Filtering
Slide a small kernel across an image, and at every position, compute the weighted sum of the pixels it currently covers. That's the entire mechanical operation — the same one a hand-designed Sobel edge filter runs, and the same one every CNN's convolutional layer runs, except a CNN learns the kernel values from data instead of a human choosing them.
Your task: implement convolve2d(image, kernel) — "valid" convolution only (no padding), stride 1. image and kernel are lists of lists (rows) of numbers; assume the kernel is no larger than the image in either dimension. Output size: for an image and kernel, the output is .