optionsMRIaggr(legend=FALSE,axes=FALSE,num.main=FALSE,mar=c(0,2,2,0))
# spatial field
## Not run:
# n <- 30
# ## End(Not run)
G <- 3
coords <- which(matrix(0, nrow = n * G, ncol = n * G) == 0,arr.ind = TRUE)
# neighborhood matrix
W_SR <- calcW(as.data.frame(coords), range = sqrt(2), row.norm = TRUE)$W
resW <- calcW(as.data.frame(coords), range = 10, row.norm = FALSE, calcBlockW = TRUE)
W_LR <- resW$W
site_order <- unlist(resW$blocks$ls_groups) - 1
# initialisation
set.seed(10)
system.time(
sample <- simulPotts(W_SR, G = 3, rho = 3.5, iter_max = 500,
site_order = site_order)$simulation
)
intensity <- rnorm((n * G)^2, mean = apply(sample, 1, which.max), sd = 0.5)
likelihood <- matrix(unlist(lapply(1:3, function(x){dnorm(intensity, mean = x, sd = 0.5)})),
ncol = G, nrow = (n * G)^2, byrow = FALSE)
likelihood_sqrt <- sqrt(likelihood)
probability <- sweep(likelihood_sqrt, MARGIN = 1, FUN = "/", STATS = rowSums(likelihood_sqrt))
multiplot(as.data.frame(coords), probability, palette = "rgb",
main = "original image")
#### local image restoration
LocalRestoration <- calcPotts(W_SR = W_SR, sample = probability, rho = 4,
site_order = site_order)
multiplot(as.data.frame(coords), LocalRestoration$predicted, palette = "rgb",
main = "local restoration of the image")
#### regional image restoration
distance.ref <- seq(1, 10, 1)
RegionalRestoration <- calcPotts(W_SR = W_SR, sample = probability,
rho = c(4,2), site_order = site_order,
W_LR = W_LR, coords = coords, distance.ref = distance.ref)
# regional potential
multiplot(as.data.frame(coords),
matrix(unlist(RegionalRestoration$Vregional), ncol = 3, nrow = (n * G)^2, byrow = FALSE),
palette = "rgb", main = "regional potentials")
# final image
multiplot(as.data.frame(coords),
matrix(unlist(RegionalRestoration$predicted), ncol = 3, nrow = (n * G)^2, byrow = FALSE),
palette = "rgb", main = "local and regional \n restoration of the image")
Run the code above in your browser using DataLab