Two-Dimensional Signal Processing and Image De-noising Alec Koppel, Mark Eisen, Alejandro Ribeiro March 14, 2016 Before we considered (one-dimensional) discrete signals of the form x : [0, N 1] C where N is the duration, having elements x(n) for n [0, N 1]. Extend this definition to two dimensions by considering the set of ordered pairs x : [0, M 1] [0, N 1] C x = {x(m, n) : m [0, M 1], n [0, N 1]}. (1) We can think of x as the set of values along the integer lattice in the twodimensional plane, hence as elements of a discrete spatial domain. We associate these signals with the space of complex matrices C M N. The inner product for two signals x and y, both of duration M N, in twodimensions is a natural extension of the one-dimensional case, and is defined as x, y := M 1 m=0 x(m, n)y (m, n). (2) n=0 As before, we define the energy of a two-dimensional signal x as x, x = x 2. We say two signals are orthogonal in two-dimensions if x, y = 0 whenever x = y, and if in addition both vectors have unit energy, i.e. x = y = 1 they are said to be orthonormal. The discrete twodimensional impulse δ(m, n) is defined as { 1 if n = m δ(m, n) = (3) 0 if n = m The discrete complex exponential e kl, (m, n) in two-dimensions at fre- 1
quencies k and l is the signal e kl, (m, n) = 1 e j2πkm/m e j2πln/n = 1 e j2π(km/m+ln/n). (4) It is a straight forward computation to check that e kl, is orthonormal to e pq, for k = p, l = q. The two-dimensional discrete Fourier transform (DFT) of x is the signal X : Z 2 C where the elements X(k, l) for all k, l Z are defined as X(k, l) := 1 M 1 x(m, n)e j2πkm/m e j2πln/n (5) m=0 n=0 The arguments k and l of the signal X(k, l) are called the vertical and horizontal frequency of the DFT and the value X(k, l) the frequency component of the given signal x. As in the one-dimensional case, when X is the DFT of x we write X = F(x). Recall that for a complex exponential, discrete frequency k is equivalent to (real) frequency f k = (k/n) f s, where N is the total number of samples and f s the sampling frequency. An alternative form of the 2d DFT is to realize that the sum in (5) is defining a two-dimensional inner-product between x and the complex exponential e kl, (m, n) with elements e kl, (m, n) = (1/ )e j2π(km/m+ln/n). We can then write X(k, l) := 1 M 1 m=0 ( ) x(m, n)e j2πln/n e j2πkm/m n=0 = 1 M 1 x(m, ), e ln e j2πkm/m M m=0 = x(m, ), e ln, e km = x, e kl, (6) which allows us to view X(k, l) as a measure of how much the signal x resembles an oscillation of frequency k in the vertical direction and l in the horizontal direction. Note that the inner products in the two middle equalities above are scalar, whereas the last is in two dimensions, as may be noted by the bold-face type. Because the complex exponential is (M, N)-periodic, the 2d DFT val- 2
ues X(k, l) and X(k + M, l + N) are equal, i.e., X(k + M, l + N) = 1 M 1 x(m, n)e j2π(k+m)m/m e j2π(l+n)n/n m=0 n=0 = 1 M 1 x(m, n)e j2πkm/m e j2πln/n m=0 n=0 = X(k, l) (7) The relationship in (7) means that the DFT is periodic in in both directions with period M and N respectively, while it is defined for all k, l Z 2, only M N values are different. As in the 1d case, we work with the canonical set of frequencies k, l [0, M 1] [0, N 1] for computational purposes, and the set of frequencies k, l [ M/2, M/2] [ N/2, N/2] for interpretation purposes. This latter canonical set contains (M + 1)(N + 1) frequencies instead of M N. As before, we may shift the values of the 2-d DFT to convert from one canonical set to another using periodicity: X( k, l) = X(M k, N l) (8) for all k, l [ M/2, M/2] [ N/2, N/2]. The operation in (8) is a chop and shift, from which we may recover the DFT values for the canonical set [ M/2, M/2] [ N/2, N/2] from the canonical set [0, M 1] [0, N 1]. Simply chop the frequencies in the box [M/2, M 1] [N/2, N 1] and shift them to the front of the set as in the onedimensional case. For the purposes of this homework, when you are asked to report a DFT, you should report the DFT for the canonical set [ M/2, M/2] [ N/2, N/2]. Further define the 2d inverse Discrete Fourier Transform (2d idft) F 1 (X) as the two-dimensional signal x(m, n) k=0 x(m, n) := 1 M 1 = 1 M/2 X(k, l)e j2πkm/m e j2πln/n l=0 N/2 k= M/2+1 l= N/2+1 X(k, l)e j2πkm/m e j2πln/n (9) The expression in (9) means that any arbitrary signal x in two dimensions may be represented as a sum of oscillations, as in the one dimensional case. Moreover, conjugacy means we can represent the sum (9) with only half as many terms. This means that we can effectively represent signals using only particular DFT coefficients under some conditions. 3
This observation is the foundation of image de-noising and compression methods which are the focus of the this and next week s lab assignments. For the subsequent questions, you may assume that M = N so that signals are of dimension N 2. 1 Two Dimensional Signal Processing 1.1 Inner products and orthogonality. Write down a function that takes as 1.1input Inner two-dimensional products and signals orthogonality x and y and outputs their inner product. Each signal is now defined by N 2 complex numbers. 1.2 Discrete Complex Exponentials. Write down a function that takes 1.2 as input Discrete the frequencies Complex k, l and Exponentials signal duration N and returns three matrices of size N 2, the first of which contains the values of e kl,n and the later two contain its real and imaginary parts. 1.3 Unit Energy 2-D Square Pulse. The two dimensional square pulse 1.3 is defined Unit asenergy 2-D Square Pulse L (m, n) = 1 L 2 if 0 m, n < L, L (m, n) = 0 if m, n L. (10) Write down a function that takes as input the signal duration T, T 0, and sampling frequency f s and outputs the square pulse as an array of size N 2 as well as the N N the signal duration. Plot the two dimensional square pulse for T = 32s, f s = 8Hz, and T 0 =.5. (Use MATLAB s imshow function). 1.4 Two-Dimensional Gaussian Signals. The Gaussian pulse centered 1.4 at µ, when Two-Dimensional t and s are uncorrelated, Gaussian is defined Signals as x(t, s) = e [(t µ)2 +(s µ) 2 ]/(2σ 2). (11) Write down a function which takes as input µ, σ and T s, and outputs the Gaussian pulse in two-dimensions. Recall that as in the one-dimensional case, we sampled t [ 3σ, 3σ] in increments of size T s. Plot the two dimensional Gaussian for µ = 2 and σ = 1. Note how these signals look when projected onto a single dimension. 4
1.5 DFT in two dimensions. Modify your function for the one dimensional DFT in inlabtwo 2 sodimensions that it now computes the DFT of a two-dimensional 1.5 signal. This computation may be expressed in terms of an inner product (written for question 1.2) of the two-dimensional discrete complex exponential (question 1.2). Compute the DFT of a 2d Gaussian pulse with µ = 0 and σ = 2. Plot your results in the two-dimensional plane. 1.6 idft in Two Dimensions. Write down a function which takes as 1.6 input idft a two-dimensional in Two Dimensions signal of duration N 2 and computes its twodimensional idft [cf. (9)]. Exploit conjugacy in your computation so that you only need to take in (N/2) 2 DFT coefficients. Compute the idft associated with the DFT of the Gaussian pulse you computed in the previous question. Plot this signal and compare it with the original Gaussian pulse. 2 Image Filtering and de-noising We may de-noise corrupted images using spatial information about the signal. To do this, we consider the two-dimensional convolution of signals x and y, denoted by x y, and defined as [x y](m, n) := = k= l= M 1 k=0 x(k, l)y(m k, n l) x(k, l)y(m k, n l) (12) l=0 The standard way to perform image de-noising is to convolve the image with a Gaussian pulse. To implement this technique, start by defining the Gaussian pulse associated with a 2-D signal x as G σ (x) = 1 2πσ 2 e x 2 2σ 2 (13) where x 2 = x, x. With two-dimensional signal (image) x the spatial de-noising technique we consider is x de-noised = G σ x. (14) 5
2.1 Spatial De-noising. Implement the technique in (14) without using 2.1 the 2-DSpatial DFT byde-noising convolving the image with the Gaussian pulse directly. Hint: MATLAB has a built in function to perform the convolution in two dimensions. Try your implementation in the spatial domain out for σ = 1, 4, 16 on sample images A and B. Do you observe significant denoising performance differences when varying σ? 6