assignment -3 - qil.uh.edu -3 1. dft implementation a. forward fourier transform b. inverse fourier...

Post on 21-May-2020

13 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Assignment -3

1. DFT Implementation

a. Forward Fourier transform

b. Inverse Fourier transform

c. Discrete Cosine transform

d. Magnitude of DFT

2. Frequency filtering

a. Ideal (Low and High Pass)

b. Butterworth (Low and High Pass)

c. Gaussian (Low and High Pass)

Due Date: Apr 7th , 11:59 PM

DFT Implementation

1. Input a matrix of integers (15X15)1. Compute forward Fourier transform

2. Compute inverse Fourier transform

3. Compute Discrete Cosine transform

4. Compute magnitude of DFT

Forward Fourier transform

Input 15X15 matrix (𝐼) Output DFT 15X15 matrix (𝐹)

i u

j v

DFT

Complex values

Forward Fourier transform

𝐹 𝑒, 𝑣 =

𝑖=0

π‘βˆ’1

𝑗=0

π‘βˆ’1

𝐼 𝑖, 𝑗 π‘’βˆ’ βˆ’12πœ‹π‘(𝑒𝑖+𝑣𝑗) , 𝑁 = 15

𝐹 𝑒, 𝑣 =

𝑖=0

π‘βˆ’1

𝑗=0

π‘βˆ’1

𝐼 𝑖, 𝑗 [cos2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 βˆ’ βˆ’1 sin

2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 ]

In python, βˆ’1 = 1𝑗

Forward Fourier transform

𝐹 𝑒, 𝑣 =

𝑖=0

π‘βˆ’1

𝑗=0

π‘βˆ’1

𝐼 𝑖, 𝑗 π‘’βˆ’ βˆ’12πœ‹π‘(𝑒𝑖+𝑣𝑗) , 𝑁 = 15

𝐹 𝑒, 𝑣 =

𝑖=0

π‘βˆ’1

𝑗=0

π‘βˆ’1

𝐼 𝑖, 𝑗 [cos2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 βˆ’ βˆ’1 sin

2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 ]

u = {0,..14}, v = {0,..14}

Inverse Fourier transform

Input 15X15 matrix (𝐼) Output DFT 15X15 matrix (𝐹)

i u

j v

IDFT

Complex values

Inverse Fourier transform

𝐼 𝑖, 𝑗 =

𝑒=0

π‘βˆ’1

𝑣=0

π‘βˆ’1

𝐹 𝑒, 𝑣 𝑒 βˆ’12πœ‹π‘(𝑒𝑖+𝑣𝑗) , 𝑁 = 15

𝐼 𝑖, 𝑗 =

𝑒=0

π‘βˆ’1

𝑣=0

π‘βˆ’1

𝐹 𝑒, 𝑣 [cos2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 + βˆ’1 sin

2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 ]

i = {0,..14}, j = {0,..14}

End up getting complex numbers

Discrete Cosine transform

𝐹 𝑒, 𝑣 =

𝑖=0

π‘βˆ’1

𝑗=0

π‘βˆ’1

𝐼 𝑖, 𝑗 [cos2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 ]

No complex part

Magnitude of DFT

𝐹 𝑒, 𝑣 =

𝑖=0

π‘βˆ’1

𝑗=0

π‘βˆ’1

𝐼 𝑖, 𝑗 [cos2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 βˆ’ βˆ’1 sin

2πœ‹

𝑁𝑒𝑖 + 𝑣𝑗 ]

𝑀 = |𝐹(𝑒, 𝑣)|

Please compute magnitude in the function. Do not use abs function.

Frequency filtering

β€’ Input Image

11

Computation of the DFTβ€’ Fast algorithms for the DFT are collectively referred to as

Fast Fourier Transform (FFT) algorithms.

β€’ We will not delve into the design of these, as they are available in most math library programs.β€’ Divide and conquer

β€’ Exploit Symmetry

β€’ Reduces complexity from 𝑂(𝑛2) to 𝑂(𝑛 log 𝑛)

Forward Fourier transform

1. Compute the Fourier transform (numpy has fftand opencv both has dft)

2. Compute the shift (Ex. Numpy has fftshift)

Note: Numpy represents real part and imaginary part in a single matrix, however, opencv uses two matrices to represent the same.

Displaying dft

β€’ Dft is one of the images that needs to be save.

β€’ However the magnitude of the dft could be large values

β€’ In order to save as an image that is visible,

1. Do a logarithmic compression (Ex. np.log(mag(dft))

2. Convert to uint8 to save it as greyscale image

Example

Mask

β€’ Write functions to compute six masks

1. Ideal Low Pass (one parameter: cutoff frequency)

2. Ideal High Pass (one parameter: cutoff frequency)

3. Butterworth Low Pass (Two parameters: cutoff and order)

4. Butterworth High Pass (Two parameters: cutoff and order)

5. Gaussian Low Pass (one parameter: cutoff frequency)

6. Gaussian High Pass(one parameter: cutoff frequency)

Mask

Filtering

β€’ Filter the image using convolution theorem

β€’ Filtered DFT is one of the images that needs to be saved.

β€’ Follow same process as before (DFT image)

Filtered DFT

Inverse Fourier transform

β€’ Compute the inverse shift (Ex. Numpy fft library has ifftshift)

β€’ Compute the inverse fourier transform (opencv has idft and numpy has ifft)

Filtered Image

β€’ The inverse Fourier transform will give complex numbers.

β€’ To transform into a meaningful image

1. Compute the magnitude

2. Do a full scale contrast stretch (to greyscale values)

3. Take negative if needed

Assignment -3

1. DFT Implementation(4 Pts)

2. Frequency filtering (11 Pts)

Total: 15 Pts.

Submission Instructions

Must use the starter code available in Github

Submission allowed only through Github

You will receive an email with invitation to join

Github classroom

Start by reading the readme.md file.

Instructions are available here

Github will automatically save the last commit

as a submission before the deadline

top related