import numpy as np from numpy.fft import fft2,ifft2,fftshift import matplotlib.pyplot as plt from scipy.misc import imread img = imread('car.png',flatten=True) img_fft = fft2(img) # Hent terskler for slik at vi f?r ca like mange fft-koeffisienter i hver b?s [ikke et n?dvendig steg] thresholds = [np.percentile(np.abs(img_fft), i) for i in np.linspace(0, 100, 15)] plt.figure() ind = 1 for thr in thresholds: img_thr = img_fft.copy() img_thr[np.abs(img_fft) < thr] = 0 img_recon = ifft2(img_thr) # plt.subplot(7,4,ind) plt.imshow(np.log(np.abs(img_thr)+1),aspect='auto') #plt.imshow(np.log(np.abs(img_thr)+1),cmap='gray',aspect='auto') plt.title('Bevarte koeffsienter: %g %%'%(np.sum(img_thr != 0)*100.0/img.size)) # plt.subplot(7,4,ind+1) plt.imshow(np.abs(img_recon),cmap='gray',aspect='auto') plt.title('Rekonstruert bilde ved terskel: %d'%thr) ind += 2 plt.show()