library(imager) library(png) library(pracma) # Importing the libraries for (f in list.files(path="nt_toolbox/toolbox_general/", pattern="*.R")) { source(paste("nt_toolbox/toolbox_general/", f, sep="")) } for (f in list.files(path="nt_toolbox/toolbox_signal/", pattern="*.R")) { source(paste("nt_toolbox/toolbox_signal/", f, sep="")) } name = 'nt_toolbox/data/lena.png' n = 256 M = load_image(name, n) options(repr.plot.width=4, repr.plot.height=4) imageplot(M[c(((n/2) - 25):((n/2) + 25)), c(((n/2) - 25):((n/2) + 25))], 'Zoom', c(1, 2, 2)) options(repr.plot.width=5, repr.plot.height=5) imageplot(-M, '-M', c(1,2,1)) imageplot(M[nrow(M):1,], 'Flipped', c(1,2,2)) sigma = 5. t = c(0:((n/2)), -(n/2):-2) mesh = meshgrid(t) X = mesh$X Y = mesh$Y h = exp( -(X**2 + Y**2)/(2.0 * sigma**2) ) h = h/sum(h) imageplot(fftshift(h)) Mh = Re(fft(fft(M[,]) * fft(h), inverse=TRUE) / n) imageplot(M, 'Image', c(1, 2, 1)) imageplot(Mh, 'Blurred', c(1, 2, 2)) G = grad(M[,]) imageplot(G[,,1], 'd/ dx', c(1, 2, 1)) imageplot(G[,,2], 'd/ dy', c(1, 2, 2)) Mf = fft(M[,]) Lf = fftshift(log(abs(Mf) + 1e-1)) imageplot(M, 'Image', c(1, 2, 1)) imageplot(Lf, 'Fourier transform', c(1, 2, 2)) source("nt_solutions/introduction_3_image/exo1.R") # Insert code here. source("nt_solutions/introduction_3_image/exo1.R") # Insert code here.