Skip to content

Assignment 5

drebain edited this page Mar 4, 2020 · 1 revision

For this assignment you will be given partially completed skeleton code that contains some of the logic you will need. All areas that you need to add or modify code to to complete the assignment requirements will be marked with a TODO comment and some more specific instructions. It is not necessary to add or modify code outside these sections.

Tasks

(3 marks) Create a Sharpen Filter

Create a 31x31 filter array containing the sharpening filter that was described in class. The filter has two components: U and G.

  • U is a unit impulse filter, which is all zeros except for the center value which is one.
  • G is a 2D Gaussian filter where each position (x, y) has the value g(x)*g(y) where g is the provided 1D Gaussian.

The final filter should be computed as 2 * U - G.

(1 mark) Zero-Pad the Filter

Make a copy of the filter which has zeros added to the outside so that it is the same shape as the input image.

(1 mark) Apply a 2D Discrete Fourier Transform

Use the numpy fft2 function to transform both the padded filter and input image into the Fourier space.

(1 mark) Apply the Filter in Fourier Space

Use the Convolution Theorem to apply the filter in the Fourier domain.

(3 marks) Convert the Fourier Space Result to an Image

Use the numpy ifft2 function and convert the result from above back to a real-valued image with valid (0-255) intensity values.

(2 marks) Apply the Filter Using Convolution

Use the cv2.filter2D function to apply the original filter to the image directly with a convolution. This should produce the same result as the steps above.

Resources

This assignment will involve some more advanced use of numpy indexing to build the filter. You will probably want to read about some of the advanced features that are available to avoid long and complex for-loops:

Numpy Indexing

You will also need to use Fast Fourier Transform functions and a filtering function: