View source: R/read_fs_volume.R
| read.fs.volume | R Documentation |
Read multi-dimensional brain imaging data from a file.
read.fs.volume(
filepath,
format = "auto",
flatten = FALSE,
with_header = FALSE,
drop_empty_dims = FALSE
)
filepath |
string. Full path to the input MGZ, MGH or NIFTI file. |
format |
character string, one one of 'auto', 'nii', 'mgh' or 'mgz'. The format to assume. If set to 'auto' (the default), the format will be derived from the file extension. |
flatten |
logical. Whether to flatten the return volume to a 1D vector. Useful if you know that this file contains 1D morphometry data. |
with_header |
logical. Whether to return the header as well. If TRUE, return an instance of class |
drop_empty_dims |
logical, whether to drop empty dimensions of the returned data |
data, multi-dimensional array. The brain imaging data, one value per voxel. The data type and the dimensions depend on the data in the file, they are read from the header. If the parameter flatten is TRUE, a numeric vector is returned instead. Note: The return value changes if the parameter with_header is TRUE, see parameter description.
To derive more information from the header, see the mghheader.* functions, like mghheader.vox2ras.tkreg.
Other morphometry functions:
fs.get.morph.file.ext.for.format(),
fs.get.morph.file.format.from.filename(),
read.fs.curv(),
read.fs.mgh(),
read.fs.morph(),
read.fs.morph.gii(),
read.fs.weight(),
write.fs.curv(),
write.fs.label.gii(),
write.fs.mgh(),
write.fs.morph(),
write.fs.morph.asc(),
write.fs.morph.gii(),
write.fs.morph.ni1(),
write.fs.morph.ni2(),
write.fs.morph.smp(),
write.fs.morph.txt(),
write.fs.weight(),
write.fs.weight.asc()
brain_image <- system.file("extdata", "brain.mgz",
package = "freesurferformats",
mustWork = TRUE
)
vd <- read.fs.volume(brain_image)
cat(sprintf(
"Read voxel data with dimensions %s. Values: min=%d, mean=%f, max=%d.\n",
paste(dim(vd), collapse = " "), min(vd), mean(vd), max(vd)
))
# Read it again with full header data:
vdh <- read.fs.volume(brain_image, with_header = TRUE)
# Use the vox2ras matrix from the header to compute RAS coordinates at CRS voxel (0, 0, 0):
vox2ras_matrix <- mghheader.vox2ras(vdh)
vox2ras_matrix %*% c(0, 0, 0, 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.