Transcribed TextTranscribed Text

This assignment is focusing on image filtering. We will perform a simple sharpening filter with both OpenCV and the Fourier Transform Image sharpening (12 marks) Implement solution py according to the specification in the comments. Note that a lot of the starter code is already done for you. Places that you will have to implement yourself is marked as TODO. Implement the TODOs. Detailed instructions on the implementation specifications are provided as comments in the starter file. Examples in the jupyter notebooks for the lecture should help you lot. The five imwr ite calls should generate the following images, respectively, in the order of occurrence from left to-right and top-to-bottom: These image are also present in your package file for you to compare against. # solut ion py --- Filename: Descr ipt ion: Author Maintainer: Created: Version: Commentary: # Change Log: # Code: import time import cv2 import numpy as np from numpy fft import fftshift # Placeholder to stop auto-syntac checking from complaining TODO None def main(): # Read Image in grayscale and show img cv2.imread("input. jpg", 0) cv2.imwrite("orig.png",img) # # Create Filter # # TODO: 3 Marks: Create sharpen filter from the lecture, but with a # Gaussian filter form the averaging instead of the mean filter For the Gaussian filter, use a kernel with size 31x31 with sigma 5. For the unit # impulse set the multiplier to be 2. kernel TODO # Filter with FFT TODO: Mark: Pad filter with zeros to have the same size as the image, but with the filter in the center. This creates larger filter, that effectively does the same thing as the original image. kernel _padded TODO # Shift filter image to have origin on 0,0. This one is done for you. The exact theory behind this was not explained in class so you may skip this part. Drop by my office hours if you are interested. kernel_padded_shifted fftshift(kernel_ padded) # TODO: Mark: Move all signal to Fourier space (DET). img_fft TODO kernel_fft TODO # Display signals in Fourier Space #I put some visualization here to help debugging :-) cv2. imwrite( "orig_fft. png", np.minimum(1e-5 * hp.abs(fftshift(img_fft)), 1.0) 255.) cv2 imwrite( "filt_fft.png" np.minimum(1e 1 np.abs(fftshift(kernel_fft)), 1.0) 255.) # TODO: 1 Mark: Do filtering in Fourier space ngffiltered_fft TODO # TODO: 1 Mark: Bring back to Spatial domain (Inverse DFT) # TODO: 2 Marks: Throw away the imaginary part and clip between o and 255 # to make it a real image. img_sharpened TODO cv2.imwrite("res_fft.png", img_sharpened.astype(np.uint8)) # Filter with OpenCV # TODO: Mark: Use padded filter and cyclic padding (wrap) to get exact results # TOOD: Mark: Clip image for display img_sharpened TODO cv2.imwrite(' res_opencv.png", img_sharpened.astype(np.uint8)) v2.waitKey( -1) if __name_ == "__main_ main() exit(0) # ends here

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

# Code:

import time

import cv2
import numpy as np
from numpy.fft import fftshift
from matplotlib import pyplot as plt
import pdb

# Placeholder to stop auto-syntac checking from complaining
TODO = None

def imshow(img, title=""):
    plt.figure(figsize=(8, 8))
    plt.imshow(img, cmap="gray")
    _ = plt.yticks([])
    _ = plt.xticks([])

def imagesc(img, title=""):
    plt.figure(figsize=(8, 8))
    img_rescaled = img / abs(img).max() + abs(img).max() * 0.5
    plt.imshow(img_rescaled, cmap="gray", interpolation="lanczos")
    _ = plt.yticks([])
    _ = plt.xticks([])

def main():

    # Read Image in grayscale and show
    img_gray = cv2.imread("input.png", 0)
    cv2.imwrite("orig.png", img_gray)...

By purchasing this solution you'll be able to access the following files:

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available 3D Graphics Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats