from __future__ import division from nt_toolbox.general import * from nt_toolbox.signal import * %pylab inline %matplotlib inline %load_ext autoreload %autoreload 2 n = 256 N = n**2 name = 'nt_toolbox/data/flowers.png' x0 = load_image(name, n) imageplot(x0) sigma = .08 y = x0 + sigma*random.standard_normal(x0.shape) imageplot(clamp(y)) cconv = lambda a,b : real(ifft2(fft2(a)*fft2(b))) normalize = lambda h : h/sum(h.flatten()) t = transpose( concatenate( (arange(0,n/2), arange(-n/2,0) ) ) ) [Y,X] = meshgrid(t, t) h = lambda mu: normalize(exp(-(X**2 + Y**2)/ (2*mu**2))) mu = 10 subplot(1,2, 1) imageplot(fftshift(h(mu))) title('h') subplot(1,2, 2) imageplot(fftshift(real(fft2(h(mu))))) title('$\hat h$'); imageplot(h(mu)) denoise = lambda x,mu : cconv(h(mu), x) imageplot(denoise(y, mu)) run -i nt_solutions/denoisingsimp_2b_linear_image/exo1 run -i nt_solutions/denoisingsimp_2b_linear_image/exo2 imageplot(denoise(y, mu)) P = 1/N * ( abs(fft2(x0))**2 ) h_w = real(ifft2(P / (P + sigma**2))) u = fftshift(h_w) imageplot( u[n/2-10:n/2+10,n/2-10:n/2+10] ) imageplot( cconv(y,h_w) )