MIT Logo

The questions below are due on Thursday May 08, 2025; 02:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

In this lab, we will synthesize and manipulate a familiar image by using frequency domain techniques.

Please note that there is no check-in for this lab.

We have provided utilities for loading, saving, and displaying images in the lib6003.image module. We have also provided utilities for taking 2D Fourier transforms and inverse transforms in the lib6003.fft module. Documentation of these utilities is available on the 6.3000 website (Help -> 6.3000 Software -> lib6003 API Reference).

The functions contained in the lib6003.image and lib6003.fft modules use NumPy arrays rather than lists. NumPy arrays implement a number of common operations very efficiently, and differ from lists in important ways:

  • NumPy arrays are homogenous (all objects in a numpy array are the same type)
  • Operators like +, -, abs, x.imag, x.real work element-wise on numpy arrays, and that enables much greater computational efficiency than writing a loop or list comprehension. For example, x+y computes the element-wise sum of the arrays x and y, and produces a new NumPy array. Similarly, x+2 produces a new Numpy array, adding 2 to each element of x.
  • 2-D NumPy arrays can be indexed using tuples, specifying first a row and then a column. For example, to grab the element at row 3 and column 4 from an array x, we can use the following notation: x[3,4]. NumPy arrays also support negative indices.

Note that, even when they represent images, NumPy arrays are indexed in row,column order (not in x,y order!). It will be important to keep this in mind as we move forward.

Discrete-Time Fourier Transforms of Rectangles

Our goal is to construct an image by combining a collection of white rectangles on a black background. We will specify each white rectangle as the product of a pulse in the horizontal direction times a pulse in the vertical direction.

Part a. Start by determining the DTFT of a 1D pulse f[n] of width W defined as follows:

f[n] = \cases{1&if $0\le n\lt W$\cr0&otherwise\cr}
where W is a positive integer.

Let F(\Omega) represent the 1D DTFT of f[n]. Derive a closed-form expression for F(\Omega).

Part b. Now define a shifted pulse f_{n0}[n] in terms of f[n] as follows:

f_{n0}[n]=f[n{-}n_0]
Let F_{n0}(\Omega) represent the 1D DTFT of f_{n0}[n]. Derive a closed-form expression for F_{n0}(\Omega).

Part c. Use the 1D results in the last parts to determine the 2D DTFT of a white rectangle g[r,c] as follows:

g[r,c]=\cases{1&if $0\le r\lt W_r$ and $0\le c\lt W_c$\cr0&otherwise\cr}
where W_r and W_c are integers that specify the widths in the vertical (r) and horizontal (c) directions, respectively.

Let G(\Omega_r,\Omega_c) represent the 2D DTFT of g[r,c]. Derive a closed-form expression for G(\Omega_r,\Omega_c).

Part d. Now define a shifted rectangle g_{r_0,c_0}[r,c] in terms of g[r,c] as follows:

g_{r_0,c_0}[r,c]=g[r{-}r_0,c{-}c_0]
Let G_{r_0,c_0}(\Omega_r,\Omega_c) represent the 2D DTFT of g_{r_0,c_0}[r,c]. Derive a closed-form expression for G_{r_0,c_0}(\Omega_r,\Omega_c).

Part e. Write a Python function to calculate G_{r_0,c_0}(\Omega_r,\Omega_c) for arbitrary integer values of r_0 and c_0 as well as arbitrary real values of \Omega_r and \Omega_c. The function should have the following form:

def G(Omega_r,Omega_c,W_r,W_c,r_0,c_0):
   ... your code here
   return your_answer
Include your function with your lab submission, along with a few test cases to check that your function is working correctly.

Hint: Beware of division by zero.

DTFT of MIT Logo

Let m[r,c] represent the following 21\times13 image (which is assumed to be zero outside of the indicated range), where white pixels correspond to a value of 1, and black to a value of 0. Assume that the point r\!=\!0,c\!=\!0 is in the upper left corner of the image, and r and c increase in the directions shown.

We would like to use the results from the previous part to evaluate M(\Omega_r,\Omega_c), which is the 2D DTFT of m[r,c]. Notice that you can express this image as a collection of white rectangles. The function G(Omega_r,Omega_c,r_0,c_0) computes values of the 2D DTFT of a single white rectangle. Since the Fourier transform of a sum of signals is equal to the sum of the Fourier transform of each, we can compute values of M(\Omega_r,\Omega_c) by summing the results from seven evaluations of G(Omega_r,Omega_c,r_0,c_0).

Write a program called M(Omega_r, Omega_c) that uses your G function to return values of M(\Omega_r,\Omega_c) at \Omega_r = Omega_r and \Omega_c = Omega_c.

DFT of MIT Logo

The 2D DFT of m[r,c] is a scaled and sampled version of the 2D DTFT M(\Omega_r, \Omega_c).

Part f. Assuming that C = 21 and R = 13, use your function from the previous section to calculate M[k_r, k_c]; then compute the inverse DFT to generate an image. Save your result using the png_write function to a file called m1a.png, and include that file with your lab submission.

Part g. Using the same function M(\Omega_r, \Omega_c), generate a second DFT by with C = 42 and R = 26. Compute the inverse DFT and save the image using png_write to a file called m1b.png and include that file with your lab submission.

Briefly describe the relation between the first and second images, and why that relation holds.

Enlarging the Logo by Scaling Frequency

In this section, we will develop a frequency-domain transformation to enlarge the MIT logo by a factor of 2, so that it occupies 42\times26 pixels rather than 21\times13 pixels.

Let m_2[r,c] represent the enlarged logo. Determine a closed form expression for M_2(\Omega_r,\Omega_c), the 2D DTFT of m_2[r,c], in terms of M(\Omega_r,\Omega_c).

Write a program called M_2(Omega_r, Omega_c) to return values of the 2D DTFT of m_2[r,c]. Your program should use the same versions of M(Omega_r, Omega_c) and G(r_0, c_0, W_r, W_c, Omega_r, Omega_c) that were used above.

Run your program and save the resulting image using png_write as m2.png and include that file in your lab submission.

Please upload a single zip file that contains your answers to all parts of this problem:

 No file selected