Time-frequency and images · Definition

2D convolution on images

signal processingtime-frequency and images

Image filters such as smoothing and edge detection are implemented with 2D convolution. Understanding its mathematical form lets you design them and predict their effect.

Definition

2D convolution is the operation that combines an image \(f(x,y)\) with a kernel \(h(x,y)\) by sliding the kernel and summing products at each position.

\[(f*h)[m,n]=\sum_{k}\sum_{l} f[k,l]\,h[m-k,n-l]\]

2D convolution is commutative and associative, and it is also linear and shift-invariant. If the kernel is separable, \(h[m,n]=h_1[m]h_2[n]\), the convolution can be done in two 1D passes, reducing the number of multiplications. In the Fourier domain, convolution becomes a pointwise product of the transforms.

Consider a \(3\times3\) image with a single bright pixel at the center, \(f[1,1]=9\), and the \(3\times3\) averaging kernel \(h\) with all entries equal to \(1/9\). When convolving, the bright pixel spreads over the nine pixels of its neighborhood, itself included, each receiving 1, which illustrates smoothing.

A typical mistake is forgetting to flip the kernel in the definition, using correlation instead of convolution. For symmetric kernels the result coincides, but with asymmetric kernels such as derivative filters the sign of the result changes.

Think about it

Why do convolution and correlation give opposite signs at an edge with a derivative kernel?

Because convolution flips the kernel, so its \(-1\) weight meets the brighter pixel, while correlation applies it to the darker one.

Exercises 10

References

  • Alan V. Oppenheim, Alan S. Willsky, Signals and Systems, 2nd edition, Pearson, 1996.
  • Alan V. Oppenheim, Ronald W. Schafer, Discrete-Time Signal Processing, 3rd edition, Pearson, 2010.