2D Convolution for Images
What You'll Learn
You'll understand how 2D convolution processes image data by accounting for height, width, and multiple color channels.
The 2D Convolution Operation
Images aren't just grids of numbers—they have spatial dimensions (height and width) and typically multiple channels (like RGB color channels). A 2D convolution extends the sliding window concept to work with this structure.
How It Works
When you apply a 2D convolution to an image:
- Input dimensions: Your image has shape
(height, width, channels)—for example, a color photo might be(256, 256, 3)for 256×256 pixels with 3 RGB channels - Filter/kernel dimensions: The filter also has depth matching the input channels, like
(3, 3, 3)for a 3×3 spatial window across all 3 color channels - Sliding across space: The filter slides over the height and width dimensions (not the channels)
- Per-position computation: At each position, you multiply the filter values with the corresponding image patch across all channels and sum everything into a single number
Think of it like a cookie cutter that presses through all color layers at once. A 3×3 filter on an RGB image actually multiplies 27 values (3×3×3) and adds them to produce one output value.
Output Shape
If you apply one filter, you get a 2D output (one channel). Multiple filters produce multiple output channels—this is how CNNs build feature maps that detect edges, textures, or patterns.
Key Takeaway: 2D convolution processes images by sliding filters across height and width while computing weighted sums across all input channels simultaneously, producing spatially-organized feature maps.