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,
  ...
)

Arguments

...

additional arguments passed to readnii.

outfile

(character) resultant masked image name

retimg

(logical) return image of class nifti

file

(character) image to be masked

mask

(character) mask given for image

reorient

(logical) If retimg, should file be reoriented when read in? Passed to readnii.

intern

(logical) to be passed to system

opts

(character) additional options to be passed to fslmask

verbose

(logical) print out command before running

Value

Result from system command, depends if intern is TRUE or FALSE.

Note

Functions with underscores have different defaults and will return an output filename, so to be used for piping

Examples

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)
})
}