q()
library(ANTsR)
q()
setwd("/home/nemymila/Rscripts/tbmnc")
library(ANTsR)
#template
t <- antsImageRead("template/T_template0.nii.gz")
#N4 field correction
t <- abpN4(t)
# resample - spacing
t <-resampleImage(t,c(1.0, 1.0, 1.0),0,4)
antsImageWrite(t, "output/template_resampled.nii.gz" )
#get AD data
files <- list.files(path="dataNC", pattern="*.nii.gz", full.names=T, recursive=FALSE)
lapply(files, function(file) {
cat("Current working file: ", file)
basen <- basename(file)
dir.create(file.path("output", basen))
m <- antsImageRead(file)
m <- abpN4(m)
m <-resampleImage(m,c(1.0, 1.0, 1.0),0,4)
tx = antsRegistration( t, m, "SyNCC",
regIterations = c(100,50,40), verbose = TRUE )
#gmw = antsApplyTransforms( f3, m3, tx$fwdtransforms)
#plot(gmw)
jac <- createJacobianDeterminantImage(t, tx$fwdtransforms[1], doLog = 1)
#plot(jac)
logFileName <- paste("output/",basen,"/logJac.nii.gz",sep='')
antsImageWrite(jac, logFileName )
dirName <- paste("output/",basen,"/",sep='')
file.copy(from=tx$fwdtransforms[1], to=dirName)
file.copy(from=tx$fwdtransforms[2], to=dirName)
file.copy(from=tx$invtransforms[2], to=dirName)
})
