## For images from Mengerson et al paper: NA is indecated by completely black pixels args <- commandArgs(TRUE) str(args) if (length(args) != 2) { cat("\nUsage: Rscript ./inpainting-black.R \n\nZero pixels in the mask are interpreted as missing\n\n") q() } INFILE <- args[1] MASKFILE <- args[2] KBW <- as.numeric(Sys.getenv("KBW", "0")) GAMMA <- 1 rho.iid <- list(along = 0, across = 0) # IID parameters rho.ar <- list(along = 0.3, across = 0.6) # AR parameters suppressMessages(library(rip.recover)) OUTDIR <- sprintf("epanechnikov-%g", KBW) if (!dir.exists(OUTDIR)) dir.create(OUTDIR) fout <- function(s) file.path(OUTDIR, sprintf("%s-%s-%s.png", INFILE, MASKFILE, s)) fexists <- function(label) { message(fout(label)) file.exists(fout(label)) } fexport <- function(x, label = deparse(substitute(x))) { rip.export(round(255 * x^GAMMA), file = fout(label)) } y <- rip.import(INFILE, "original") if (nchannel(y) == 4) y <- as.rip(as.array(y)[,,-4]) COLOR <- nchannel(y) == 3 mask <- rip.import(MASKFILE, "grayscale") mask01 <- as.rip(mask == 0) image(mask01) ## OpenCV inpainting if (FALSE) if (!fexists("incv")) { ## incv <- rip.cv$photo$inpaint(y, mask01, radius = 20) incv <- rip.cv$xphoto$inpaint(y, 255 * (1-mask01), 0L) incv[] <- (incv/255)^(1/GAMMA) fexport(incv) ## if (!fexists("incv.robust")) ## { ## incv.robust <- ## rip.denoise(incv, kbw = 0, method = "direct", verbose = TRUE, ## patch = 200, overlap = 20, ## yerror = "huber", huber.k = 1, ## lambda = LAMBDA, alpha = 2, rho = rho.iid) ## fexport(incv.robust) ## } } y[] <- (y/255)^(1/GAMMA) if (COLOR) { tmp <- as.array(y) # or as.array(y) -> NA -> as.rip() is.na(tmp[,,1]) <- mask01 > 0 is.na(tmp[,,2]) <- mask01 > 0 is.na(tmp[,,3]) <- mask01 > 0 ## tmp <- y ## is.na(tmp[, c(T, F, F)]) <- mask01 > 0 ## is.na(tmp[, c(F, T, F)]) <- mask01 > 0 ## is.na(tmp[, c(F, F, T)]) <- mask01 > 0 tmp <- as.rip(tmp) } else { tmp <- rip.desaturate(y) is.na(tmp) <- mask01 > 0 } ## image(255 * rip.desaturate(tmp), rescale = FALSE) if (!fexists("giid")) { giid <- rip.denoise(tmp, kbw = KBW, method = "direct", verbose = TRUE, patch = 200, overlap = 20, lambda = 0.01, alpha = 2, rho = rho.iid) ## image(giid * 255, rescale = FALSE) fexport(giid) } if (!fexists("gar")) { gar <- rip.denoise(tmp, kbw = KBW, method = "direct", verbose = TRUE, patch = 200, overlap = 20, lambda = 0.01, alpha = 2, rho = rho.ar) ## image(giid * 255, rescale = FALSE) fexport(gar) } ## if (!fexists("giid.robust")) ## { ## giid.robust <- ## rip.denoise(giid, kbw = KBW, method = "direct", verbose = TRUE, ## patch = 200, overlap = 20, ## yerror = "huber", huber.k = 1, ## lambda = 0.01, alpha = 2, rho = rho.iid) ## fexport(giid.robust) ## } if (!fexists("sar")) { sar <- rip.denoise(tmp, kbw = KBW, method = "direct", verbose = TRUE, patch = 200, overlap = 20, lambda = 0.001, alpha = 0.8, rho = rho.ar) fexport(sar) } ## if (!fexists("sar.robust")) ## { ## sar.robust <- ## rip.denoise(sar, kbw = KBW, method = "direct", verbose = TRUE, ## patch = 200, overlap = 20, ## yerror = "huber", huber.k = 1, ## lambda = 0.01, alpha = 0.8, rho = rho.ar) ## fexport(sar.robust) ## }