[242173]: / R / CT_Skull_Stripper.R

Download this file

71 lines (64 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#' @title CT Skull Stripping Wrapper
#' @description Simple Wrapper for \code{\link{CT_Skull_Strip}} and
#' \code{\link{CT_Skull_Strip_robust}}, with simple flag for robustness
#' @param ... (character) File to be skull stripped or object of class
#' @param maskfile (character) Filename for mask (if \code{keepmask = TRUE}).
#' If \code{NULL}, then a temporary file will be generated.
#' nifti
#' @param robust (logical) output filename
#' @export
CT_Skull_Stripper <- function(
...,
robust = FALSE
){
L = list(...)
nL = names(L)
if (is.null(nL)) {
nL = rep("", length = length(L))
}
if (robust) {
n = names(formals(CT_Skull_Strip_robust))
n = c("", n)
ind = which(nL %in% n)
L = L[ind]
res = do.call("CT_Skull_Strip_robust", L)
} else {
n = names(formals(CT_Skull_Strip))
n = c("", n)
ind = which(nL %in% n)
L = L[ind]
res = do.call("CT_Skull_Strip", L)
}
return(res)
}
#' @rdname CT_Skull_Stripper
#' @export
CT_Skull_Stripper_mask <- function(
...,
maskfile = NULL,
robust = FALSE
){
if (is.null(maskfile)) {
maskfile = tempfile(fileext = ".nii.gz")
}
# making retimg and reorient for mask
args = list(...)
retimg = args$retimg
if (is.null(retimg)) {
retimg = TRUE
}
reorient = args$reorient
if (is.null(reorient)) {
reorient = FALSE
}
res = CT_Skull_Stripper(
..., robust = robust,
maskfile = maskfile)
if (retimg) {
mask = readnii(maskfile,
reorient = reorient)
}
L = list(ss_image = res,
mask = mask)
return(L)
}