Spatial Filters & Convolution
Module 3 - Kernels, Blur, Sharpen, Noise Reduction
What is Convolution?
Convolution is the fundamental operation in image processing (and CNNs). A small matrix called a kernel (or filter) slides across the image. At each position, you multiply each kernel value by the corresponding pixel, then sum - that sum becomes the output pixel.
| (I ★ K)(x, y) | result of convolving image I with kernel K at output pixel (x, y) |
| I | input image - a 2-D grid of pixel intensity values |
| K | kernel (filter) - a small matrix, e.g. 3×3, whose values define the operation (blur, sharpen, edge detect...) |
| ★ | convolution operator - slide K over every pixel of I and compute a weighted sum |
| Σᵢ Σⱼ | double summation - loop over every row i and column j of the kernel |
| I(x+i, y+j) | the neighboring pixel of I offset by (i, j) from the center position (x, y) |
| K(i, j) | the kernel weight at position (i, j) - how much that neighbor contributes |
| · (dot) | multiply the neighbor pixel value by the kernel weight, then add it to the running total |
The kernel encodes what pattern you're looking for or what effect you want. A blur kernel averages neighbors; an edge kernel looks for intensity differences.
Common Kernels
Interactive Kernel Editor
Edit kernel values, then apply to the image. Click a preset above to load it.
Types of Blur
- Box blur: Each pixel = average of its neighbors. Fast but not realistic.
- Gaussian blur: Weighted average - neighbors closer to center count more. Most natural. σ controls spread.
- Median filter: Replace each pixel with the median of neighbors. Preserves edges, excellent for salt-and-pepper noise.
- Bilateral filter: Blur only pixels with similar intensity - smooths while preserving edges.
Blur Comparison - Live
Quiz
Check your understanding
1. A 3×3 box blur kernel sums all 9 neighbors. What should each value be so pixel values stay in [0,255]?
2. Which filter is best for removing salt-and-pepper noise while preserving edges?
3. You convolve an image with a sharpen kernel: [0,-1,0,-1,5,-1,0,-1,0]. What is the sum of the kernel values?