2.2. Convolution#
After discussing simple image transformations based on histogram manipulations before, we will introduce another family of methods that perform image filtering. The underlying concept of image filtering can simply be expressed by the mathematical convolution operator. In simple terms, a convolution is an operation combining the information of two functions to compute a new function. A convolution can be interpreted geometrically as sliding the first function over the second, while computing the overlapping area of both functions.
We begin by defining the continuous convolution operator in the following.
Definition 2.7 (Continuous convolution)
Let \(f,g \in L^1(\R^n; \C)\) be absolutely integrable functions. Then the convolution \((f*g) \in L^1(\R^n; \C)\) of the functions \(f\) and \(g\) is defined as:
The convolution operator has some useful properties which we discuss in the following.
Remark 2.2 (Properties of convolution)
Let \(f, g, h\in L^1(\mathbb{R}^n;\C)\), then we have the following properties:
\(f*g=g*f\) (symmetry)
\(f*(g*h)=(f*g)*h\) (associativity)
\(f*(g+h)=f*g+f*h\) (distributive law)
\(\overline{f*g}=\overline{f}*\overline{g}\) (complex conjugation)
\((f*g)' = f'*g = f*g'\) (differentiation)
In the context of image processing the function \(f\) in the convolution is usually the image to be processed and the function \(g\) is a so called image filter. Depending on the particular choice of filter the convolution performs the task of smoothing, denoising, edge detection, etc.
There exists an interesting mathematical relation between the convolution and the Fourier transform.
Theorem 2.1 (Convolution theorem)
Let \(f, g\in L^1(\R^n;\C)\) be absolutely integrable functions. Then the following identity holds:
If \((\hat{f} \cdot \hat{g}) \in L^1(\R^n; \C)\) then by applying the inverse Fourier transform, we get:
For the sake of simplicity, we neglect here the normalisation factor \({(2\pi)}^{-\frac{n}{2}}\).
Proof. In the following proof we neglect the normalisation factor \({(2\pi)}^{-\frac{n}{2}}\) of the continuous Fourier transform to make following the proof easier.
Introducing the auxiliary variable \(w := x-y\) yields \(x = w + y\), which does not change the integration limits as they are infinite. Thus, we get
Since the integration variables can simply be exchanged, we get
This proofs the first identity of the convolution theorem.
Assuming that \((\hat{f} \cdot \hat{g}) \in L^1(\R^n; \C)\) we can simply prove the second identity by applying the inverse Fourier transform to the first equation:
◻
To perform the convolution operation on discrete images we need a discrete analogue of the continuous convolution operator.
Definition 2.8 (1D Discrete convolution)
Let \(f_h,g_h:\Z\to \C\) be two discrete functions. The discrete convolution \((f_h * g_h)\) of \(f_h\) and \(g_h\) is defined as:
If the support of the two functions \(f_h\) and \(g_h\) is limited to a finite set of points \(\left[0, N-1 \right]\subset \Z\), then the discrete convolution simplifies to:
Because we are aiming to use the discrete convolution in the context of image processing the restriction to a finite set of points \(\left[0, N-1 \right)\subset \Z\) is meaningful.
Since the convolution is a linear operator (as follows from the distributivity property in Remark 2.2), the discrete convolution can be expressed as the following matrix-vector product:
The matrix has a particular structure as it periodically contains the discrete filter \(g_h\) shifted by one index per row. Indeed, we can easily show that this matrix-vector multiplication yields the discrete convolution \(\left(f*g\right)\). To demonstrate this let us regard the first entry \(\left(f_h*g_h\right)_1\) of the discrete convolution, which is given by
The following example computes the results of a one-dimensional discrete convolution via matrix-vector multiplication.
Example 2.1 (Convolution matrix)
Let \(g_h \coloneqq (0,\frac{1}{4},{\frac{\color{blue}1}2},\frac{1}{4},0)^T\) and \(f_h \coloneqq (0,1,1,1,0)^T\). Then we compute the discrete convolution via the following matrix-vector product:
.
Fig. 2.2 Original grayscale image of the popular cameraman test image and convolution with the horizontal Sobel filter.#
There exists also a discrete variant of the convolution theorem in Theorem 2.1, which we give in the following.
Theorem 2.2 (Discrete Convolution Theorem)
Let \(f,g: \Z^n\to \C\) be two discrete functions and at least one of them has compact support, i.e., it is zero outside a finite number of points. Then the following identity holds:\
Proof. Exercise. ◻