🏥
Real-world scenario
Priya at MedScan Diagnostics (Bangalore): detect tumor boundaries in CT scans using CNN filters

Priya is analyzing CT scans at MedScan Diagnostics in Bangalore. She wants to train a CNN to detect tumors by learning to recognize edges and patterns in images. The problem: how does a CNN actually "see"? Fully-connected networks treat images as flat vectors, losing 2D structure. Convolution solves this: small filters slide across the image, detecting edges (low-level), corners (mid-level), and tumor shapes (high-level). Pooling compresses feature maps, reducing computation while preserving important patterns. Understanding convolution is the foundation of computer vision—from medical imaging to autonomous driving.

32x32
CIFAR-10 Image Size
3
Color Channels (RGB)
10
Classes

What is convolution? A filter sliding across an image

Core idea: A convolution applies a small filter (kernel) to patches of an image. The filter slides left-to-right, top-to-bottom, computing the dot product between filter weights and image pixels at each position. This produces a feature map: a smaller 2D grid of activations.

Why convolution? It exploits locality: nearby pixels are more correlated than distant ones. A 3x3 filter focuses on local patches, learning edges, textures, and patterns. Stacking convolutions builds a hierarchy: layer 1 detects edges (simple), layer 2 detects corners (intermediate), layer 3 detects objects (high-level).

Biological intuition: The brain's visual cortex works similarly—neurons respond to local patterns (edges at specific angles, colors, orientations) before combining them into objects.

Convolution math: kernel dot product

A convolution operation: slide a 3x3 kernel over a 5x5 image, computing dot products. At each position, multiply kernel values by image pixels, sum them, and place the result in the output feature map.

convolution_manual.py Implement convolution from scratch