The Fourier Transform Introduction to Digital Signal Processing (886457) 6 1 / 56
Contents Introduction Fourier Transforms One-dimensional DFT Two-dimensional DFT Fourier Transforms Function in Octave Filtering in the Frequency Domain Ideal filtering Gaussian filtering 2 / 56
Introduction A transform represents the pixel values in some other, but equivalent form. Transforms allow for some very efficient and powerful algorithms. 3 / 56
Introduction The Fourier Transform is of fundamental importance to image processing. It allows us to perform tasks which would be impossible to perform any other way; its efficiency allows us to perform other tasks more quickly. 4 / 56
The Fourier Transform The Fourier Transform provides, among other things, a powerful alternative to linear spatial filtering; it is more efficient to use the Fourier transform than a spatial filter for a large filter. The Fourier Transform also allows us to isolate and process particular image frequencies, and so perform low-pass and high-pass filtering with a great degree of precision. 5 / 56
Background: Fourier Series Fourier series: Any periodic signals can be viewed as weighted sum of sinusoidal signals with different frequencies Frequency Domain: view frequency as an independent variable 6 / 56 (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.
The Fourier Transform Our starting place is the observation that a periodic function may be written as the sum of sines and cosines of varying amplitudes and frequencies. For example, in figure 4.1 we plot a function, and its decomposition in to sine functions. 7 / 56
8 / 56
Fourier Tr. and Frequency Domain DFT = Discrete Fourier Transform Time, spatial Domain Signals DFT Inverse DFT Frequency Domain Signals 9 / 56
The One-Dimensional DFT Since we only have to obtain a finite number of values, we only need a finite number of functions to do it. Consider for example the discrete sequence 1, 1, 1, 1, -1, -1, -1, -1, This can be expressed as the sum of only two sine functions; this is shown in figure 4.3. 10 / 56
11 / 56
Definition of the one dimensional DFT Suppose f = f 0, f 1, f(2),, f(n 1), is a sequence of length N. We define its discrete Fourier transform to be the sequencef = F 0, F 1, F(2),, F(N 1), F(u) = N 1 x=0 exp 2πi xu N f(x) The formula for the inverse DFT is very similar to the forward transform: N 1 f(x) = 1 N u=0 exp 2πi xu N F(u) 12 / 56
Periodicity of 1D DFT From DFT: F(u) = N 1 x=0 exp 2πi xu N f(x) -N 0 N 2N We display only in this range DFT repeats itself every N points (Period = N) but we usually display it for n = 0,, N-1 13 / 56
Conventional Display for 1D DFT f(x) DFT F(u) 0 N-1 0 N-1 Time Domain Signal Low frequency area High frequency area The graph F(u) is not easy to understand! 14 / 56
Conventional Display for DFT : FFT Shift F(u) FFT Shift: Shift center of the graph F(u) to 0 to get better Display which is easier to understand. 0 N-1 F(u) Low frequency area High frequency area -N/2 0 N/2-1 15 / 56
The Two-Dimensional DFT In two dimensions, the DFT takes a matrix as input, and returns another matrix, of the same size, as output. If the original matrix values are f(x, y), where x and y are the indices, then the output matrix values are F(u, v). We call the matrix F the Fourier transform. Given that an image may be considered as a twodimensional function f(x, y), it seems reasonable to assume that f can be expressed as sums of corrugation functions 16 / 56
corrugation 17 / 56
The Two-Dimensional DFT The forward and inverse transforms for an M N matrix, where for notational convenience we assume that the x indices are from 0 to M 1 and the y indices are from 0 to N 1 are: F(u, v) = M 1 x=0 N 1 y=0 exp 2πi xu M + yv N f(x, y) f(x, y) = 1 M 1 MN u=0 N 1 y=0 exp 2πi xu M + yv N F(u, v) 18 / 56
The Two-Dimensional DFT Notice that the Fourier transform filter elements can be expressed as products: exp 2πi xu M + yv N = exp 2πi xu M exp 2πi yv N We can break down our formulas above to simpler formulas that work on single rows or columns. 19 / 56
The Two-Dimensional DFT 20 / 56
Periodicity of 2D DFT 2D DFT: M 1 N 1 F(u, v) = exp 2πi x=0 y=0 xu M + yv N f(x, y) g(x,y) -M 0 For an image of size NxM pixels, its 2-D DFT repeats itself every N points in x- direction and every M points in y-direction. M 2M We display only in this range -N 0 N 2N 21 / 56 (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.
Conventional Display for 2D DFT F(u,v) has low frequency areas at corners of the image while high frequency areas are at the center of the image which is inconvenient to interpret. Low frequency area High frequency area (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. 22 / 56
2D FFT Shift : Better Display of 2D DFT 2D FFT Shift is a Octave function: Shift the zero frequency of F(u,v) to the center of an image. FFTSHIFT (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. Low frequency area High frequency 23 / 56 area
2D FFT Shift (cont.) : How it works -M 0 M Display of 2D DFT After FFT Shift -N 0 N 2N 2M Original display of 2D DFT (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. 24 / 56
Example of 2-D DFT Notice that the longer the time domain signal, The shorter its Fourier transform 25 / 56 (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition.
Example of 2-D DFT Notice that direction of an object in spatial image and Its Fourier transform are orthogonal to each other. (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. 26 / 56
Example of 2-D DFT 2D DFT Original image 2D FFT Shift 27 / 56
Example of 2-D DFT 2D DFT Original image 2D FFT Shift 28 / 56
Fourier Transforms in Octave The relevant Octave functions for us are: fft which takes the DFT of a vector, ifft which takes the inverse DFT of a vector, fft2 which takes the DFT of a matrix, ifft2 which takes the inverse DFT of a matrix, fftshift which shifts a transform 29 / 56
Complex Image Display Function 30 / 56
Example 1 Now we ll create a box, and then its Fourier transform: 31 / 56
Example 2 The cameraman image and its DFT 32 / 56
Filtering in Frequency Domain Ideal filtering Low pass filtering High pass filtering Gaussian filtering Low pass filtering High pass filtering 33 / 56
Basic Concept of Filtering in the Frequency Domain From Fourier Transform Property: g( x, y) f ( x, y) h( x, y) F( u, v) H( u, v) G( u, v) We cam perform filtering process by using Multiplication in the frequency domain is easier than convolution in the spatial Domain. (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. 34 / 56
Filtering in the Frequency Domain with FFT shift F(u,v) H(u,v) (User defined) g(x,y) FFT shift X 2D IFFT 2D FFT FFT shift f(x,y) G(u,v) In this case, F(u,v) and H(u,v) must have the same size and have the zero frequency at the center. 35 / 56
Ideal filtering Low pass filtering ต วกรองความถ ต าผ านแบบอ ดมคต เป นการกรอง ความถ ท จะยอมให ส ญญาณความถ ต าผ านไปได แต จะ ท าการลดขนาดส ญญาณความถ ส งออกไป โดยจะยอมให ความถ ต งแต 0 Hz จนถ ง Cutoff ผ าน ไปย งผลล พธ 36 / 56
Ideal Lowpass Filter H( u, v) 1 0 D( u, v) D( u, v) D D 0 0 Surface Plot 1 0.8 Ideal Lowpass Filter with D 0 = 5 0.6 0.4 0.2 0 Abrupt change in the amplitude 20 0-20 -20 0 20 37 / 56
Ideal Lowpass Filter 127 38 / 56
Example: Ideal Lowpass Filter 39 / 56
Example: Ideal Lowpass Filter 40 / 56
Ideal filtering High pass filtering ต วกรองความถ ส งผ านแบบอ ดมคต เป นการกรอง ความถ ท ยอมให ความถ ส งกว า cutoff ผ านไปย ง ผลล พธ และความถ ต งแต 0 Hz ถ ง cutoff จะไม ให ผ านออกไป จะลดทอนความถ ภายในวงกลม และจะไม ลดทอน ความถ ท งหมดท อย ภายนอกวงกลมน 41 / 56
42 / 56 (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. Ideal Highpass Filters 0 0 ), ( 1 ), ( 0 ), ( D v u D D v u D v u H where D(u,v) = Distance from (u,v) to the center of the mask. Ideal LPF Filter Transfer function
Example: Ideal Highpass Filters 43 / 56
Example: Ideal Highpass Filters 44 / 56
Example: Ideal Highpass Filters 45 / 56
Example: Ideal Highpass Filters 46 / 56
Gaussian filtering Low pass filtering Gaussian filters may be considered to be the most smooth of all the filters we have discussed so far, with ideal filters the least smooth 47 / 56
Gaussian Lowpass Filter Transfer function H( u, v) Where D 0 = spread factor. e D 2 ( u, v)/2d 2 0 (Images from Rafael C. Gonzalez and Richard E. Wood, Digital Image Processing, 2 nd Edition. Note: the Gaussian filter is the only filter that has no ripple and hence no ringing effect. 48 / 56
Gaussian Lowpass Filter We can create Gaussian filters using the fspecial function, and apply them to our transform. Note the use of the mat2gray function. The fspecial function on its own produces a low pass Gaussian filter with a very small maximum: 49 / 56
Example: Gaussian Lowpass Filter In each case, the final parameter of the fspecial function is the standard deviation; it controls the width of the filter. Clearly, the larger the standard deviation, the wider the function, and so the greater amount of the transform is preserved. 50 / 56
Example: Gaussian Lowpass Filter 51 / 56
Example: Gaussian Lowpass Filter 52 / 56
Gaussian Highpass Filters High pass filtering We can apply a high pass Gaussian filter easily; we create a high pass filter by subtracting a low pass filter from 1. 2 2 D ( u, v)/2d0 H( u, v) 1 e Where D 0 = spread factor. 53 / 56
Example: Gaussian Highpass Filters 54 / 56
Example: Gaussian Highpass Filters 55 / 56
References Dr. Nawapak Eua-Anant, Image Enhancement in the Frequency Domain, https://gear.kku.ac.th/~nawapak/178353/chapter04.ppt Gonzalez & Woods, Digital Image Processing (2002) Alasdair McAndrew, An Introduction to Digital Image Processing with Matlab (2004) 56 / 56