import numpy as np from numpy.fft import fft2,ifft2,fftshift import matplotlib.pyplot as plt from scipy.misc import imread # Lager 2D vindu med st?rrelse win_size[0] x win_size[1]: def tukeywin(win_size,alpha): N,M = win_size # h = np.zeros((2,max(N,M))) # for i in range(2): sz = win_size[i] # n1 = int(round(alpha*(sz-1)*0.5)) n1_coor = np.arange(n1) # til ? regne ut verdiene til cosinus-ene # n2 = int(round((sz-1)*(1-alpha*0.5))) # n3_coor = np.arange(n2,N) # h[i,:n1] = 0.5*(1 + np.cos(np.pi*(2*n1_coor/(alpha*(sz-1)) - 1))) h[i,n1:n2] = 1 h[i,n2:] = 0.5*(1 + np.cos(np.pi*(2*n3_coor/(alpha*(sz-1)) - 2/alpha + 1))) # return np.outer(h[0,:N],h[1,:M]) img = imread('lena.png',flatten=True) w = tukeywin(img.shape,0.5) img_w = img*w img_fft = fftshift(fft2(img)) img_w_fft = fftshift(fft2(img_w)) plt.figure() plt.subplot(2,2,1) plt.imshow(img,cmap='gray') plt.title("Uten vindu") plt.subplot(2,2,2) plt.imshow(np.log(np.abs(img_fft) + 1),cmap='gray') plt.title("Amplitudespekteret til bildet uten vindu") plt.subplot(2,2,3) plt.imshow(img_w,cmap='gray') plt.title("Med vindu") plt.subplot(2,2,4) plt.imshow(np.log(np.abs(img_w_fft)+1),cmap='gray') plt.title("Amplitudespekteret til bildet med vindu") plt.show()