Presentation is loading. Please wait.

Presentation is loading. Please wait.

Frequency Domain Processing

Similar presentations


Presentation on theme: "Frequency Domain Processing"— Presentation transcript:

1 Frequency Domain Processing
Chapter 4 Frequency Domain Processing Objectives: We will learn about filters that are carried out in the frequency domain. In addition to being the base for linear filtering, Fourier Transform offers considerable flexibility in the design and implementation of filtering solutions in areas such as image enhancement, image restoration, image data compression, and a some other applications. The frequency and spatial filtering can be combined to achieve results that are beyond what each can achieve individually.

2 Fourier Transform Fourier transform of a function f(x) (one-dimensional) is: where We can obtain the f(x) using the inverse Fourier Transform. The two-dimensional version of this equations are: And the inverse Fourier Transform for this one can be shown as:

3 Discrete Fourier Transform
To do any of these on a computer we need the discrete versions. For one dimensional case suppose we have M discrete points. In the two dimensional case, assume we have M and N discrete points in x and y directions respectively. One-dimensional: The inverse transform is:

4

5 Discrete Fourier Transform Two-dimensional:
Where, f(x,y) denotes the input image with: x = 0, 1, 2, …, M-1 and y = 0, 1, 2, …, N-1 representing the number of rows and columns of the M-by-N image. The inverse transform is: Remember that we have: Since images are 2-D arrays, we work with these two.

6 Discrete Fourier Transform

7 What are they? The value of the transformation at the origin of the frequency domain [I.e., F(0,0)] is called the dc component of the Fourier Transform. F(0,0) is is equal to MN times the average value of f(x,y) Even if f(x,y) is real, it transformation in general is complex. To visually analyze a transform, we need to compute its spectrum. I.e., compute the magnitude of the complex variable F(u , v) and display it as an image. F(u,v) can also be represented as:

8 Discrete Fourier Transform Example
Compute the Fourier transform of the function shown below: x f(x,y) X Y y A

9 Example – FFT Compute the FFT of f(x) = 2x. Let’s only computes for 4 frequencies.

10 F(2) = -1 F(3) = -1 - j

11 Example >> f = zeros(512,512); >> f(245:265,235:275)=1; >> imshow(f)

12 Example - cont >> F = fft2(f); >> F2 = log(abs(F)); >> imshow(F2)

13 Example – cont Centering the spectrum
F = fft2(f); F2 = log(abs(F)); imshow(F2) for i = 1:512 for j = 1:512 f(i,j) = (-1)^(i+j)*f(i,j); end figure,imshow(F2)

14 This is what happened

15

16 Filtering in the frequency domain
In general, the foundation of linear filtering in both the spatial and frequency domains is the convolution theorem: Conversely, we will have: Here, the symbol “*” indicates convolution of the two functions, and the expression on sides of the double arrow denotes Fourier Transform pair. We are interested in the first one, where filtering in spatial domain consists of convoluting an image f(x,y) with a filter mask, h(x,y). Based on the convolution theorem we can obtain the same result by multiplying F(u,v) by H(u,v), the Fourier transform of the spatial filter. It is common to refer to H(u,v) as the filter transfer function.

17 Convolution and Correlation Example: Occurrences of a letter in a text

18 Read the Original Image, Store it in array text
(Determine the size, Let’s say p, q) Read the image of the letter, Store it in an array l (Determine the size, Let’s say n, m) Rotate the image of the letter by 180 Compute the FFT of the letter, pad it to the p, q size Compute the FFT of the text

19 Multiply element-by-element the two
Take the Real part of the result Multiply element-by-element the two Find the MAX Threshold based on the MAX Display

20 Based on convolution theorem:
To obtain corresponding filtered image in the spatial domain we simply compute the inverse Fourier transform of the product of H(u,v)F(u,v). This is identical to what we would obtain by using convolution in the spatial domain, as long as the filter mask h(x,y) is the inverse Fourier transform of H(u,v). Convolving periodic functions can cause interference between adjacent period if the periods are close with respect to the duration of the nonzero parts of the functions.

21 This interference, wraparound error, can be avoided by padding the functions with zeros as explain below. Assume that functions f(x,y) and h(x,y) are of size AXB and CXD, respectively. Form two extended (padded) functions both of size PXQ by appending zeros to f and h. The wraparound error is avoided by choosing: In MATLAB, we will use F = fft2(f, PQ(1), PQ(2)) This appends enough zeros to f such that the resulting image is of size PQ(1)*PQ(2), then computes the FFT.

22

23

24

25 Basic Steps in DFT Filtering

26 Basic Steps in DFT Filtering
Obtain the padding parameters using function paddedsize: PQ = paddedsize(size(f)); Obtain the Fourier transform with padding: F = fft2(f, PQ(1), PQ(2)); 3. Generate a filter function, H, of size PQ(1)XPQ(2) using one of the methods discussed in the remainder of this chapter. The filter must be in the format shown in Fig 4.4b. If it is not in that format, use shift to make it. 4. Multiply the transform by the filter: G = H .* F

27 Basic Steps in DFT Filtering
5. Obtain the real part of the inverse FFT of G: g = real(ifft2(G)); 6. Crop the top, left rectangle to the original size: g = g(1:size(f, 1), 1:size(f, 2));

28 Example for DFT Filtering
Try this for f = [0 0; 1 1]; PQ = paddedsize(size(f)); Fp = fft2(f, PQ(1), PQ(2)); HP = lpfilter(‘gaussian’, PQ(1), PQ(2), 2*sig); GP = HP .* Fp; gp = real(ifft2(GP)); gpc = gp(1:size(f,1), 1:size(f,2)); %cropping imshow(gp, [ ]) Similar result as: w = fspecial('gaussian', 3,3); gnew = imfilter(double(f), w)

29 Obtaining Frequency Domain Filters from Spatial Filters
In general, filtering in the spatial domain is more efficient computationally than frequency domain filtering when the filters are small. One obvious approach for generating a frequency domain filter, H, that corresponds to a given spatial filter, h, is to let: H = fft2(h, PQ(1), PQ(2)), where the values of vector PQ depend on the size of the image we want to filter, as discussed in the last section. But we need to know:

30 Obtaining Frequency Domain Filters from Spatial Filters
How to convert spatial filters into equivalent frequency domain filters, How to compare the results between spatial domain filtering using function imfilter, and frequency domain filtering.

31 F = fft2(f) S = fftshift(log(1+ abs(F))); S = gscale(S); imshow(S) 600x600 image

32 Generate the spatial filter using fspecial:
h = fspecial(‘sobol’) h = 1 0 -1 2 0 -2 To view a plot of the corresponding frequency domain filter:

33 freqz2(h)

34 PQ = paddedsize(size(f)); H = freqz2(h, PQ(1), PQ(2));
H1 = ifftshift(H); Origin at the top

35 abs(h)

36 abs(H1)

37 Next, we generate the filtered images. In spatial domain we use:
gs = imfilter(double(f), h); Which pads the border of the image with 0. The filtered image obtained by frequency domain processing: gf = dftfilt(f, H1); Download the dftfilt, paddedsize, and other related files from the notes web page.

38 gs = imfilter(double(f), h);

39 gf = dftfilt(f, H1); Negative values are presented. Average is below the mid-gray value.

40 imshow(abs(gs), [ ])

41 imshow(abs(gf), [ ])

42 Using thresholding we can see the boundaries better
abs(gs) > 0.2*abs(max(gs(:))))

43 Using thresholding we can see the boundaries better
abs(gf) > 0.2*abs(max(gf(:))))

44 Generating Filters Directly in the Frequency Domain
We discussed circularly symmetric filters that are specified as various functions of distance from the origin of the transform. One of the things we need to compute is the distance between any point and a specified point in the frequency rectangle. In MATLAB, for FFT computations the origin of the transform is at the top-left of the frequency rectangle. Thus, our distance is also measured from that point. In order for us to compute such a distance, we need the meshing system. This is what we call meshgrid array and is generated by dftuv function.

45 Example Here is an example of distance computation. In this example we will compute the distance squared from every point in a rectangle of size 8x5 to the origin of the frequency rectangle. >> [U , V] = dftuv(8, 5); This computes meshgrid frequency matrices U and V both of size 8-by-5. >> D = U.^2 + V.^2

46 U = V =

47 D =

48 U = V = D =

49 function [U, V] = dftuv[M, N] u = 0: (M-1); v = 0: (N-1);
idx = find(u > M/2); u(idx) = u(idx) – M; idy = find(v > N/2); v(idy) = v(idy) – N; [U, V] = meshgrid(u, v); The meshgrid function will produce two arrays. Rows on U are copies of rows in u and columns on V are copies of columns on v.

50 The distance with respect to the center of the frequency rectangle can be computed as:
>> fftshift(D) ans =

51 Lowpass Frequency Domain Filters
An Ideal Lowpass Filter (ILPF) has the transfer function: Where D0 is a specified non-negative number and D(u,v) is the distance from point (u, v) to the center of the filter. The D(u,v) = D0 falls on a circle. Since we multiply filter H by the Fourier transform of an image, an ideal case would be where all components of F outside the circle gets “cut off”, i.e. gets multiplied by 0 and keep the points in/on the circle unchanged.

52 Lowpass Frequency Domain Filters – cont.
A Butterworth lowpass filter (BLPF) of order n, with a cutoff frequency at distance D0 from the origin, has the transform function: Unlike ILPF, this one does not have a shape discontinuity at D0. In this transformation when D(u,v) = D0, H(u,v) will be 0.5, or down 50% from its maximum value. The Gaussian lowpass filter (GLPF) is given by: Where is the standard deviation. If we let = D0 we will obtain: What would be H(u,v) For D(u,v) = D0?

53 Where p = D(u,v)/D0

54 Example: Create a 3x3 filter in the frequency domain.

55 Example Original Image f

56 PQ = paddedsize(size(f));
[U , V] = dftuv(PQ(1), PQ(2) ); D0 = 0.05*PQ(2); F = fft2(f, PQ(1), PQ(2)); H = exp(- (U.^2 + V.^2)/(2*(D0^2))); figure, imshow(fftshift(H), [ ] )

57 Spectrum: figure, imshow(log(1 + abs(fftshift(F),[ ] )

58 g = dftfilt(f, H); figure, imshow(g , [ ] ) Note: The lpfilter generates the transfer functions of all the lowpass filters discussed in this chapter. You need to copy this file from the notes web page.

59 Sharpening Frequency Domain Filters
Just as lowpass filtering blurs an image, the opposite will happen in case of highpass filtering. Highpass filters sharpen the image by attenuating the low frequencies and leaving the high frequencies of the Fourier transforms relatively unchanged. Basics of highpass filtering Given the transfer function H1p(u,v) of a lowpass filter, we obtain the transfer function of the corresponding highpass filter by using the simple relation: Hhp(u, v) = 1 – H1p(u, v) The function hpfilter is used in MATLAB to generate highpass filters.

60 Highpass Filter Options with hpfilter
hpfilter(type, M, N, D0, n) It creates the transfer function of a highpass filter, H, of the specified TYPE and size M-by-N. ‘ideal’ : Ideal highpass filter with cutoff frequency D0. No need for n, and D0 must be positive. ‘btw’ : Butterworth highpass filter of order n, and cutoff D0. The default value for n is 1.0. D0 must be positive. ‘gaussian’ : Gaussian highpass filter with cutoff (standard deviation) D0. No need for n, and D0 must be positive.

61 Example – Ideal highpass filter
H = fftshift(hpfilter(‘ideal’, 500, 500, 50 )); mesh(H(1:10:500, 1:10:500)); axis([ ]) colormap([0 0 0]) axis off

62 Example – Ideal highpass filter
Corresponding image to This one is shown on the right hand side figure, imshow(H, [ ] )

63 Example – Butterworth highpass filter
H = fftshift(hpfilter(‘butterworth’, 500, 500, 50 )); mesh(H(1:10:500, 1:10:500)); axis([ ]) colormap([0 0 0]) axis off

64 Example – Butterworth highpass filter
Corresponding image to This one is shown on the right hand side figure, imshow(H, [ ] )

65 Example – Gaussian highpass filter
Corresponding image to This one is shown on the right hand side

66 PQ = paddedsize(size(f));
D0 = 0.05*PQ(1); H = hpfilter(‘gaussian’, PQ(1), PQ(2), D0); g = dftfilt(f, H); figure, imshoow(g, [ ] )

67 High-Frequency Emphasis Filtering
Highpass filtering zero out the dc term, thus reducing the average value of an image to 0. An approach to compensate for this is to add an offset to a highpass filter. When an offset is combined with multiplying the filter by a constant greater than 1, the approach is called high-frequency emphasis. The multiplier increases the amplitude of low frequencies, but low frequency effects on enhancement are less than those of high frequencies. The high-frequency emphasis transfer function is defined as: Hhfe(u, v) = a + bHhp(u,v) Where a is the offset, b is the multiplier, and Hhp(u,v) is the transfer function of a highpass filter.


Download ppt "Frequency Domain Processing"

Similar presentations


Ads by Google