## load NIFTI files and convert them to MRIaggr
path.Pat1 <- system.file(file.path("nifti"), package = "MRIaggr")
ls.array <- list(readMRI(file.path(path.Pat1, "T1_t0"), format = "nifti"),
                 readMRI(file.path(path.Pat1, "T2_GRE_t0"), format = "nifti"))
MRIaggr.Pat1 <- constMRIaggr(ls.array, identifier = "Pat1", param = c("T1_t0","T2_GRE_t0"))
#### 1- thresholding approach ####
res <- calcBrainMask(MRIaggr.Pat1, param = "T2_GRE_t0", type = "threshold",
                     th.select_optima = 2)
breaks <- res$analysis[,"threshold"]
res <- calcBrainMask(MRIaggr.Pat1, param = "T2_GRE_t0", type = "threshold",
                     th.breaks = breaks[breaks > 50], th.select_optima = 1,
                     overwrite = TRUE, update.object = TRUE)
## display
multiplot(MRIaggr.Pat1, param = "mask")
multiplot(MRIaggr.Pat1, param = "T2_GRE_t0", index1 = "mask")
## other parameter 
## Not run: 
# res <- calcBrainMask(MRIaggr.Pat1, param = "T1_t0", type = "threshold",
#                      th.breaks = 200)
# 
# res <- calcBrainMask(MRIaggr.Pat1, param = "T1_t0", type = "threshold",
#                      th.breaks = seq(0, 400, length.out = 50), th.select_optima = 2,
#                      overwrite = TRUE, update.object = TRUE)
# 
# multiplot(MRIaggr.Pat1, param = "mask")
# ## End(Not run)
#### 2- k-means approach ####
## Not run: 
# res <- calcBrainMask(MRIaggr.Pat1, param = "T2_GRE_t0", type = "kmeans",
#                      kmeans.n_groups = 2:4,
#                      update.object = TRUE, overwrite = TRUE)
# ## End(Not run)
					 
## display
multiplot(MRIaggr.Pat1, param = "T2_GRE_t0", index1 = "mask")
multiplot(MRIaggr.Pat1, param = "mask")
Run the code above in your browser using DataLab