This function calls fslmaths -mas
to mask an image from
an image mask and either saves the image or returns an object of class nifti
fsl_mask(..., outfile = tempfile(fileext = ".nii.gz"), retimg = FALSE)
fslmask(
file,
mask,
outfile = NULL,
retimg = TRUE,
reorient = FALSE,
intern = FALSE,
opts = "",
verbose = TRUE,
...
)
additional arguments passed to readnii
.
(character) resultant masked image name
(logical) return image of class nifti
(character) image to be masked
(character) mask given for image
(logical) If retimg, should file be reoriented when read in?
Passed to readnii
.
(logical) to be passed to system
(character) additional options to be passed to fslmask
(logical) print out command before running
Result from system command, depends if intern is TRUE or FALSE.
Functions with underscores have different defaults and will return an output filename, so to be used for piping
if (have.fsl()){
system.time({
x = array(rnorm(1e5), dim = c(100, 100, 10))
img = nifti(x, dim= c(100, 100, 10),
datatype = convert.datatype()$FLOAT32, cal.min = min(x),
cal.max = max(x), pixdim = rep(1, 4))
mask = img > .5
masked = fslmask(img, mask = mask, retimg=TRUE)
})
}
#> fslmaths "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpKzob0N/file85754da4412b.nii.gz" -mas "/private/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T/RtmpKzob0N/file85755ab295df.nii.gz" "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpKzob0N/file85756ce96019"
#> user system elapsed
#> 0.366 0.004 0.374