options(warn=-1) # turns off warnings, to turn on: "options(warn=0)" library(imager) library(png) 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="")) } options(repr.plot.width=3.5, repr.plot.height=3.5) n <- 512 f <- rescale(load_image("nt_toolbox/data/lena.png", n)) imageplot(f) fF <- fft(f)/n imageplot(log(1e-5 + abs(fftshift(as.matrix(fF))))) T <- .3 c <- fF * (abs(fF) > T) fM <- Re( (fft(c, inverse=TRUE)/length(c))*n ) imageplot(clamp(fM)) options(repr.plot.width=7, repr.plot.height=3.5) source("nt_solutions/coding_1_approximation/exo1.R") ## Insert your code here. options(repr.plot.width=3.5, repr.plot.height=3.5) source("nt_solutions/coding_1_approximation/exo2.R") ## Insert your code here. options(repr.plot.width=3.5, repr.plot.height=3.5) source("nt_solutions/coding_1_approximation/exo3.R") ## Insert your code here. Jmin <- 1 h <- compute_wavelet_filter("Daubechies",10) fW <- perform_wavortho_transf(f, Jmin, + 1, h) plot_wavelet(fW, Jmin) title(main='Wavelet coefficients') options(repr.plot.width=7, repr.plot.height=3.5) source("nt_solutions/coding_1_approximation/exo4.R") ## Insert your code here. options(repr.plot.width=4, repr.plot.height=4) source("nt_solutions/coding_1_approximation/exo5.R") ## Insert your code here dct2 <- function(f){ return( t(dct_2d(t(dct_2d(as.matrix(f))))) ) } idct2 <- function(f){ return( t(dct_2d(t(dct_2d(as.matrix(f),inverted=T)), inverted=T)) ) } fC <- dct2(f) imageplot(log(1e-5 + abs(fC))) options(repr.plot.width=7, repr.plot.height=3.5) source("nt_solutions/coding_1_approximation/exo6.R") ## Insert your code here. options(repr.plot.width=4, repr.plot.height=4) source("nt_solutions/coding_1_approximation/exo7.R") ## Insert your code here. w <- 16 fL <- matrix(rep(0, length=n*n), c(n, n)) i <- 5 j <- 7 P <- as.matrix(f)[((i-1)*w):(i*w-1), ((j-1)*w):(j*w-1)] fL[((i-1)*w):(i*w-1), ((j-1)*w):(j*w-1)] = dct2(P) options(repr.plot.width=7, repr.plot.height=3.5) imageplot(P, 'Patch', c(1, 2, 1)) imageplot(dct2(P-mean(P)), 'DCT', c(1, 2, 2)) source("nt_solutions/coding_1_approximation/exo8.R") ## Insert your code here. options(repr.plot.width=3.5, repr.plot.height=3.5) imageplot(clip(abs(fL),0,.005*w*w)) source("nt_solutions/coding_1_approximation/exo9.R") ## Insert your code here. options(repr.plot.width=7, repr.plot.height=3.5) source("nt_solutions/coding_1_approximation/exo10.R") ## Insert your code here. options(repr.plot.width=4, repr.plot.height=4) source("nt_solutions/coding_1_approximation/exo11.R") ## Insert your code here. n <- 512 fList <- array(rep(0, length=n*n*4), c(n, n, 4)) fList[ , , 1] <- rescale(load_image("nt_toolbox/data/regular3.png", n)) fList[ , , 2] <- rescale(load_image("nt_toolbox/data/phantom.png", n)) fList[ , , 3] <- rescale(load_image("nt_toolbox/data/lena.png", n)) fList[ , , 4] <- rescale(load_image("nt_toolbox/data/mandrill.png", n)) options(repr.plot.width=7, repr.plot.height=7) for (i in 1:4){ imageplot(fList[ , , i], '', c(2,2,i)) } options(repr.plot.width=4, repr.plot.height=4) source("nt_solutions/coding_1_approximation/exo12.R") ## Insert your code here.