using PyPlot using NtToolBox # using Autoreload # arequire("NtToolBox") n0 = 512 f = rescale(load_image("NtToolBox/src/data/lena.png", n0)); figure(figsize = (5,5)) imageplot(f, "Image f"); figure(figsize = (5,5)) imageplot(f[Int(n0/2 - 32) : Int(n0/2 + 32), Int(n0/2 - 32) : Int(n0/2 + 32)], "Zoom") figure(figsize = (8,8)) imageplot(-f, "-f", [1, 2, 1]) imageplot(f[end:-1:1, :], "Flipped", [1, 2, 2]) k = 9; #size of the kernel h = ones(k, k) h = h/sum(h); #normalize fh = conv2(Array{Float64, 2}(f), h); figure(figsize = (5,5)) imageplot(fh, "Blurred image") F = plan_fft(f) F = (F*f)/n0; println(@sprintf("Energy of Image: %f", norm(f))) println(@sprintf("Energy of Fourier: %f", norm(F))) L = fftshift(log(abs(F) + 1e-1)); figure(figsize = (5,5)) imageplot(L, "Log(Fourier transform)") M = Base.div(n0^2, 64); include("NtSolutions/introduction_4_fourier_wavelets/exo1.jl") ## Insert your code here. figure(figsize = (7, 6)) subplot(2, 1, 1) plot(f[: , Base.div(n0, 2)]) xlim(0, n0) title("f") subplot(2, 1, 2) plot(fM[: , Base.div(n0, 2)]) xlim(0, n0) title("f_M") show() T = .2; F = plan_fft(f) F = (F*f)/n0; FT = F .* (abs(F) .> T); L = fftshift(log(abs(FT) + 1e-1)) figure(figsize = (5,5)) imageplot(L, "thresholded Log(Fourier transform)") fM = plan_ifft(FT) fM = real(n0*(fM*FT)); figure(figsize = (5,5)) imageplot(clamP(fM), @sprintf("Linear, Fourier, SNR = %.1f dB", snr(f, fM))) m = sum(FT .!= 0) print(@sprintf("M/N = 1/%d" ,(n0^2)/m)) include("NtSolutions/introduction_4_fourier_wavelets/exo2.jl") ## Insert your code here. Jmin = 0; fw = NtToolBox.perform_wavelet_transf(f, Jmin, + 1); # using NPZ # test = npzread("pgsh.npy") figure(figsize = (10, 10)) NtToolBox.plot_wavelet(fw) title("Wavelet coefficients") include("NtSolutions/introduction_4_fourier_wavelets/exo3.jl") ## Insert your code here. T = .15 fwT = fw.*(abs(fw) .> T); figure(figsize = (15,15)) subplot(1, 2, 1) plot_wavelet(fw) title("Original coefficients") subplot(1, 2, 2) plot_wavelet(fwT) title("Thresholded coefficients") show() fM = NtToolBox.perform_wavelet_transf(fwT, Jmin, -1) figure(figsize = (5, 5)) imageplot(clamP(fM), @sprintf("Approximation, SNR, = %.1f dB", snr(f, fM))) include("NtSolutions/introduction_4_fourier_wavelets/exo4.jl") ## Insert your code here. figure(figsize = (7, 6)) subplot(2, 1, 1) plot(f[:, Base.div(n0, 2)]) title("f") subplot(2, 1, 2) plot(fM[:, Base.div(n0, 2)]) title("f_M") show()