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) = Σᵢ Σⱼ I(x+i, y+j) · K(i, j)
Symbol guide
(I ★ K)(x, y)result of convolving image I with kernel K at output pixel (x, y)
Iinput image - a 2-D grid of pixel intensity values
Kkernel (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.

Padding: When the kernel reaches the border, we have less neighbors. Common strategies: zero padding (pad with 0s), reflect padding (mirror the image), or just crop the output.

Common Kernels

Interactive Kernel Editor

Edit kernel values, then apply to the image. Click a preset above to load it.

Identity
Original
Filtered

Types of Blur

Blur Comparison - Live

With noise
After filter

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?