#### 1- with simulated data ####
## simulate
set.seed(10)
n <- 4
Y <- rnorm(n^2)
## conversion
res1 <- df2array(contrast = Y, coords = expand.grid(1:n + 0.5, 1:n + 0.5))
res2 <- df2array(contrast = Y, coords = expand.grid(1:n, 1:n), format = "matrix")
res3 <- df2array(contrast = Y, coords = expand.grid(2 * (1:n), 2 * (1:n)))
res4 <- df2array(contrast=cbind(Y ,Y, Y), coords = expand.grid(2 * (1:n), 2 * (1:n)),
range.coords = c(10,10))
## display
par(mfrow = c(2,2), mar = rep(2,4), mgp = c(1.5,0.5,0))
fields::image.plot(unique(res1$coords[,1]), unique(res1$coords[,2]), res1$contrast[[1]],
xlab = "", ylab = "")
fields::image.plot(unique(res2$coords[,1]), unique(res2$coords[,2]), res2$contrast,
xlab = "", ylab = "")
fields::image.plot(res3$contrast[[1]])
fields::image.plot(res4$contrast[[2]])
#### 2- with MRIaggr data ####
## load a MRIaggr object
data("MRIaggr.Pat1_red", package = "MRIaggr")
carto <- selectContrast(MRIaggr.Pat1_red, param = "DWI_t0", format = "vector")
coords <- selectCoords(MRIaggr.Pat1_red)
coords[,1] <- coords[,1] + 30
coords[,2] <- coords[,2] + 15
## converion 1
array.DWI_t0 <- df2array(carto, coords = coords, default_value = 1000)$contrast[[1]]
# display
fields::image.plot(min(coords[,1]):max(coords[,1]), min(coords[,2]):max(coords[,2]),
array.DWI_t0[,,1], xlab = "i", ylab = "j")
## conversion 2
array.DWI_t0 <- df2array(contrast=carto, coords = coords, default_value = 1000,
range.coords = c(128,128,3))$contrast[[1]]
# display
fields::image.plot(1:128, 1:128, array.DWI_t0[,,1], xlab = "i", ylab = "k")
Run the code above in your browser using DataLab