Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# import necessary packages # reading / writing image files from skimage import io from skimage import color # array operations import numpy as np

# import necessary packages
# reading/writing image files
from skimage import io
from skimage import color
# array operations
import numpy as np
# displaying images and plots
import matplotlib as mpl
import matplotlib.pyplot as plt
# mathematical calculations
import math
# signal processing operations
from scipy import signal
# random number generation
from scipy.stats import norm
# DFT calculations
from scipy import fftpack as ft
# STEP 3 Estimate the power spectrum of the observed (blurred and noisy) image
# ADD YOUR CODE HERE
# for every 64x64 block of the observed image:
# window the block with a Hanning window (use a taper length of 6)
# my_winHanning(nSize, nTaper):
# take the DFT of each block
# calculate the magnitude-squared of DFT's
# obtain P_g(k,l) as the average over the blocks (there should be 64 blocks)
def my_winHanning(nSize, nTaper):
assert nTaper >0
assert nSize >2* nTaper
# create an array to hold the window
winHann = np.ones(nSize)
# taper left and right sides
val = math.pi / nTaper
for n in range(nTaper):
# calculate taper
w =0.5+0.5* math.cos(n * val)
# assign right taper
winHann[nSize - nTaper + n]= w
# assign left taper
winHann[nTaper -1- n]= w
return winHann
height, width = imgBlurredNoisy.shape
block_size =64
taper_length=6
power_spectrum_total=0
num_blocks=0
for i in range(0, height, block_size):
for j in range(0, width, block_size):
img_block = imgBlurredNoisy[i:i+block_size, j:j+block_size]
window = my_winHanning(block_size, taper_length)
windowed_block = img_block * window
fft_block = ft.fft2(windowed_block)
power_spectrum = np.abs(fft_block)**2
power_spectrum_total += power_spectrum
num_blocks +=1
P_g = power_spectrum_total / num_blocks The image is 256x256. I get 64x64 where I should get 4x4 matrix. Could you explain why and fix the code? Thank you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago