using PyPlot using NtToolBox n = 512 f = load_image("NtToolBox/src/data/wood.png",n,1,1,0); figure(figsize = (5,5)) imageplot(f); z = zeros(1,1,size(f,3)) fe = [z reshape(f[1,:,:], (1,size(f,2),size(f,3))) z; reshape(f[:,1,:], (size(f,1),1,size(f,3))) f reshape(f[:,end,:], (size(f,1),1,size(f,3))); z reshape(f[end,:,:], (1,size(f,2),size(f,3))) z]; laplacian = x -> 4*x - ( circshift(x,(0, 1)) + circshift(x,(1,0)) + circshift(x,(-1,0)) + circshift(x,(0,-1)) ) d = laplacian(fe) d = d[2:end-1, 2:end-1, :]; Y = repeat(0:n-1,outer=(1,n)) X=Y' U = 4 - 2*cos(2*X*pi/n) - 2*cos(2*Y*pi/n); P = fft(d,(1,2))./repeat(U, outer=(1, 1, size(f,3))) P[1,1,:] = sum(sum(f,1),2); p = real(ifft(P,(1,2))); mydisp = x -> [x x; x x] figure(figsize = (10,10)) imageplot(mydisp(f), "Original, periodized", [1,2,1]) imageplot(mydisp(p), "Periodic layer, periodized", [1,2,2]); include("NtSolutions/graphics_1_synthesis_gaussian/exo1.jl") ## Insert your code here. f0 = mean(p,3)[:,:,1]; u = f0 u[1,1] = 0 u[2,1] = 1 figure(figsize = (5,5)) imageplot(clamp(u,0,1)) w = randn(n,n)/n w = w-mean(vec(w)) + 1/n^2; f = real(ifft(fft(f0,(1,2)).*fft(w,(1,2)))); figure(figsize = (10,10)) u = f0 u[1,1] = 0 u[2,1] = 1 imageplot(clamp(u,0,1), "Input", [1,2,1]) u = f u[1,1] = 0 u[2,1] = 1 imageplot(clamp(u,0,1), "Synthesized", [1,2,2]); include("NtSolutions/graphics_1_synthesis_gaussian/exo2.jl"); ## Insert your code here. f0 = p; include("NtSolutions/graphics_1_synthesis_gaussian/exo3.jl") ## Insert your code here. include("NtSolutions/graphics_1_synthesis_gaussian/exo4.jl") ## Insert your code here. n0 = n*2; a = 10/n; phi = t-> sin.(t/a*pi/2).^2 psi = t-> phi(t).*(t .< a) + (t .>= a).*(t .<= 1-a) + phi(1-t).*(t .> 1-a); t = collect(linspace(0, 1, n)) g = repeat( psi(t)*psi(t)', outer=(1, 1, size(f0,3))); mu0 = repeat(mean(mean(f0, 1), 2), outer=(n,n,1)) f1 = repeat(mean(mean(f0, 1), 2), outer=(n0,n0,1)) range = Base.div(n0,2)-Base.div(n,2)+1:Base.div(n0,2) + Base.div(n,2) f1[range ,range, :] = mu0 + n0/n*g.*(f0-mu0); u = f1 u[1,1] = 0 u[2,1] = 1 figure(figsize = (5,5)) imageplot(clamp(u,0,1)) include("NtSolutions/graphics_1_synthesis_gaussian/exo5.jl"); ## Insert your code here.